aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docker/Dockerfile2
-rw-r--r--docker/smoke/Dockerfile2
-rw-r--r--functest/api/__init__.py0
-rw-r--r--functest/api/base.py66
-rw-r--r--functest/api/common/__init__.py0
-rw-r--r--functest/api/common/api_utils.py91
-rw-r--r--functest/api/common/error.py24
-rw-r--r--functest/api/resources/__init__.py0
-rw-r--r--functest/api/resources/v1/__init__.py0
-rw-r--r--functest/api/resources/v1/creds.py29
-rw-r--r--functest/api/resources/v1/envs.py34
-rw-r--r--functest/api/resources/v1/testcases.py48
-rw-r--r--functest/api/resources/v1/tiers.py67
-rw-r--r--functest/api/server.py67
-rw-r--r--functest/api/urls.py52
-rw-r--r--functest/ci/config_functest.yaml13
-rw-r--r--functest/ci/logging.ini7
-rw-r--r--functest/ci/run_tests.py140
-rw-r--r--functest/ci/testcases.yaml24
-rw-r--r--functest/ci/tier_builder.py9
-rw-r--r--functest/ci/tier_handler.py89
-rw-r--r--functest/cli/commands/cli_env.py37
-rw-r--r--functest/cli/commands/cli_os.py19
-rw-r--r--functest/cli/commands/cli_testcase.py27
-rw-r--r--functest/cli/commands/cli_tier.py44
-rw-r--r--functest/energy/energy.py11
-rw-r--r--functest/opnfv_tests/vnf/ims/orchestra.yaml61
-rw-r--r--functest/opnfv_tests/vnf/ims/orchestra_clearwaterims.py684
-rw-r--r--functest/opnfv_tests/vnf/ims/orchestra_ims.yaml45
-rw-r--r--functest/opnfv_tests/vnf/ims/orchestra_openims.py (renamed from functest/opnfv_tests/vnf/ims/orchestra_ims.py)239
-rw-r--r--functest/tests/unit/ci/test_run_tests.py171
-rw-r--r--functest/tests/unit/ci/test_tier_builder.py3
-rw-r--r--functest/tests/unit/vnf/ims/test_orchestra_clearwaterims.py227
-rw-r--r--functest/tests/unit/vnf/ims/test_orchestra_openims.py (renamed from functest/tests/unit/vnf/ims/test_orchestra_ims.py)61
-rw-r--r--requirements.txt2
-rw-r--r--setup.cfg1
-rw-r--r--tox.ini1
37 files changed, 1937 insertions, 460 deletions
diff --git a/docker/Dockerfile b/docker/Dockerfile
index fe918527..2cbee665 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -14,7 +14,7 @@ LABEL version="0.1" description="OPNFV Functest Docker container"
# Environment variables
ARG BRANCH=master
ARG RALLY_TAG=0.8.1
-ARG ODL_TAG=release/beryllium-sr4
+ARG ODL_TAG=release/carbon
ARG OPENSTACK_TAG=stable/ocata
ARG VIMS_TAG=stable
ARG VROUTER_TAG=stable
diff --git a/docker/smoke/Dockerfile b/docker/smoke/Dockerfile
index 223ed64d..10385470 100644
--- a/docker/smoke/Dockerfile
+++ b/docker/smoke/Dockerfile
@@ -2,7 +2,7 @@ FROM opnfv/functest-core
ARG BRANCH=master
ARG OPENSTACK_TAG=stable/ocata
-ARG ODL_TAG=release/beryllium-sr4
+ARG ODL_TAG=release/carbon
COPY thirdparty-requirements.txt thirdparty-requirements.txt
RUN apk --no-cache add --virtual .build-deps --update \
diff --git a/functest/api/__init__.py b/functest/api/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/functest/api/__init__.py
diff --git a/functest/api/base.py b/functest/api/base.py
new file mode 100644
index 00000000..efeab824
--- /dev/null
+++ b/functest/api/base.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""
+The base class to dispatch request
+
+"""
+
+import logging
+
+from flask import request
+from flask_restful import Resource
+
+from functest.api.common import api_utils, error
+
+
+LOGGER = logging.getLogger(__name__)
+
+
+class ApiResource(Resource):
+ """ API Resource class"""
+
+ def __init__(self):
+ super(ApiResource, self).__init__()
+
+ def _post_args(self): # pylint: disable=no-self-use
+ # pylint: disable=maybe-no-member
+ """ Return action and args after parsing request """
+
+ data = request.json if request.json else {}
+ params = api_utils.change_to_str_in_dict(data)
+ action = params.get('action', request.form.get('action', ''))
+ args = params.get('args', {})
+ try:
+ args['file'] = request.files['file']
+ except KeyError:
+ pass
+ LOGGER.debug('Input args are: action: %s, args: %s', action, args)
+
+ return action, args
+
+ def _dispatch_post(self):
+ """ Dispatch request """
+ action, args = self._post_args()
+ return self._dispatch(args, action)
+
+ def _dispatch(self, args, action):
+ """
+ Dynamically load the classes with reflection and
+ obtain corresponding methods
+ """
+ try:
+ return getattr(self, action)(args)
+ except AttributeError:
+ error.result_handler(status=1, data='No such action')
+
+
+# Import modules from package "functest.api.resources"
+# and append them into sys.modules
+api_utils.import_modules_from_package("functest.api.resources")
diff --git a/functest/api/common/__init__.py b/functest/api/common/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/functest/api/common/__init__.py
diff --git a/functest/api/common/api_utils.py b/functest/api/common/api_utils.py
new file mode 100644
index 00000000..f518e777
--- /dev/null
+++ b/functest/api/common/api_utils.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""
+Utils for functest restapi
+
+"""
+
+import collections
+import logging
+import os
+import sys
+from oslo_utils import importutils
+
+import six
+
+import functest
+
+LOGGER = logging.getLogger(__name__)
+
+
+def change_to_str_in_dict(obj):
+ """
+ Return a dict with key and value both in string if they are in Unicode
+ """
+ if isinstance(obj, collections.Mapping):
+ return {str(k): change_to_str_in_dict(v) for k, v in obj.items()}
+ elif isinstance(obj, list):
+ return [change_to_str_in_dict(ele) for ele in obj]
+ elif isinstance(obj, six.text_type):
+ return str(obj)
+ return obj
+
+
+def itersubclasses(cls, _seen=None):
+ """ Generator over all subclasses of a given class in depth first order """
+
+ if not isinstance(cls, type):
+ raise TypeError("itersubclasses must be called with "
+ "new-style classes, not %.100r" % cls)
+ _seen = _seen or set()
+ try:
+ subs = cls.__subclasses__()
+ except TypeError: # fails only when cls is type
+ subs = cls.__subclasses__(cls)
+ for sub in subs:
+ if sub not in _seen:
+ _seen.add(sub)
+ yield sub
+ for itersub in itersubclasses(sub, _seen):
+ yield itersub
+
+
+def import_modules_from_package(package):
+ """
+ Import modules from package and append into sys.modules
+ :param: package - Full package name. For example: functest.api.resources
+ """
+ path = [os.path.dirname(functest.__file__), ".."] + package.split(".")
+ path = os.path.join(*path)
+ for root, _, files in os.walk(path):
+ for filename in files:
+ if filename.startswith("__") or not filename.endswith(".py"):
+ continue
+ new_package = ".".join(root.split(os.sep)).split("....")[1]
+ module_name = "%s.%s" % (new_package, filename[:-3])
+ try:
+ try_append_module(module_name, sys.modules)
+ except ImportError:
+ LOGGER.exception("unable to import %s", module_name)
+
+
+def try_append_module(name, modules):
+ """ Append the module into specified module system """
+
+ if name not in modules:
+ modules[name] = importutils.import_module(name)
+
+
+def change_obj_to_dict(obj):
+ """ Transfer the object into dict """
+ dic = {}
+ for key, value in vars(obj).items():
+ dic.update({key: value})
+ return dic
diff --git a/functest/api/common/error.py b/functest/api/common/error.py
new file mode 100644
index 00000000..d0045225
--- /dev/null
+++ b/functest/api/common/error.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""
+Used to handle results
+
+"""
+
+from flask import jsonify
+
+
+def result_handler(status, data):
+ """ Return the json format of result in dict """
+ result = {
+ 'status': status,
+ 'result': data
+ }
+ return jsonify(result)
diff --git a/functest/api/resources/__init__.py b/functest/api/resources/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/functest/api/resources/__init__.py
diff --git a/functest/api/resources/v1/__init__.py b/functest/api/resources/v1/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/functest/api/resources/v1/__init__.py
diff --git a/functest/api/resources/v1/creds.py b/functest/api/resources/v1/creds.py
new file mode 100644
index 00000000..e402d7e3
--- /dev/null
+++ b/functest/api/resources/v1/creds.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""
+Resources to handle openstack related requests
+"""
+
+from flask import jsonify
+
+from functest.api.base import ApiResource
+from functest.cli.commands.cli_os import OpenStack
+from functest.utils import openstack_utils as os_utils
+from functest.utils.constants import CONST
+
+
+class V1Creds(ApiResource):
+ """ V1Creds Resource class"""
+
+ def get(self): # pylint: disable=no-self-use
+ """ Get credentials """
+ os_utils.source_credentials(CONST.__getattribute__('openstack_creds'))
+ credentials_show = OpenStack.show_credentials()
+ return jsonify(credentials_show)
diff --git a/functest/api/resources/v1/envs.py b/functest/api/resources/v1/envs.py
new file mode 100644
index 00000000..35bffb04
--- /dev/null
+++ b/functest/api/resources/v1/envs.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""
+Resources to handle environment related requests
+"""
+
+from flask import jsonify
+
+from functest.api.base import ApiResource
+from functest.cli.commands.cli_env import Env
+import functest.utils.functest_utils as ft_utils
+
+
+class V1Envs(ApiResource):
+ """ V1Envs Resource class"""
+
+ def get(self): # pylint: disable=no-self-use
+ """ Get environment """
+ environment_show = Env().show()
+ return jsonify(environment_show)
+
+ def post(self):
+ """ Used to handle post request """
+ return self._dispatch_post()
+
+ def prepare(self, args): # pylint: disable=no-self-use, unused-argument
+ """ Prepare environment """
+ ft_utils.execute_command("prepare_env start")
diff --git a/functest/api/resources/v1/testcases.py b/functest/api/resources/v1/testcases.py
new file mode 100644
index 00000000..c3b8217a
--- /dev/null
+++ b/functest/api/resources/v1/testcases.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""
+Resources to handle testcase related requests
+"""
+
+from flask import abort, jsonify
+
+from functest.api.base import ApiResource
+from functest.api.common import api_utils
+from functest.cli.commands.cli_testcase import Testcase
+
+
+class V1Testcases(ApiResource):
+ """ V1Testcases Resource class"""
+
+ def get(self): # pylint: disable=no-self-use
+ """ GET all testcases """
+ testcases_list = Testcase().list()
+ result = {'testcases': testcases_list.split('\n')[:-1]}
+ return jsonify(result)
+
+
+class V1Testcase(ApiResource):
+ """ V1Testcase Resource class"""
+
+ def get(self, testcase_name): # pylint: disable=no-self-use
+ """ GET the info of one testcase"""
+ testcase = Testcase().show(testcase_name)
+ if not testcase:
+ abort(404, "The test case '%s' does not exist or is not supported"
+ % testcase_name)
+ testcase_info = api_utils.change_obj_to_dict(testcase)
+ dependency_dict = api_utils.change_obj_to_dict(
+ testcase_info.get('dependency'))
+ testcase_info.pop('name')
+ testcase_info.pop('dependency')
+ result = {'testcase': testcase_name}
+ result.update(testcase_info)
+ result.update({'dependency': dependency_dict})
+ return jsonify(result)
diff --git a/functest/api/resources/v1/tiers.py b/functest/api/resources/v1/tiers.py
new file mode 100644
index 00000000..71a98bea
--- /dev/null
+++ b/functest/api/resources/v1/tiers.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""
+Resources to handle tier related requests
+"""
+
+import re
+
+from flask import abort, jsonify
+
+from functest.api.base import ApiResource
+from functest.cli.commands.cli_tier import Tier
+
+
+class V1Tiers(ApiResource):
+ """ V1Tiers Resource class """
+
+ def get(self):
+ # pylint: disable=no-self-use
+ """ GET all tiers """
+ tiers_list = Tier().list()
+ data = re.split("[\n\t]", tiers_list)
+ data = [i.strip() for i in data if i != '']
+ data_dict = dict()
+ for i in range(len(data) / 2):
+ one_data = {data[i * 2]: data[i * 2 + 1]}
+ if i == 0:
+ data_dict = one_data
+ else:
+ data_dict.update(one_data)
+ result = {'tiers': data_dict}
+ return jsonify(result)
+
+
+class V1Tier(ApiResource):
+ """ V1Tier Resource class """
+
+ def get(self, tier_name): # pylint: disable=no-self-use
+ """ GET the info of one tier """
+ testcases = Tier().gettests(tier_name)
+ if not testcases:
+ abort(404, "The tier with name '%s' does not exist." % tier_name)
+ tier_info = Tier().show(tier_name)
+ tier_info.__dict__.pop('name')
+ tier_info.__dict__.pop('tests_array')
+ result = {'tier': tier_name, 'testcases': testcases}
+ result.update(tier_info.__dict__)
+ return jsonify(result)
+
+
+class V1TestcasesinTier(ApiResource):
+ """ V1TestcasesinTier Resource class """
+
+ def get(self, tier_name): # pylint: disable=no-self-use
+ """ GET all testcases within given tier """
+ testcases = Tier().gettests(tier_name)
+ if not testcases:
+ abort(404, "The tier with name '%s' does not exist." % tier_name)
+ result = {'tier': tier_name, 'testcases': testcases}
+ return jsonify(result)
diff --git a/functest/api/server.py b/functest/api/server.py
new file mode 100644
index 00000000..e246333e
--- /dev/null
+++ b/functest/api/server.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""
+Used to launch Functest RestApi
+
+"""
+
+import logging
+import socket
+from urlparse import urljoin
+import pkg_resources
+
+from flask import Flask
+from flask_restful import Api
+
+from functest.api.base import ApiResource
+from functest.api.urls import URLPATTERNS
+from functest.api.common import api_utils
+
+
+LOGGER = logging.getLogger(__name__)
+
+
+def get_resource(resource_name):
+ """ Obtain the required resource according to resource name """
+ name = ''.join(resource_name.split('_'))
+ return next((r for r in api_utils.itersubclasses(ApiResource)
+ if r.__name__.lower() == name))
+
+
+def get_endpoint(url):
+ """ Obtain the endpoint of url """
+ address = socket.gethostbyname(socket.gethostname())
+ return urljoin('http://{}:5000'.format(address), url)
+
+
+def api_add_resource(api):
+ """
+ The resource has multiple URLs and you can pass multiple URLs to the
+ add_resource() method on the Api object. Each one will be routed to
+ your Resource
+ """
+ for url_pattern in URLPATTERNS:
+ try:
+ api.add_resource(
+ get_resource(url_pattern.target), url_pattern.url,
+ endpoint=get_endpoint(url_pattern.url))
+ except StopIteration:
+ LOGGER.error('url resource not found: %s', url_pattern.url)
+
+
+def main():
+ """Entry point"""
+ logging.config.fileConfig(pkg_resources.resource_filename(
+ 'functest', 'ci/logging.ini'))
+ LOGGER.info('Starting Functest server')
+ app = Flask(__name__)
+ api = Api(app)
+ api_add_resource(api)
+ app.run(host='0.0.0.0')
diff --git a/functest/api/urls.py b/functest/api/urls.py
new file mode 100644
index 00000000..ca45b4be
--- /dev/null
+++ b/functest/api/urls.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""
+Define multiple URLs
+"""
+
+
+class Url(object): # pylint: disable=too-few-public-methods
+ """ Url Class """
+
+ def __init__(self, url, target):
+ super(Url, self).__init__()
+ self.url = url
+ self.target = target
+
+
+URLPATTERNS = [
+ # GET /api/v1/functest/envs => GET environment
+ Url('/api/v1/functest/envs', 'v1_envs'),
+
+ # POST /api/v1/functest/envs/action , {"action":"prepare"}
+ # => Prepare environment
+ Url('/api/v1/functest/envs/action', 'v1_envs'),
+
+ # GET /api/v1/functest/openstack/credentials => GET credentials
+ Url('/api/v1/functest/openstack/credentials', 'v1_creds'),
+
+ # GET /api/v1/functest/testcases => GET all testcases
+ Url('/api/v1/functest/testcases', 'v1_test_cases'),
+
+ # GET /api/v1/functest/testcases/<testcase_name>
+ # => GET the info of one testcase
+ Url('/api/v1/functest/testcases/<testcase_name>', 'v1_testcase'),
+
+ # GET /api/v1/functest/testcases => GET all tiers
+ Url('/api/v1/functest/tiers', 'v1_tiers'),
+
+ # GET /api/v1/functest/tiers/<tier_name>
+ # => GET the info of one tier
+ Url('/api/v1/functest/tiers/<tier_name>', 'v1_tier'),
+
+ # GET /api/v1/functest/tiers/<tier_name>/testcases
+ # => GET all testcases within given tier
+ Url('/api/v1/functest/tiers/<tier_name>/testcases', 'v1_testcases_in_tier')
+]
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml
index 415d5e9d..6107b42a 100644
--- a/functest/ci/config_functest.yaml
+++ b/functest/ci/config_functest.yaml
@@ -133,10 +133,14 @@ vnf:
tenant_name: cloudify_ims
tenant_description: vIMS
config: cloudify_ims.yaml
- orchestra_ims:
- tenant_name: orchestra_ims
- tenant_description: ims deployed with openbaton
- config: orchestra_ims.yaml
+ orchestra_openims:
+ tenant_name: orchestra_openims
+ tenant_description: OpenIMS deployed with Open Baton
+ config: orchestra.yaml
+ orchestra_clearwaterims:
+ tenant_name: orchestra_clearwaterims
+ tenant_description: Clearwater IMS deployed with Open Baton
+ config: orchestra.yaml
opera_ims:
tenant_name: opera_ims
tenant_description: ims deployed with open-o
@@ -193,3 +197,4 @@ energy_recorder:
api_url: http://energy.opnfv.fr/resources
api_user: ""
api_password: ""
+
diff --git a/functest/ci/logging.ini b/functest/ci/logging.ini
index 210c8f5f..f1ab7241 100644
--- a/functest/ci/logging.ini
+++ b/functest/ci/logging.ini
@@ -1,5 +1,5 @@
[loggers]
-keys=root,functest,ci,cli,core,energy,opnfv_tests,utils
+keys=root,functest,api,ci,cli,core,energy,opnfv_tests,utils
[handlers]
keys=console,wconsole,file,null
@@ -16,6 +16,11 @@ level=NOTSET
handlers=file
qualname=functest
+[logger_api]
+level=NOTSET
+handlers=wconsole
+qualname=functest.api
+
[logger_ci]
level=NOTSET
handlers=console
diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py
index b95e1008..e26f4305 100644
--- a/functest/ci/run_tests.py
+++ b/functest/ci/run_tests.py
@@ -1,12 +1,11 @@
#!/usr/bin/env python
-#
-# Author: Jose Lausuch (jose.lausuch@ericsson.com)
+
+# Copyright (c) 2016 Ericsson AB and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
-#
import argparse
import enum
@@ -17,6 +16,7 @@ import os
import pkg_resources
import re
import sys
+import textwrap
import prettytable
@@ -66,17 +66,14 @@ class RunTestsParser(object):
class Runner(object):
def __init__(self):
- self.executed_test_cases = []
+ self.executed_test_cases = {}
self.overall_result = Result.EX_OK
self.clean_flag = True
self.report_flag = False
-
- @staticmethod
- def print_separator(str, count=45):
- line = ""
- for i in range(0, count - 1):
- line += str
- logger.info("%s" % line)
+ self._tiers = tb.TierBuilder(
+ CONST.__getattribute__('INSTALLER_TYPE'),
+ CONST.__getattribute__('DEPLOY_SCENARIO'),
+ pkg_resources.resource_filename('functest', 'ci/testcases.yaml'))
@staticmethod
def source_rc_file():
@@ -109,21 +106,11 @@ class Runner(object):
logger.exception("Cannot get {}'s config options".format(testname))
return None
- def run_test(self, test, tier_name, testcases=None):
+ def run_test(self, test):
if not test.is_enabled():
raise TestNotEnabled(
"The test case {} is not enabled".format(test.get_name()))
- logger.info("\n") # blank line
- self.print_separator("=")
logger.info("Running test case '%s'...", test.get_name())
- self.print_separator("=")
- logger.debug("\n%s" % test)
- self.source_rc_file()
-
- flags = " -t %s" % test.get_name()
- if self.report_flag:
- flags += " -r"
-
result = testcase.TestCase.EX_RUN_ERROR
run_dict = self.get_run_dict(test.get_name())
if run_dict:
@@ -132,7 +119,7 @@ class Runner(object):
cls = getattr(module, run_dict['class'])
test_dict = ft_utils.get_dict_by_test(test.get_name())
test_case = cls(**test_dict)
- self.executed_test_cases.append(test_case)
+ self.executed_test_cases[test.get_name()] = test_case
if self.clean_flag:
if test_case.create_snapshot() != test_case.EX_OK:
return result
@@ -156,7 +143,6 @@ class Runner(object):
run_dict['class']))
else:
raise Exception("Cannot import the class for the test case.")
-
return result
def run_tier(self, tier):
@@ -165,68 +151,60 @@ class Runner(object):
if tests is None or len(tests) == 0:
logger.info("There are no supported test cases in this tier "
"for the given scenario")
- return 0
- logger.info("\n\n") # blank line
- self.print_separator("#")
- logger.info("Running tier '%s'" % tier_name)
- self.print_separator("#")
- logger.debug("\n%s" % tier)
- for test in tests:
- result = self.run_test(test, tier_name)
- if result != testcase.TestCase.EX_OK:
- logger.error("The test case '%s' failed.", test.get_name())
- self.overall_result = Result.EX_ERROR
- if test.is_blocking():
- raise BlockingTestFailed(
- "The test case {} failed and is blocking".format(
- test.get_name()))
+ self.overall_result = Result.EX_ERROR
+ else:
+ logger.info("Running tier '%s'" % tier_name)
+ for test in tests:
+ result = self.run_test(test)
+ if result != testcase.TestCase.EX_OK:
+ logger.error("The test case '%s' failed.", test.get_name())
+ self.overall_result = Result.EX_ERROR
+ if test.is_blocking():
+ raise BlockingTestFailed(
+ "The test case {} failed and is blocking".format(
+ test.get_name()))
+ return self.overall_result
- def run_all(self, tiers):
- summary = ""
+ def run_all(self):
tiers_to_run = []
-
- for tier in tiers.get_tiers():
+ msg = prettytable.PrettyTable(
+ header_style='upper', padding_width=5,
+ field_names=['tiers', 'order', 'CI Loop', 'description',
+ 'testcases'])
+ for tier in self._tiers.get_tiers():
if (len(tier.get_tests()) != 0 and
re.search(CONST.__getattribute__('CI_LOOP'),
tier.get_ci_loop()) is not None):
tiers_to_run.append(tier)
- summary += ("\n - %s:\n\t %s"
- % (tier.get_name(),
- tier.get_test_names()))
-
- logger.info("Tests to be executed:%s" % summary)
+ msg.add_row([tier.get_name(), tier.get_order(),
+ tier.get_ci_loop(),
+ textwrap.fill(tier.description, width=40),
+ textwrap.fill(' '.join([str(x.get_name(
+ )) for x in tier.get_tests()]), width=40)])
+ logger.info("TESTS TO BE EXECUTED:\n\n%s\n", msg)
for tier in tiers_to_run:
self.run_tier(tier)
def main(self, **kwargs):
- _tiers = tb.TierBuilder(
- CONST.__getattribute__('INSTALLER_TYPE'),
- CONST.__getattribute__('DEPLOY_SCENARIO'),
- pkg_resources.resource_filename('functest', 'ci/testcases.yaml'))
-
if kwargs['noclean']:
self.clean_flag = False
-
if kwargs['report']:
self.report_flag = True
-
try:
if kwargs['test']:
self.source_rc_file()
logger.debug("Test args: %s", kwargs['test'])
- if _tiers.get_tier(kwargs['test']):
- self.run_tier(_tiers.get_tier(kwargs['test']))
- elif _tiers.get_test(kwargs['test']):
+ if self._tiers.get_tier(kwargs['test']):
+ self.run_tier(self._tiers.get_tier(kwargs['test']))
+ elif self._tiers.get_test(kwargs['test']):
result = self.run_test(
- _tiers.get_test(kwargs['test']),
- _tiers.get_tier_name(kwargs['test']),
- kwargs['test'])
+ self._tiers.get_test(kwargs['test']))
if result != testcase.TestCase.EX_OK:
logger.error("The test case '%s' failed.",
kwargs['test'])
self.overall_result = Result.EX_ERROR
elif kwargs['test'] == "all":
- self.run_all(_tiers)
+ self.run_all()
else:
logger.error("Unknown test case or tier '%s', "
"or not supported by "
@@ -234,39 +212,45 @@ class Runner(object):
% (kwargs['test'],
CONST.__getattribute__('DEPLOY_SCENARIO')))
logger.debug("Available tiers are:\n\n%s",
- _tiers)
+ self._tiers)
return Result.EX_ERROR
else:
- self.run_all(_tiers)
+ self.run_all()
except BlockingTestFailed:
pass
except Exception:
logger.exception("Failures when running testcase(s)")
self.overall_result = Result.EX_ERROR
+ if not self._tiers.get_test(kwargs['test']):
+ self.summary(self._tiers.get_tier(kwargs['test']))
+ logger.info("Execution exit value: %s" % self.overall_result)
+ return self.overall_result
+ def summary(self, tier=None):
msg = prettytable.PrettyTable(
header_style='upper', padding_width=5,
field_names=['env var', 'value'])
for env_var in ['INSTALLER_TYPE', 'DEPLOY_SCENARIO', 'BUILD_TAG',
'CI_LOOP']:
msg.add_row([env_var, CONST.__getattribute__(env_var)])
- logger.info("Deployment description: \n\n%s\n", msg)
-
- if len(self.executed_test_cases) > 1:
- msg = prettytable.PrettyTable(
- header_style='upper', padding_width=5,
- field_names=['test case', 'project', 'tier',
- 'duration', 'result'])
- for test_case in self.executed_test_cases:
+ logger.info("Deployment description:\n\n%s\n", msg)
+ msg = prettytable.PrettyTable(
+ header_style='upper', padding_width=5,
+ field_names=['test case', 'project', 'tier',
+ 'duration', 'result'])
+ tiers = [tier] if tier else self._tiers.get_tiers()
+ for tier in tiers:
+ for test in tier.get_tests():
+ test_case = self.executed_test_cases[test.get_name()]
result = 'PASS' if(test_case.is_successful(
- ) == test_case.EX_OK) else 'FAIL'
+ ) == test_case.EX_OK) else 'FAIL'
msg.add_row([test_case.case_name, test_case.project_name,
- _tiers.get_tier_name(test_case.case_name),
+ self._tiers.get_tier_name(test_case.case_name),
test_case.get_duration(), result])
- logger.info("FUNCTEST REPORT: \n\n%s\n", msg)
-
- logger.info("Execution exit value: %s" % self.overall_result)
- return self.overall_result
+ for test in tier.get_skipped_test():
+ msg.add_row([test.get_name(), test.get_project(),
+ tier.get_name(), "00:00", "SKIP"])
+ logger.info("FUNCTEST REPORT:\n\n%s\n", msg)
def main():
diff --git a/functest/ci/testcases.yaml b/functest/ci/testcases.yaml
index aae6c3b5..fecd8126 100644
--- a/functest/ci/testcases.yaml
+++ b/functest/ci/testcases.yaml
@@ -269,6 +269,7 @@ tiers:
-
case_name: doctor-notification
+ enabled: false
project_name: doctor
criteria: 100
blocking: false
@@ -494,19 +495,32 @@ tiers:
class: 'AaaVnf'
-
- case_name: orchestra_ims
- enabled: true
+ case_name: orchestra_openims
+ project_name: functest
+ criteria: 100
+ blocking: false
+ description: >-
+ OpenIMS VNF deployment with Open Baton (Orchestra)
+ dependencies:
+ installer: ''
+ scenario: 'os-nosdn-nofeature-ha'
+ run:
+ module: 'functest.opnfv_tests.vnf.ims.orchestra_openims'
+ class: 'OpenImsVnf'
+
+ -
+ case_name: orchestra_clearwaterims
project_name: functest
criteria: 100
blocking: false
description: >-
- VNF deployment with OpenBaton (Orchestra)
+ ClearwaterIMS VNF deployment with Open Baton (Orchestra)
dependencies:
installer: ''
scenario: 'os-nosdn-nofeature-ha'
run:
- module: 'functest.opnfv_tests.vnf.ims.orchestra_ims'
- class: 'ImsVnf'
+ module: 'functest.opnfv_tests.vnf.ims.orchestra_clearwaterims'
+ class: 'ClearwaterImsVnf'
-
case_name: opera_vims
diff --git a/functest/ci/tier_builder.py b/functest/ci/tier_builder.py
index f8038468..d2722dc2 100644
--- a/functest/ci/tier_builder.py
+++ b/functest/ci/tier_builder.py
@@ -1,11 +1,11 @@
#!/usr/bin/env python
+
+# Copyright (c) 2016 Ericsson AB and others.
#
-# jose.lausuch@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
-#
import tier_handler as th
import yaml
@@ -52,11 +52,14 @@ class TierBuilder(object):
dependency=dep,
criteria=dic_testcase['criteria'],
blocking=dic_testcase['blocking'],
- description=dic_testcase['description'])
+ description=dic_testcase['description'],
+ project=dic_testcase['project_name'])
if (testcase.is_compatible(self.ci_installer,
self.ci_scenario) and
testcase.is_enabled()):
tier.add_test(testcase)
+ else:
+ tier.skip_test(testcase)
self.tier_objects.append(tier)
diff --git a/functest/ci/tier_handler.py b/functest/ci/tier_handler.py
index 4f2f14ec..dd3e77ce 100644
--- a/functest/ci/tier_handler.py
+++ b/functest/ci/tier_handler.py
@@ -1,14 +1,18 @@
#!/usr/bin/env python
+
+# Copyright (c) 2016 Ericsson AB and others.
#
-# jose.lausuch@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
-#
import re
+import textwrap
+
+import prettytable
+
LINE_LENGTH = 72
@@ -32,6 +36,7 @@ class Tier(object):
def __init__(self, name, order, ci_loop, description=""):
self.tests_array = []
+ self.skipped_tests_array = []
self.name = name
self.order = order
self.ci_loop = ci_loop
@@ -40,12 +45,18 @@ class Tier(object):
def add_test(self, testcase):
self.tests_array.append(testcase)
+ def skip_test(self, testcase):
+ self.skipped_tests_array.append(testcase)
+
def get_tests(self):
array_tests = []
for test in self.tests_array:
array_tests.append(test)
return array_tests
+ def get_skipped_test(self):
+ return self.skipped_tests_array
+
def get_test_names(self):
array_tests = []
for test in self.tests_array:
@@ -75,31 +86,16 @@ class Tier(object):
return self.ci_loop
def __str__(self):
- lines = split_text(self.description, LINE_LENGTH - 6)
-
- out = ""
- out += ("+%s+\n" % ("=" * (LINE_LENGTH - 2)))
- out += ("| Tier: " + self.name.ljust(LINE_LENGTH - 10) + "|\n")
- out += ("+%s+\n" % ("=" * (LINE_LENGTH - 2)))
- out += ("| Order: " + str(self.order).ljust(LINE_LENGTH - 10) + "|\n")
- out += ("| CI Loop: " + str(self.ci_loop).ljust(LINE_LENGTH - 12) +
- "|\n")
- out += ("| Description:".ljust(LINE_LENGTH - 1) + "|\n")
- for line in lines:
- out += ("| " + line.ljust(LINE_LENGTH - 7) + " |\n")
- out += ("| Test cases:".ljust(LINE_LENGTH - 1) + "|\n")
- tests = self.get_test_names()
- if len(tests) > 0:
- for i in range(len(tests)):
- out += ("| - %s |\n" % tests[i].ljust(LINE_LENGTH - 9))
- else:
- out += ("| (There are no supported test cases "
- .ljust(LINE_LENGTH - 1) + "|\n")
- out += ("| in this tier for the given scenario) "
- .ljust(LINE_LENGTH - 1) + "|\n")
- out += ("|".ljust(LINE_LENGTH - 1) + "|\n")
- out += ("+%s+\n" % ("-" * (LINE_LENGTH - 2)))
- return out
+ msg = prettytable.PrettyTable(
+ header_style='upper', padding_width=5,
+ field_names=['tiers', 'order', 'CI Loop', 'description',
+ 'testcases'])
+ msg.add_row(
+ [self.name, self.order, self.ci_loop,
+ textwrap.fill(self.description, width=40),
+ textwrap.fill(' '.join([str(x.get_name(
+ )) for x in self.get_tests()]), width=40)])
+ return msg.get_string()
class TestCase(object):
@@ -109,13 +105,15 @@ class TestCase(object):
dependency,
criteria,
blocking,
- description=""):
+ description="",
+ project=""):
self.name = name
self.enabled = enabled
self.dependency = dependency
self.criteria = criteria
self.blocking = blocking
self.description = description
+ self.project = project
@staticmethod
def is_none(item):
@@ -147,26 +145,16 @@ class TestCase(object):
def is_blocking(self):
return self.blocking
+ def get_project(self):
+ return self.project
+
def __str__(self):
- lines = split_text(self.description, LINE_LENGTH - 6)
-
- out = ""
- out += ("+%s+\n" % ("=" * (LINE_LENGTH - 2)))
- out += ("| Testcase: " + self.name.ljust(LINE_LENGTH - 14) + "|\n")
- out += ("+%s+\n" % ("=" * (LINE_LENGTH - 2)))
- out += ("| Description:".ljust(LINE_LENGTH - 1) + "|\n")
- for line in lines:
- out += ("| " + line.ljust(LINE_LENGTH - 7) + " |\n")
- out += ("| Criteria: " +
- str(self.criteria).ljust(LINE_LENGTH - 14) + "|\n")
- out += ("| Dependencies:".ljust(LINE_LENGTH - 1) + "|\n")
- installer = self.dependency.get_installer()
- scenario = self.dependency.get_scenario()
- out += ("| - Installer:" + installer.ljust(LINE_LENGTH - 17) + "|\n")
- out += ("| - Scenario :" + scenario.ljust(LINE_LENGTH - 17) + "|\n")
- out += ("|".ljust(LINE_LENGTH - 1) + "|\n")
- out += ("+%s+\n" % ("-" * (LINE_LENGTH - 2)))
- return out
+ msg = prettytable.PrettyTable(
+ header_style='upper', padding_width=5,
+ field_names=['test case', 'description', 'criteria', 'dependency'])
+ msg.add_row([self.name, textwrap.fill(self.description, width=40),
+ self.criteria, self.dependency])
+ return msg.get_string()
class Dependency(object):
@@ -182,6 +170,7 @@ class Dependency(object):
return self.scenario
def __str__(self):
- return ("Dependency info:\n"
- " installer: " + self.installer + "\n"
- " scenario: " + self.scenario + "\n")
+ delimitator = "\n" if self.get_installer(
+ ) and self.get_scenario() else ""
+ return "{}{}{}".format(self.get_installer(), delimitator,
+ self.get_scenario())
diff --git a/functest/cli/commands/cli_env.py b/functest/cli/commands/cli_env.py
index 99d36996..72a870b5 100644
--- a/functest/cli/commands/cli_env.py
+++ b/functest/cli/commands/cli_env.py
@@ -16,7 +16,7 @@ from functest.utils.constants import CONST
import functest.utils.functest_utils as ft_utils
-class CliEnv(object):
+class Env(object):
def __init__(self):
pass
@@ -56,17 +56,14 @@ class CliEnv(object):
if self.status(verbose=False) == 0:
STATUS = "ready"
- msg = prettytable.PrettyTable(
- header_style='upper', padding_width=5,
- field_names=['Functest Environment', 'value'])
- msg.add_row(['INSTALLER', installer_info])
- msg.add_row(['SCENARIO', scenario])
- msg.add_row(['POD', node])
- if build_tag:
- msg.add_row(['BUILD TAG', build_tag])
- msg.add_row(['DEBUG FLAG', is_debug])
- msg.add_row(['STATUS', STATUS])
- click.echo(msg.get_string())
+ env_info = {'INSTALLER': installer_info,
+ 'SCENARIO': scenario,
+ 'POD': node,
+ 'DEBUG FLAG': is_debug,
+ 'BUILD_TAG': build_tag,
+ 'STATUS': STATUS}
+
+ return env_info
def status(self, verbose=True):
ret_val = 0
@@ -78,3 +75,19 @@ class CliEnv(object):
click.echo("Functest environment ready to run tests.\n")
return ret_val
+
+
+class CliEnv(Env):
+
+ def __init__(self):
+ super(CliEnv, self).__init__()
+
+ def show(self):
+ env_info = super(CliEnv, self).show()
+ msg = prettytable.PrettyTable(
+ header_style='upper', padding_width=5,
+ field_names=['Functest Environment', 'value'])
+ for key, value in env_info.iteritems():
+ if key is not None:
+ msg.add_row([key, value])
+ click.echo(msg.get_string())
diff --git a/functest/cli/commands/cli_os.py b/functest/cli/commands/cli_os.py
index f4ec1661..e97ab080 100644
--- a/functest/cli/commands/cli_os.py
+++ b/functest/cli/commands/cli_os.py
@@ -18,7 +18,7 @@ import functest.utils.openstack_clean as os_clean
import functest.utils.openstack_snapshot as os_snapshot
-class CliOpenStack(object):
+class OpenStack(object):
def __init__(self):
self.os_auth_url = CONST.__getattribute__('OS_AUTH_URL')
@@ -43,9 +43,11 @@ class CliOpenStack(object):
@staticmethod
def show_credentials():
+ dic_credentials = {}
for key, value in os.environ.items():
if key.startswith('OS_'):
- click.echo("{}={}".format(key, value))
+ dic_credentials.update({key: value})
+ return dic_credentials
def check(self):
self.ping_endpoint()
@@ -88,3 +90,16 @@ class CliOpenStack(object):
"'functest openstack snapshot-create'")
return
os_clean.main()
+
+
+class CliOpenStack(OpenStack):
+
+ def __init__(self):
+ super(CliOpenStack, self).__init__()
+
+ @staticmethod
+ def show_credentials():
+ dic_credentials = OpenStack.show_credentials()
+ for key, value in dic_credentials.items():
+ if key.startswith('OS_'):
+ click.echo("{}={}".format(key, value))
diff --git a/functest/cli/commands/cli_testcase.py b/functest/cli/commands/cli_testcase.py
index cb3d4739..65dd9ab7 100644
--- a/functest/cli/commands/cli_testcase.py
+++ b/functest/cli/commands/cli_testcase.py
@@ -20,7 +20,7 @@ import functest.utils.functest_utils as ft_utils
import functest.utils.functest_vacation as vacation
-class CliTestcase(object):
+class Testcase(object):
def __init__(self):
self.tiers = tb.TierBuilder(
@@ -33,15 +33,11 @@ class CliTestcase(object):
for tier in self.tiers.get_tiers():
for test in tier.get_tests():
summary += (" %s\n" % test.get_name())
- click.echo(summary)
+ return summary
def show(self, testname):
description = self.tiers.get_test(testname)
- if description is None:
- click.echo("The test case '%s' does not exist or is not supported."
- % testname)
-
- click.echo(description)
+ return description
@staticmethod
def run(testname, noclean=False, report=False):
@@ -62,3 +58,20 @@ class CliTestcase(object):
for test in tests:
cmd = "run_tests {}-t {}".format(flags, test)
ft_utils.execute_command(cmd)
+
+
+class CliTestcase(Testcase):
+
+ def __init__(self):
+ super(CliTestcase, self).__init__()
+
+ def list(self):
+ click.echo(super(CliTestcase, self).list())
+
+ def show(self, testname):
+ testcase_show = super(CliTestcase, self).show(testname)
+ if testcase_show:
+ click.echo(testcase_show)
+ else:
+ click.echo("The test case '%s' does not exist or is not supported."
+ % testname)
diff --git a/functest/cli/commands/cli_tier.py b/functest/cli/commands/cli_tier.py
index 9b2e60ba..995354bb 100644
--- a/functest/cli/commands/cli_tier.py
+++ b/functest/cli/commands/cli_tier.py
@@ -19,7 +19,7 @@ from functest.utils.constants import CONST
import functest.utils.functest_utils as ft_utils
-class CliTier(object):
+class Tier(object):
def __init__(self):
self.tiers = tb.TierBuilder(
@@ -34,26 +34,23 @@ class CliTier(object):
% (tier.get_order(),
tier.get_name(),
tier.get_test_names()))
- click.echo(summary)
+ return summary
def show(self, tiername):
tier = self.tiers.get_tier(tiername)
if tier is None:
- tier_names = self.tiers.get_tier_names()
- click.echo("The tier with name '%s' does not exist. "
- "Available tiers are:\n %s\n" % (tiername, tier_names))
+ return None
else:
- click.echo(self.tiers.get_tier(tiername))
+ tier_info = self.tiers.get_tier(tiername)
+ return tier_info
def gettests(self, tiername):
tier = self.tiers.get_tier(tiername)
if tier is None:
- tier_names = self.tiers.get_tier_names()
- click.echo("The tier with name '%s' does not exist. "
- "Available tiers are:\n %s\n" % (tiername, tier_names))
+ return None
else:
tests = tier.get_test_names()
- click.echo("Test cases in tier '%s':\n %s\n" % (tiername, tests))
+ return tests
@staticmethod
def run(tiername, noclean=False, report=False):
@@ -70,3 +67,30 @@ class CliTier(object):
else:
cmd = "run_tests {}-t {}".format(flags, tiername)
ft_utils.execute_command(cmd)
+
+
+class CliTier(Tier):
+
+ def __init__(self):
+ super(CliTier, self).__init__()
+
+ def list(self):
+ click.echo(super(CliTier, self).list())
+
+ def show(self, tiername):
+ tier_info = super(CliTier, self).show(tiername)
+ if tier_info:
+ click.echo(tier_info)
+ else:
+ tier_names = self.tiers.get_tier_names()
+ click.echo("The tier with name '%s' does not exist. "
+ "Available tiers are:\n %s\n" % (tiername, tier_names))
+
+ def gettests(self, tiername):
+ tests = super(CliTier, self).gettests(tiername)
+ if tests:
+ click.echo("Test cases in tier '%s':\n %s\n" % (tiername, tests))
+ else:
+ tier_names = self.tiers.get_tier_names()
+ click.echo("The tier with name '%s' does not exist. "
+ "Available tiers are:\n %s\n" % (tiername, tier_names))
diff --git a/functest/energy/energy.py b/functest/energy/energy.py
index 580bc6b0..c410e84f 100644
--- a/functest/energy/energy.py
+++ b/functest/energy/energy.py
@@ -16,6 +16,7 @@ import urllib
from functools import wraps
import requests
+import urllib3
import functest.utils.functest_utils as ft_utils
@@ -76,7 +77,7 @@ class EnergyRecorder(object):
INITIAL_STEP = "running"
# Default connection timeout
- CONNECTION_TIMOUT = 1
+ CONNECTION_TIMOUT = urllib3.Timeout(connect=1, read=3)
@staticmethod
def load_config():
@@ -104,13 +105,13 @@ class EnergyRecorder(object):
"API recorder at: " + energy_recorder_uri + uri_comp)
# Creds
- user = ft_utils.get_functest_config(
+ creds_usr = ft_utils.get_functest_config(
"energy_recorder.api_user")
- password = ft_utils.get_functest_config(
+ creds_pass = ft_utils.get_functest_config(
"energy_recorder.api_password")
- if user != "" and password != "":
- energy_recorder_api_auth = (user, password)
+ if creds_usr != "" and creds_pass != "":
+ energy_recorder_api_auth = (creds_usr, creds_pass)
else:
energy_recorder_api_auth = None
diff --git a/functest/opnfv_tests/vnf/ims/orchestra.yaml b/functest/opnfv_tests/vnf/ims/orchestra.yaml
new file mode 100644
index 00000000..7b43c001
--- /dev/null
+++ b/functest/opnfv_tests/vnf/ims/orchestra.yaml
@@ -0,0 +1,61 @@
+tenant_images:
+ orchestrator:
+ ubuntu-14.04-server-cloudimg-amd64-disk1: http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
+ orchestra_openims:
+ openims: http://marketplace.openbaton.org:8082/api/v1/images/52e2ccc0-1dce-4663-894d-28aab49323aa/img
+ orchestra_clearwaterims:
+ ubuntu-14.04-server-cloudimg-amd64-disk1: http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
+mano:
+ name: OpenBaton
+ version: '3.2.0'
+ requirements:
+ flavor:
+ name: openbaton
+ ram_min: 4096
+ disk: 5
+ vcpus: 2
+ image: 'ubuntu-14.04-server-cloudimg-amd64-disk1'
+ bootstrap:
+ url: http://get.openbaton.org/bootstraps/bootstrap_3.2.0_opnfv/bootstrap
+ config:
+ url: http://get.openbaton.org/bootstraps/bootstrap_3.2.0_opnfv/bootstrap-config-file
+ gvnfm:
+ userdata:
+ url: https://raw.githubusercontent.com/openbaton/generic-vnfm/3.2.0/src/main/resources/user-data.sh
+ credentials:
+ username: admin
+ password: openbaton
+
+orchestra_openims:
+ name: OpenIMS
+ descriptor:
+ url: http://marketplace.openbaton.org:8082/api/v1/nsds/fokus/OpenImsCore/3.2.0/json
+ requirements:
+ flavor:
+ name: m1.small
+ ram_min: 2048
+ disk: 5
+ vcpus: 2
+ test:
+ scscf:
+ ports: [3870, 6060]
+ pcscf:
+ ports: [4060]
+ icscf:
+ ports: [3869, 5060]
+ fhoss:
+ ports: [3868]
+ bind9:
+ ports: []
+
+orchestra_clearwaterims:
+ name: Clearwater IMS
+ descriptor:
+ url: http://marketplace.openbaton.org:8082/api/v1/nsds/fokus/ClearwaterIMS/3.2.0/json
+ requirements:
+ flavor:
+ name: m1.small
+ ram_min: 2048
+ disk: 5
+ vcpus: 2
+ test: \ No newline at end of file
diff --git a/functest/opnfv_tests/vnf/ims/orchestra_clearwaterims.py b/functest/opnfv_tests/vnf/ims/orchestra_clearwaterims.py
new file mode 100644
index 00000000..9e14711c
--- /dev/null
+++ b/functest/opnfv_tests/vnf/ims/orchestra_clearwaterims.py
@@ -0,0 +1,684 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2016 Orange and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""Orchestra Clearwater IMS testcase implementation."""
+
+import json
+import logging
+import os
+import socket
+import time
+import pkg_resources
+import yaml
+
+from snaps.openstack.create_image import OpenStackImage, ImageSettings
+from snaps.openstack.create_flavor import OpenStackFlavor, FlavorSettings
+from snaps.openstack.create_security_group import (
+ OpenStackSecurityGroup,
+ SecurityGroupSettings,
+ SecurityGroupRuleSettings,
+ Direction,
+ Protocol)
+from snaps.openstack.create_network import (
+ OpenStackNetwork,
+ NetworkSettings,
+ SubnetSettings,
+ PortSettings)
+from snaps.openstack.create_router import OpenStackRouter, RouterSettings
+from snaps.openstack.os_credentials import OSCreds
+from snaps.openstack.create_instance import (
+ VmInstanceSettings,
+ OpenStackVmInstance)
+from functest.opnfv_tests.openstack.snaps import snaps_utils
+
+import functest.core.vnf as vnf
+import functest.utils.openstack_utils as os_utils
+from functest.utils.constants import CONST
+
+from org.openbaton.cli.errors.errors import NfvoException
+from org.openbaton.cli.agents.agents import MainAgent
+
+
+__author__ = "Pauls, Michael <michael.pauls@fokus.fraunhofer.de>"
+# ----------------------------------------------------------
+#
+# UTILS
+#
+# -----------------------------------------------------------
+
+
+def get_config(parameter, file_path):
+ """
+ Get config parameter.
+
+ Returns the value of a given parameter in file.yaml
+ parameter must be given in string format with dots
+ Example: general.openstack.image_name
+ """
+ with open(file_path) as config_file:
+ file_yaml = yaml.safe_load(config_file)
+ config_file.close()
+ value = file_yaml
+ for element in parameter.split("."):
+ value = value.get(element)
+ if value is None:
+ raise ValueError("The parameter %s is not defined in"
+ " reporting.yaml", parameter)
+ return value
+
+
+def servertest(host, port):
+ """Method to test that a server is reachable at IP:port"""
+ args = socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM)
+ for family, socktype, proto, canonname, sockaddr in args:
+ sock = socket.socket(family, socktype, proto)
+ try:
+ sock.connect(sockaddr)
+ except socket.error:
+ return False
+ else:
+ sock.close()
+ return True
+
+
+def get_userdata(orchestrator=dict):
+ """Build userdata for Open Baton machine"""
+ userdata = "#!/bin/bash\n"
+ userdata += "echo \"Executing userdata...\"\n"
+ userdata += "set -x\n"
+ userdata += "set -e\n"
+ userdata += "echo \"Set nameserver to '8.8.8.8'...\"\n"
+ userdata += "echo \"nameserver 8.8.8.8\" >> /etc/resolv.conf\n"
+ userdata += "echo \"Install curl...\"\n"
+ userdata += "apt-get install curl\n"
+ userdata += "echo \"Inject public key...\"\n"
+ userdata += ("echo \"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuPXrV3"
+ "geeHc6QUdyUr/1Z+yQiqLcOskiEGBiXr4z76MK4abiFmDZ18OMQlc"
+ "fl0p3kS0WynVgyaOHwZkgy/DIoIplONVr2CKBKHtPK+Qcme2PVnCtv"
+ "EqItl/FcD+1h5XSQGoa+A1TSGgCod/DPo+pes0piLVXP8Ph6QS1k7S"
+ "ic7JDeRQ4oT1bXYpJ2eWBDMfxIWKZqcZRiGPgMIbJ1iEkxbpeaAd9O"
+ "4MiM9nGCPESmed+p54uYFjwEDlAJZShcAZziiZYAvMZhvAhe6USljc"
+ "7YAdalAnyD/jwCHuwIrUw/lxo7UdNCmaUxeobEYyyFA1YVXzpNFZya"
+ "XPGAAYIJwEq/ openbaton@opnfv\" >> /home/ubuntu/.ssh/aut"
+ "horized_keys\n")
+ userdata += "echo \"Download bootstrap...\"\n"
+ userdata += ("curl -s %s "
+ "> ./bootstrap\n" % orchestrator['bootstrap']['url'])
+ userdata += ("curl -s %s" "> ./config_file\n" %
+ orchestrator['bootstrap']['config']['url'])
+ userdata += ("echo \"Disable usage of mysql...\"\n")
+ userdata += "sed -i s/mysql=.*/mysql=no/g /config_file\n"
+ userdata += ("echo \"Setting 'rabbitmq_broker_ip' to '%s'\"\n"
+ % orchestrator['details']['fip'].ip)
+ userdata += ("sed -i s/rabbitmq_broker_ip=localhost/rabbitmq_broker_ip"
+ "=%s/g /config_file\n" % orchestrator['details']['fip'].ip)
+ userdata += "echo \"Set autostart of components to 'false'\"\n"
+ userdata += "export OPENBATON_COMPONENT_AUTOSTART=false\n"
+ userdata += "echo \"Execute bootstrap...\"\n"
+ bootstrap = "sh ./bootstrap release -configFile=./config_file"
+ userdata += bootstrap + "\n"
+ userdata += "echo \"Setting 'nfvo.plugin.timeout' to '300000'\"\n"
+ userdata += ("echo \"nfvo.plugin.timeout=600000\" >> "
+ "/etc/openbaton/openbaton-nfvo.properties\n")
+ userdata += (
+ "wget %s -O /etc/openbaton/openbaton-vnfm-generic-user-data.sh\n" %
+ orchestrator['gvnfm']['userdata']['url'])
+ userdata += "sed -i '113i"'\ \ \ \ '"sleep 60' " \
+ "/etc/openbaton/openbaton-vnfm-generic-user-data.sh\n"
+ userdata += "echo \"Starting NFVO\"\n"
+ userdata += "service openbaton-nfvo restart\n"
+ userdata += "echo \"Starting Generic VNFM\"\n"
+ userdata += "service openbaton-vnfm-generic restart\n"
+ userdata += "echo \"...end of userdata...\"\n"
+ return userdata
+
+
+class ClearwaterImsVnf(vnf.VnfOnBoarding):
+ """Clearwater IMS VNF deployed with openBaton orchestrator"""
+
+ logger = logging.getLogger(__name__)
+
+ def __init__(self, **kwargs):
+ if "case_name" not in kwargs:
+ kwargs["case_name"] = "orchestra_clearwaterims"
+ super(ClearwaterImsVnf, self).__init__(**kwargs)
+ # self.logger = logging.getLogger("functest.ci.run_tests.orchestra")
+ self.logger.info("kwargs %s", (kwargs))
+
+ self.case_dir = pkg_resources.resource_filename(
+ 'functest', 'opnfv_tests/vnf/ims/')
+ self.data_dir = CONST.__getattribute__('dir_ims_data')
+ self.test_dir = CONST.__getattribute__('dir_repo_vims_test')
+ self.created_resources = []
+ self.logger.info("%s VNF onboarding test starting", self.case_name)
+
+ try:
+ self.config = CONST.__getattribute__(
+ 'vnf_{}_config'.format(self.case_name))
+ except BaseException:
+ raise Exception("Orchestra VNF config file not found")
+ config_file = self.case_dir + self.config
+
+ self.mano = dict(
+ get_config("mano", config_file),
+ details={}
+ )
+ self.logger.debug("Orchestrator configuration %s", self.mano)
+
+ self.details['orchestrator'] = dict(
+ name=self.mano['name'],
+ version=self.mano['version'],
+ status='ERROR',
+ result=''
+ )
+
+ self.vnf = dict(
+ get_config(self.case_name, config_file),
+ )
+ self.logger.debug("VNF configuration: %s", self.vnf)
+
+ self.details['vnf'] = dict(
+ name=self.vnf['name'],
+ )
+
+ self.details['test_vnf'] = dict(
+ name=self.case_name,
+ )
+
+ # Orchestra base Data directory creation
+ if not os.path.exists(self.data_dir):
+ os.makedirs(self.data_dir)
+
+ self.images = get_config(
+ "tenant_images.%s" %
+ self.case_name, config_file)
+ self.images.update(
+ get_config(
+ "tenant_images.%s" %
+ self.case_name,
+ config_file))
+ self.snaps_creds = None
+
+ def prepare(self):
+ """Prepare testscase (Additional pre-configuration steps)."""
+ super(ClearwaterImsVnf, self).prepare()
+
+ self.logger.info("Additional pre-configuration steps")
+ self.logger.info("creds %s", (self.creds))
+
+ self.snaps_creds = OSCreds(
+ username=self.creds['username'],
+ password=self.creds['password'],
+ auth_url=self.creds['auth_url'],
+ project_name=self.creds['tenant'],
+ identity_api_version=int(os_utils.get_keystone_client_version()))
+
+ self.prepare_images()
+ self.prepare_flavor()
+ self.prepare_security_groups()
+ self.prepare_network()
+ self.prepare_floating_ip()
+
+ def prepare_images(self):
+ """Upload images if they doen't exist yet"""
+ self.logger.info("Upload images if they doen't exist yet")
+ for image_name, image_url in self.images.iteritems():
+ self.logger.info("image: %s, url: %s", image_name, image_url)
+ if image_url and image_name:
+ image = OpenStackImage(
+ self.snaps_creds,
+ ImageSettings(name=image_name,
+ image_user='cloud',
+ img_format='qcow2',
+ url=image_url))
+ image.create()
+ # self.created_resources.append(image);
+
+ def prepare_security_groups(self):
+ """Create Open Baton security group if it doesn't exist yet"""
+ self.logger.info(
+ "Creating security group for Open Baton if not yet existing...")
+ sg_rules = list()
+ sg_rules.append(
+ SecurityGroupRuleSettings(
+ sec_grp_name="orchestra-sec-group-allowall",
+ direction=Direction.ingress,
+ protocol=Protocol.tcp,
+ port_range_min=1,
+ port_range_max=65535))
+ sg_rules.append(
+ SecurityGroupRuleSettings(
+ sec_grp_name="orchestra-sec-group-allowall",
+ direction=Direction.egress,
+ protocol=Protocol.tcp,
+ port_range_min=1,
+ port_range_max=65535))
+ sg_rules.append(
+ SecurityGroupRuleSettings(
+ sec_grp_name="orchestra-sec-group-allowall",
+ direction=Direction.ingress,
+ protocol=Protocol.udp,
+ port_range_min=1,
+ port_range_max=65535))
+ sg_rules.append(
+ SecurityGroupRuleSettings(
+ sec_grp_name="orchestra-sec-group-allowall",
+ direction=Direction.egress,
+ protocol=Protocol.udp,
+ port_range_min=1,
+ port_range_max=65535))
+ sg_rules.append(
+ SecurityGroupRuleSettings(
+ sec_grp_name="orchestra-sec-group-allowall",
+ direction=Direction.ingress,
+ protocol=Protocol.icmp))
+ sg_rules.append(
+ SecurityGroupRuleSettings(
+ sec_grp_name="orchestra-sec-group-allowall",
+ direction=Direction.egress,
+ protocol=Protocol.icmp))
+ # sg_rules.append(
+ # SecurityGroupRuleSettings(
+ # sec_grp_name="orchestra-sec-group-allowall",
+ # direction=Direction.ingress,
+ # protocol=Protocol.icmp,
+ # port_range_min=-1,
+ # port_range_max=-1))
+ # sg_rules.append(
+ # SecurityGroupRuleSettings(
+ # sec_grp_name="orchestra-sec-group-allowall",
+ # direction=Direction.egress,
+ # protocol=Protocol.icmp,
+ # port_range_min=-1,
+ # port_range_max=-1))
+
+ security_group = OpenStackSecurityGroup(
+ self.snaps_creds,
+ SecurityGroupSettings(
+ name="orchestra-sec-group-allowall",
+ rule_settings=sg_rules))
+
+ security_group_info = security_group.create()
+ self.created_resources.append(security_group)
+ self.mano['details']['sec_group'] = security_group_info.name
+ self.logger.info(
+ "Security group orchestra-sec-group-allowall prepared")
+
+ def prepare_flavor(self):
+ """Create Open Baton flavor if it doesn't exist yet"""
+ self.logger.info(
+ "Create Flavor for Open Baton NFVO if not yet existing")
+
+ flavor_settings = FlavorSettings(
+ name=self.mano['requirements']['flavor']['name'],
+ ram=self.mano['requirements']['flavor']['ram_min'],
+ disk=self.mano['requirements']['flavor']['disk'],
+ vcpus=self.mano['requirements']['flavor']['vcpus'])
+ flavor = OpenStackFlavor(self.snaps_creds, flavor_settings)
+ flavor_info = flavor.create()
+ self.created_resources.append(flavor)
+ self.mano['details']['flavor'] = {}
+ self.mano['details']['flavor']['name'] = flavor_settings.name
+ self.mano['details']['flavor']['id'] = flavor_info.id
+
+ def prepare_network(self):
+ """Create network/subnet/router if they doen't exist yet"""
+ self.logger.info(
+ "Creating network/subnet/router if they doen't exist yet...")
+ subnet_settings = SubnetSettings(
+ name='%s_subnet' %
+ self.case_name,
+ cidr="192.168.100.0/24")
+ network_settings = NetworkSettings(
+ name='%s_net' %
+ self.case_name,
+ subnet_settings=[subnet_settings])
+ orchestra_network = OpenStackNetwork(
+ self.snaps_creds, network_settings)
+ orchestra_network_info = orchestra_network.create()
+ self.mano['details']['network'] = {}
+ self.mano['details']['network']['id'] = orchestra_network_info.id
+ self.mano['details']['network']['name'] = orchestra_network_info.name
+ self.mano['details']['external_net_name'] = snaps_utils.\
+ get_ext_net_name(self.snaps_creds)
+ self.created_resources.append(orchestra_network)
+ orchestra_router = OpenStackRouter(
+ self.snaps_creds,
+ RouterSettings(
+ name='%s_router' %
+ self.case_name,
+ external_gateway=self.mano['details']['external_net_name'],
+ internal_subnets=[
+ subnet_settings.name]))
+ orchestra_router.create()
+ self.created_resources.append(orchestra_router)
+ self.logger.info("Created network and router for Open Baton NFVO...")
+
+ def prepare_floating_ip(self):
+ """Select/Create Floating IP if it doesn't exist yet"""
+ self.logger.info("Retrieving floating IP for Open Baton NFVO")
+ neutron_client = snaps_utils.neutron_utils.neutron_client(
+ self.snaps_creds)
+ # Finding Tenant ID to check to which tenant the Floating IP belongs
+ tenant_id = os_utils.get_tenant_id(
+ os_utils.get_keystone_client(self.creds),
+ self.tenant_name)
+ # Use os_utils to retrieve complete information of Floating IPs
+ floating_ips = os_utils.get_floating_ips(neutron_client)
+ my_floating_ips = []
+ # Filter Floating IPs with tenant id
+ for floating_ip in floating_ips:
+ # self.logger.info("Floating IP: %s", floating_ip)
+ if floating_ip.get('tenant_id') == tenant_id:
+ my_floating_ips.append(floating_ip.get('floating_ip_address'))
+ # Select if Floating IP exist else create new one
+ if len(my_floating_ips) >= 1:
+ # Get Floating IP object from snaps for clean up
+ snaps_floating_ips = snaps_utils.neutron_utils.get_floating_ips(
+ neutron_client)
+ for my_floating_ip in my_floating_ips:
+ for snaps_floating_ip in snaps_floating_ips:
+ if snaps_floating_ip.ip == my_floating_ip:
+ self.mano['details']['fip'] = snaps_floating_ip
+ self.logger.info(
+ "Selected floating IP for Open Baton NFVO %s",
+ (self.mano['details']['fip'].ip))
+ break
+ if self.mano['details']['fip'] is not None:
+ break
+ else:
+ self.logger.info("Creating floating IP for Open Baton NFVO")
+ self.mano['details']['fip'] = snaps_utils.neutron_utils.\
+ create_floating_ip(
+ neutron_client,
+ self.mano['details']['external_net_name'])
+ self.logger.info(
+ "Created floating IP for Open Baton NFVO %s",
+ (self.mano['details']['fip'].ip))
+
+ def get_vim_descriptor(self):
+ """"Create VIM descriptor to be used for onboarding"""
+ self.logger.info(
+ "Building VIM descriptor with PoP creds: %s",
+ self.creds)
+ # Depending on API version either tenant ID or project name must be
+ # used
+ if os_utils.is_keystone_v3():
+ self.logger.info(
+ "Using v3 API of OpenStack... -> Using OS_PROJECT_ID")
+ project_id = os_utils.get_tenant_id(
+ os_utils.get_keystone_client(),
+ self.creds.get("project_name"))
+ else:
+ self.logger.info(
+ "Using v2 API of OpenStack... -> Using OS_TENANT_NAME")
+ project_id = self.creds.get("tenant_name")
+ self.logger.debug("VIM project/tenant id: %s", project_id)
+ vim_json = {
+ "name": "vim-instance",
+ "authUrl": self.creds.get("auth_url"),
+ "tenant": project_id,
+ "username": self.creds.get("username"),
+ "password": self.creds.get("password"),
+ "securityGroups": [
+ self.mano['details']['sec_group']
+ ],
+ "type": "openstack",
+ "location": {
+ "name": "opnfv",
+ "latitude": "52.525876",
+ "longitude": "13.314400"
+ }
+ }
+ self.logger.info("Built VIM descriptor: %s", vim_json)
+ return vim_json
+
+ def deploy_orchestrator(self):
+ self.logger.info("Deploying Open Baton...")
+ self.logger.info("Details: %s", self.mano['details'])
+ start_time = time.time()
+
+ self.logger.info("Creating orchestra instance...")
+ userdata = get_userdata(self.mano)
+ self.logger.info("flavor: %s\n"
+ "image: %s\n"
+ "network_id: %s\n",
+ self.mano['details']['flavor']['name'],
+ self.mano['requirements']['image'],
+ self.mano['details']['network']['id'])
+ self.logger.debug("userdata: %s\n", userdata)
+ # setting up image
+ image_settings = ImageSettings(
+ name=self.mano['requirements']['image'],
+ image_user='ubuntu',
+ exists=True)
+ # setting up port
+ port_settings = PortSettings(
+ name='%s_port' % self.case_name,
+ network_name=self.mano['details']['network']['name'])
+ # build configuration of vm
+ orchestra_settings = VmInstanceSettings(
+ name=self.case_name,
+ flavor=self.mano['details']['flavor']['name'],
+ port_settings=[port_settings],
+ security_group_names=[self.mano['details']['sec_group']],
+ userdata=userdata)
+ orchestra_vm = OpenStackVmInstance(self.snaps_creds,
+ orchestra_settings,
+ image_settings)
+
+ orchestra_vm.create()
+ self.created_resources.append(orchestra_vm)
+ self.mano['details']['id'] = orchestra_vm.get_vm_info()['id']
+ self.logger.info(
+ "Created orchestra instance: %s",
+ self.mano['details']['id'])
+
+ self.logger.info("Associating floating ip: '%s' to VM '%s' ",
+ self.mano['details']['fip'].ip,
+ self.case_name)
+ nova_client = os_utils.get_nova_client()
+ if not os_utils.add_floating_ip(
+ nova_client,
+ self.mano['details']['id'],
+ self.mano['details']['fip'].ip):
+ duration = time.time() - start_time
+ self.details["orchestrator"].update(
+ status='FAIL', duration=duration)
+ self.logger.error("Cannot associate floating IP to VM.")
+ return False
+
+ self.logger.info("Waiting for Open Baton NFVO to be up and running...")
+ timeout = 0
+ while timeout < 200:
+ if servertest(
+ self.mano['details']['fip'].ip,
+ "8080"):
+ break
+ else:
+ self.logger.info(
+ "Open Baton NFVO is not started yet (%ss)",
+ (timeout * 5))
+ time.sleep(5)
+ timeout += 1
+
+ if timeout >= 200:
+ duration = time.time() - start_time
+ self.details["orchestrator"].update(
+ status='FAIL', duration=duration)
+ self.logger.error("Open Baton is not started correctly")
+ return False
+
+ self.logger.info("Waiting for all components to be up and running...")
+ time.sleep(60)
+ duration = time.time() - start_time
+ self.details["orchestrator"].update(status='PASS', duration=duration)
+ self.logger.info("Deploy Open Baton NFVO: OK")
+ return True
+
+ def deploy_vnf(self):
+ start_time = time.time()
+ self.logger.info("Deploying %s...", self.vnf['name'])
+
+ main_agent = MainAgent(
+ nfvo_ip=self.mano['details']['fip'].ip,
+ nfvo_port=8080,
+ https=False,
+ version=1,
+ username=self.mano['credentials']['username'],
+ password=self.mano['credentials']['password'])
+
+ self.logger.info(
+ "Create %s Flavor if not existing", self.vnf['name'])
+ flavor_settings = FlavorSettings(
+ name=self.vnf['requirements']['flavor']['name'],
+ ram=self.vnf['requirements']['flavor']['ram_min'],
+ disk=self.vnf['requirements']['flavor']['disk'],
+ vcpus=self.vnf['requirements']['flavor']['vcpus'])
+ flavor = OpenStackFlavor(self.snaps_creds, flavor_settings)
+ flavor_info = flavor.create()
+ self.logger.debug("Flavor id: %s", flavor_info.id)
+
+ self.logger.info("Getting project 'default'...")
+ project_agent = main_agent.get_agent("project", "")
+ for project in json.loads(project_agent.find()):
+ if project.get("name") == "default":
+ self.mano['details']['project_id'] = project.get("id")
+ self.logger.info("Found project 'default': %s", project)
+ break
+
+ vim_json = self.get_vim_descriptor()
+ self.logger.info("Registering VIM: %s", vim_json)
+
+ main_agent.get_agent(
+ "vim", project_id=self.mano['details']['project_id']).create(
+ entity=json.dumps(vim_json))
+
+ market_agent = main_agent.get_agent(
+ "market", project_id=self.mano['details']['project_id'])
+
+ try:
+ self.logger.info("sending: %s", self.vnf['descriptor']['url'])
+ nsd = market_agent.create(entity=self.vnf['descriptor']['url'])
+ if nsd.get('id') is None:
+ self.logger.error("NSD not onboarded correctly")
+ duration = time.time() - start_time
+ self.details["vnf"].update(status='FAIL', duration=duration)
+ return False
+ self.mano['details']['nsd_id'] = nsd.get('id')
+ self.logger.info("Onboarded NSD: " + nsd.get("name"))
+
+ nsr_agent = main_agent.get_agent(
+ "nsr", project_id=self.mano['details']['project_id'])
+
+ self.mano['details']['nsr'] = nsr_agent.create(
+ self.mano['details']['nsd_id'])
+ except NfvoException as exc:
+ self.logger.error(exc.message)
+ duration = time.time() - start_time
+ self.details["vnf"].update(status='FAIL', duration=duration)
+ return False
+
+ if self.mano['details']['nsr'].get('code') is not None:
+ self.logger.error(
+ "%s cannot be deployed: %s -> %s",
+ self.vnf['name'],
+ self.mano['details']['nsr'].get('code'),
+ self.mano['details']['nsr'].get('message'))
+ self.logger.error("%s cannot be deployed", self.vnf['name'])
+ duration = time.time() - start_time
+ self.details["vnf"].update(status='FAIL', duration=duration)
+ return False
+
+ timeout = 0
+ self.logger.info("Waiting for NSR to go to ACTIVE...")
+ while self.mano['details']['nsr'].get("status") != 'ACTIVE' \
+ and self.mano['details']['nsr'].get("status") != 'ERROR':
+ timeout += 1
+ self.logger.info("NSR is not yet ACTIVE... (%ss)", 5 * timeout)
+ if timeout == 300:
+ self.logger.error("INACTIVE NSR after %s sec..", 5 * timeout)
+ duration = time.time() - start_time
+ self.details["vnf"].update(status='FAIL', duration=duration)
+ return False
+ time.sleep(5)
+ self.mano['details']['nsr'] = json.loads(
+ nsr_agent.find(self.mano['details']['nsr'].get('id')))
+
+ duration = time.time() - start_time
+ if self.mano['details']['nsr'].get("status") == 'ACTIVE':
+ self.details["vnf"].update(status='PASS', duration=duration)
+ self.logger.info("Sleep for 60s to ensure that all "
+ "services are up and running...")
+ time.sleep(60)
+ result = True
+ else:
+ self.details["vnf"].update(status='FAIL', duration=duration)
+ self.logger.error("NSR: %s", self.mano['details'].get('nsr'))
+ result = False
+ return result
+
+ def test_vnf(self):
+ self.logger.info(
+ "Testing VNF Clearwater IMS is not yet implemented...")
+ start_time = time.time()
+
+ duration = time.time() - start_time
+ self.details["test_vnf"].update(status='PASS', duration=duration)
+ self.logger.info("Test VNF: OK")
+ return True
+
+ def clean(self):
+ self.logger.info("Cleaning %s...", self.case_name)
+ try:
+ main_agent = MainAgent(
+ nfvo_ip=self.mano['details']['fip'].ip,
+ nfvo_port=8080,
+ https=False,
+ version=1,
+ username=self.mano['credentials']['username'],
+ password=self.mano['credentials']['password'])
+ self.logger.info("Terminating %s...", self.vnf['name'])
+ if (self.mano['details'].get('nsr')):
+ main_agent.get_agent(
+ "nsr",
+ project_id=self.mano['details']['project_id']).delete(
+ self.mano['details']['nsr'].get('id'))
+ self.logger.info("Sleeping 60 seconds...")
+ time.sleep(60)
+ else:
+ self.logger.info("No need to terminate the VNF...")
+ # os_utils.delete_instance(nova_client=os_utils.get_nova_client(),
+ # instance_id=self.mano_instance_id)
+ except (NfvoException, KeyError) as exc:
+ self.logger.error('Unexpected error cleaning - %s', exc)
+
+ try:
+ neutron_client = os_utils.get_neutron_client(self.creds)
+ self.logger.info("Deleting Open Baton Port...")
+ port = snaps_utils.neutron_utils.get_port_by_name(
+ neutron_client, '%s_port' % self.case_name)
+ snaps_utils.neutron_utils.delete_port(neutron_client, port)
+ time.sleep(10)
+ except Exception as exc:
+ self.logger.error('Unexpected error cleaning - %s', exc)
+ try:
+ self.logger.info("Deleting Open Baton Floating IP...")
+ snaps_utils.neutron_utils.delete_floating_ip(
+ neutron_client, self.mano['details']['fip'])
+ except Exception as exc:
+ self.logger.error('Unexpected error cleaning - %s', exc)
+
+ for resource in reversed(self.created_resources):
+ try:
+ self.logger.info("Cleaning %s", str(resource))
+ resource.clean()
+ except Exception as exc:
+ self.logger.error('Unexpected error cleaning - %s', exc)
+ super(ClearwaterImsVnf, self).clean()
diff --git a/functest/opnfv_tests/vnf/ims/orchestra_ims.yaml b/functest/opnfv_tests/vnf/ims/orchestra_ims.yaml
deleted file mode 100644
index 9deb11c7..00000000
--- a/functest/opnfv_tests/vnf/ims/orchestra_ims.yaml
+++ /dev/null
@@ -1,45 +0,0 @@
-tenant_images:
- ubuntu_14.04: http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
- openims: http://marketplace.openbaton.org:8082/api/v1/images/52e2ccc0-1dce-4663-894d-28aab49323aa/img
-orchestrator:
- name: openbaton
- version: '3.2.0'
- requirements:
- flavor:
- name: orchestra
- ram_min: 4096
- disk: 5
- vcpus: 2
- os_image: 'ubuntu_14.04'
- bootstrap:
- url: http://get.openbaton.org/bootstraps/bootstrap_3.2.0_opnfv/bootstrap
- config:
- url: http://get.openbaton.org/bootstraps/bootstrap_3.2.0_opnfv/bootstrap-config-file
- gvnfm:
- userdata:
- url: https://raw.githubusercontent.com/openbaton/generic-vnfm/3.2.0/src/main/resources/user-data.sh
- credentials:
- username: admin
- password: openbaton
-vnf:
- name: openims
- descriptor:
- url: http://marketplace.openbaton.org:8082/api/v1/nsds/fokus/OpenImsCore/3.2.0/json
- requirements:
- flavor:
- name: m1.small
- ram_min: 2048
- disk: 5
- vcpus: 2
-
-vIMS:
- scscf:
- ports: [3870, 6060]
- pcscf:
- ports: [4060]
- icscf:
- ports: [3869, 5060]
- fhoss:
- ports: [3868]
- bind9:
- ports: [] \ No newline at end of file
diff --git a/functest/opnfv_tests/vnf/ims/orchestra_ims.py b/functest/opnfv_tests/vnf/ims/orchestra_openims.py
index 0a0a766a..f9a81f22 100644
--- a/functest/opnfv_tests/vnf/ims/orchestra_ims.py
+++ b/functest/opnfv_tests/vnf/ims/orchestra_openims.py
@@ -139,16 +139,16 @@ def get_userdata(orchestrator=dict):
return userdata
-class ImsVnf(vnf.VnfOnBoarding):
+class OpenImsVnf(vnf.VnfOnBoarding):
"""OpenIMS VNF deployed with openBaton orchestrator"""
- # logger = logging.getLogger(__name__)
+ logger = logging.getLogger(__name__)
def __init__(self, **kwargs):
if "case_name" not in kwargs:
- kwargs["case_name"] = "orchestra_ims"
- super(ImsVnf, self).__init__(**kwargs)
- self.logger = logging.getLogger("functest.ci.run_tests.orchestra")
+ kwargs["case_name"] = "orchestra_openims"
+ super(OpenImsVnf, self).__init__(**kwargs)
+ # self.logger = logging.getLogger("functest.ci.run_tests.orchestra")
self.logger.info("kwargs %s", (kwargs))
self.case_dir = pkg_resources.resource_filename(
@@ -156,7 +156,7 @@ class ImsVnf(vnf.VnfOnBoarding):
self.data_dir = CONST.__getattribute__('dir_ims_data')
self.test_dir = CONST.__getattribute__('dir_repo_vims_test')
self.created_resources = []
- self.logger.info("Orchestra IMS VNF onboarding test starting")
+ self.logger.info("%s VNF onboarding test starting", self.case_name)
try:
self.config = CONST.__getattribute__(
@@ -165,48 +165,45 @@ class ImsVnf(vnf.VnfOnBoarding):
raise Exception("Orchestra VNF config file not found")
config_file = self.case_dir + self.config
- self.baton = dict(
- requirements=get_config("orchestrator.requirements", config_file),
- credentials=get_config("orchestrator.credentials", config_file),
- bootstrap=get_config("orchestrator.bootstrap", config_file),
- gvnfm=get_config("orchestrator.gvnfm", config_file),
+ self.mano = dict(
+ get_config("mano", config_file),
+ details={}
)
- self.logger.debug("Orchestrator configuration %s", self.baton)
+ self.logger.debug("Orchestrator configuration %s", self.mano)
self.details['orchestrator'] = dict(
- name=get_config("orchestrator.name", config_file),
- version=get_config("orchestrator.version", config_file),
+ name=self.mano['name'],
+ version=self.mano['version'],
status='ERROR',
result=''
)
- self.baton['details'] = {}
- self.baton['details']['image'] = self.baton['requirements']['os_image']
- self.baton['details']['name'] = self.details['orchestrator']['name']
self.vnf = dict(
- descriptor=get_config("vnf.descriptor", config_file),
- requirements=get_config("vnf.requirements", config_file)
+ get_config(self.case_name, config_file),
)
+ self.logger.debug("VNF configuration: %s", self.vnf)
+
self.details['vnf'] = dict(
- name=get_config("vnf.name", config_file),
+ name=self.vnf['name'],
)
- self.logger.debug("VNF configuration: %s", self.vnf)
self.details['test_vnf'] = dict(
- name="openims-test",
+ name=self.case_name,
)
- # vIMS Data directory creation
+ # Orchestra base Data directory creation
if not os.path.exists(self.data_dir):
os.makedirs(self.data_dir)
- self.images = get_config("tenant_images", config_file)
- self.ims_conf = get_config("vIMS", config_file)
+ self.images = get_config("tenant_images.%s" %
+ self.case_name, config_file)
+ self.images.update(get_config("tenant_images.%s" %
+ self.case_name, config_file))
self.snaps_creds = None
def prepare(self):
"""Prepare testscase (Additional pre-configuration steps)."""
- super(ImsVnf, self).prepare()
+ super(OpenImsVnf, self).prepare()
self.logger.info("Additional pre-configuration steps")
self.logger.info("creds %s", (self.creds))
@@ -272,6 +269,16 @@ class ImsVnf(vnf.VnfOnBoarding):
protocol=Protocol.udp,
port_range_min=1,
port_range_max=65535))
+ sg_rules.append(
+ SecurityGroupRuleSettings(
+ sec_grp_name="orchestra-sec-group-allowall",
+ direction=Direction.ingress,
+ protocol=Protocol.icmp))
+ sg_rules.append(
+ SecurityGroupRuleSettings(
+ sec_grp_name="orchestra-sec-group-allowall",
+ direction=Direction.egress,
+ protocol=Protocol.icmp))
# sg_rules.append(
# SecurityGroupRuleSettings(
# sec_grp_name="orchestra-sec-group-allowall",
@@ -295,7 +302,7 @@ class ImsVnf(vnf.VnfOnBoarding):
security_group_info = security_group.create()
self.created_resources.append(security_group)
- self.baton['details']['sec_group'] = security_group_info.name
+ self.mano['details']['sec_group'] = security_group_info.name
self.logger.info(
"Security group orchestra-sec-group-allowall prepared")
@@ -305,16 +312,16 @@ class ImsVnf(vnf.VnfOnBoarding):
"Create Flavor for Open Baton NFVO if not yet existing")
flavor_settings = FlavorSettings(
- name=self.baton['requirements']['flavor']['name'],
- ram=self.baton['requirements']['flavor']['ram_min'],
- disk=self.baton['requirements']['flavor']['disk'],
- vcpus=self.baton['requirements']['flavor']['vcpus'])
+ name=self.mano['requirements']['flavor']['name'],
+ ram=self.mano['requirements']['flavor']['ram_min'],
+ disk=self.mano['requirements']['flavor']['disk'],
+ vcpus=self.mano['requirements']['flavor']['vcpus'])
flavor = OpenStackFlavor(self.snaps_creds, flavor_settings)
flavor_info = flavor.create()
self.created_resources.append(flavor)
- self.baton['details']['flavor'] = {}
- self.baton['details']['flavor']['name'] = flavor_settings.name
- self.baton['details']['flavor']['id'] = flavor_info.id
+ self.mano['details']['flavor'] = {}
+ self.mano['details']['flavor']['name'] = flavor_settings.name
+ self.mano['details']['flavor']['id'] = flavor_info.id
def prepare_network(self):
"""Create network/subnet/router if they doen't exist yet"""
@@ -322,27 +329,27 @@ class ImsVnf(vnf.VnfOnBoarding):
"Creating network/subnet/router if they doen't exist yet...")
subnet_settings = SubnetSettings(
name='%s_subnet' %
- self.baton['details']['name'],
+ self.case_name,
cidr="192.168.100.0/24")
network_settings = NetworkSettings(
name='%s_net' %
- self.baton['details']['name'],
+ self.case_name,
subnet_settings=[subnet_settings])
orchestra_network = OpenStackNetwork(
self.snaps_creds, network_settings)
orchestra_network_info = orchestra_network.create()
- self.baton['details']['network'] = {}
- self.baton['details']['network']['id'] = orchestra_network_info.id
- self.baton['details']['network']['name'] = orchestra_network_info.name
- self.baton['details']['external_net_name'] = \
+ self.mano['details']['network'] = {}
+ self.mano['details']['network']['id'] = orchestra_network_info.id
+ self.mano['details']['network']['name'] = orchestra_network_info.name
+ self.mano['details']['external_net_name'] = \
snaps_utils.get_ext_net_name(self.snaps_creds)
self.created_resources.append(orchestra_network)
orchestra_router = OpenStackRouter(
self.snaps_creds,
RouterSettings(
name='%s_router' %
- self.baton['details']['name'],
- external_gateway=self.baton['details']['external_net_name'],
+ self.case_name,
+ external_gateway=self.mano['details']['external_net_name'],
internal_subnets=[
subnet_settings.name]))
orchestra_router.create()
@@ -374,21 +381,21 @@ class ImsVnf(vnf.VnfOnBoarding):
for my_floating_ip in my_floating_ips:
for snaps_floating_ip in snaps_floating_ips:
if snaps_floating_ip.ip == my_floating_ip:
- self.baton['details']['fip'] = snaps_floating_ip
+ self.mano['details']['fip'] = snaps_floating_ip
self.logger.info(
"Selected floating IP for Open Baton NFVO %s",
- (self.baton['details']['fip'].ip))
+ (self.mano['details']['fip'].ip))
break
- if self.baton['details']['fip'] is not None:
+ if self.mano['details']['fip'] is not None:
break
else:
self.logger.info("Creating floating IP for Open Baton NFVO")
- self.baton['details']['fip'] = \
- snaps_utils.neutron_utils.create_floating_ip(
- neutron_client, self.baton['details']['external_net_name'])
+ self.mano['details']['fip'] = (
+ snaps_utils.neutron_utils. create_floating_ip(
+ neutron_client, self.mano['details']['external_net_name']))
self.logger.info(
"Created floating IP for Open Baton NFVO %s",
- (self.baton['details']['fip'].ip))
+ (self.mano['details']['fip'].ip))
def get_vim_descriptor(self):
""""Create VIM descriptor to be used for onboarding"""
@@ -415,7 +422,7 @@ class ImsVnf(vnf.VnfOnBoarding):
"username": self.creds.get("username"),
"password": self.creds.get("password"),
"securityGroups": [
- self.baton['details']['sec_group']
+ self.mano['details']['sec_group']
],
"type": "openstack",
"location": {
@@ -428,34 +435,34 @@ class ImsVnf(vnf.VnfOnBoarding):
return vim_json
def deploy_orchestrator(self):
- self.logger.info("Deploying orchestrator Open Baton ...")
- self.logger.info("Details: %s", self.baton['details'])
+ self.logger.info("Deploying Open Baton...")
+ self.logger.info("Details: %s", self.mano['details'])
start_time = time.time()
self.logger.info("Creating orchestra instance...")
- userdata = get_userdata(self.baton)
+ userdata = get_userdata(self.mano)
self.logger.info("flavor: %s\n"
"image: %s\n"
"network_id: %s\n",
- self.baton['details']['flavor']['name'],
- self.baton['details']['image'],
- self.baton['details']['network']['id'])
+ self.mano['details']['flavor']['name'],
+ self.mano['requirements']['image'],
+ self.mano['details']['network']['id'])
self.logger.debug("userdata: %s\n", userdata)
# setting up image
image_settings = ImageSettings(
- name=self.baton['details']['image'],
+ name=self.mano['requirements']['image'],
image_user='ubuntu',
exists=True)
# setting up port
port_settings = PortSettings(
- name='%s_port' % self.baton['details']['name'],
- network_name=self.baton['details']['network']['name'])
+ name='%s_port' % self.case_name,
+ network_name=self.mano['details']['network']['name'])
# build configuration of vm
orchestra_settings = VmInstanceSettings(
- name=self.baton['details']['name'],
- flavor=self.baton['details']['flavor']['name'],
+ name=self.case_name,
+ flavor=self.mano['details']['flavor']['name'],
port_settings=[port_settings],
- security_group_names=[self.baton['details']['sec_group']],
+ security_group_names=[self.mano['details']['sec_group']],
userdata=userdata)
orchestra_vm = OpenStackVmInstance(self.snaps_creds,
orchestra_settings,
@@ -463,19 +470,19 @@ class ImsVnf(vnf.VnfOnBoarding):
orchestra_vm.create()
self.created_resources.append(orchestra_vm)
- self.baton['details']['id'] = orchestra_vm.get_vm_info()['id']
+ self.mano['details']['id'] = orchestra_vm.get_vm_info()['id']
self.logger.info(
"Created orchestra instance: %s",
- self.baton['details']['id'])
+ self.mano['details']['id'])
self.logger.info("Associating floating ip: '%s' to VM '%s' ",
- self.baton['details']['fip'].ip,
- self.baton['details']['name'])
+ self.mano['details']['fip'].ip,
+ self.case_name)
nova_client = os_utils.get_nova_client()
if not os_utils.add_floating_ip(
nova_client,
- self.baton['details']['id'],
- self.baton['details']['fip'].ip):
+ self.mano['details']['id'],
+ self.mano['details']['fip'].ip):
duration = time.time() - start_time
self.details["orchestrator"].update(
status='FAIL', duration=duration)
@@ -486,7 +493,7 @@ class ImsVnf(vnf.VnfOnBoarding):
timeout = 0
while timeout < 200:
if servertest(
- self.baton['details']['fip'].ip,
+ self.mano['details']['fip'].ip,
"8080"):
break
else:
@@ -511,18 +518,18 @@ class ImsVnf(vnf.VnfOnBoarding):
def deploy_vnf(self):
start_time = time.time()
- self.logger.info("Deploying OpenIMS...")
+ self.logger.info("Deploying %s...", self.vnf['name'])
main_agent = MainAgent(
- nfvo_ip=self.baton['details']['fip'].ip,
+ nfvo_ip=self.mano['details']['fip'].ip,
nfvo_port=8080,
https=False,
version=1,
- username=self.baton['credentials']['username'],
- password=self.baton['credentials']['password'])
+ username=self.mano['credentials']['username'],
+ password=self.mano['credentials']['password'])
self.logger.info(
- "Check if openims Flavor is available, if not, create one")
+ "Create %s Flavor if not existing", self.vnf['name'])
flavor_settings = FlavorSettings(
name=self.vnf['requirements']['flavor']['name'],
ram=self.vnf['requirements']['flavor']['ram_min'],
@@ -536,7 +543,7 @@ class ImsVnf(vnf.VnfOnBoarding):
project_agent = main_agent.get_agent("project", "")
for project in json.loads(project_agent.find()):
if project.get("name") == "default":
- self.baton['details']['project_id'] = project.get("id")
+ self.mano['details']['project_id'] = project.get("id")
self.logger.info("Found project 'default': %s", project)
break
@@ -544,11 +551,11 @@ class ImsVnf(vnf.VnfOnBoarding):
self.logger.info("Registering VIM: %s", vim_json)
main_agent.get_agent(
- "vim", project_id=self.baton['details']['project_id']).create(
+ "vim", project_id=self.mano['details']['project_id']).create(
entity=json.dumps(vim_json))
market_agent = main_agent.get_agent(
- "market", project_id=self.baton['details']['project_id'])
+ "market", project_id=self.mano['details']['project_id'])
try:
self.logger.info("sending: %s", self.vnf['descriptor']['url'])
@@ -558,47 +565,48 @@ class ImsVnf(vnf.VnfOnBoarding):
duration = time.time() - start_time
self.details["vnf"].update(status='FAIL', duration=duration)
return False
- self.baton['details']['nsd_id'] = nsd.get('id')
+ self.mano['details']['nsd_id'] = nsd.get('id')
self.logger.info("Onboarded NSD: " + nsd.get("name"))
nsr_agent = main_agent.get_agent(
- "nsr", project_id=self.baton['details']['project_id'])
+ "nsr", project_id=self.mano['details']['project_id'])
- self.baton['details']['nsr'] = nsr_agent.create(
- self.baton['details']['nsd_id'])
+ self.mano['details']['nsr'] = nsr_agent.create(
+ self.mano['details']['nsd_id'])
except NfvoException as exc:
self.logger.error(exc.message)
duration = time.time() - start_time
self.details["vnf"].update(status='FAIL', duration=duration)
return False
- if self.baton['details']['nsr'].get('code') is not None:
+ if self.mano['details']['nsr'].get('code') is not None:
self.logger.error(
- "vIMS cannot be deployed: %s -> %s",
- self.baton['details']['nsr'].get('code'),
- self.baton['details']['nsr'].get('message'))
- self.logger.error("vIMS cannot be deployed")
+ "%s cannot be deployed: %s -> %s",
+ self.vnf['name'],
+ self.mano['details']['nsr'].get('code'),
+ self.mano['details']['nsr'].get('message'))
+ self.logger.error("%s cannot be deployed", self.vnf['name'])
duration = time.time() - start_time
self.details["vnf"].update(status='FAIL', duration=duration)
return False
timeout = 0
self.logger.info("Waiting for NSR to go to ACTIVE...")
- while self.baton['details']['nsr'].get("status") != 'ACTIVE' \
- and self.baton['details']['nsr'].get("status") != 'ERROR':
+ while self.mano['details']['nsr'].get("status") != 'ACTIVE' \
+ and self.mano['details']['nsr'].get("status") != 'ERROR':
timeout += 1
self.logger.info("NSR is not yet ACTIVE... (%ss)", 5 * timeout)
- if timeout == 150:
+ if timeout == 300:
self.logger.error("INACTIVE NSR after %s sec..", 5 * timeout)
duration = time.time() - start_time
self.details["vnf"].update(status='FAIL', duration=duration)
return False
time.sleep(5)
- self.baton['details']['nsr'] = json.loads(
- nsr_agent.find(self.baton['details']['nsr'].get('id')))
+ self.mano['details']['nsr'] = json.loads(
+ nsr_agent.find(self.mano['details']['nsr'].get('id')))
duration = time.time() - start_time
- if self.baton['details']['nsr'].get("status") == 'ACTIVE':
+ if self.mano['details']['nsr'].get("status") == 'ACTIVE':
self.details["vnf"].update(status='PASS', duration=duration)
self.logger.info("Sleep for 60s to ensure that all "
"services are up and running...")
@@ -606,7 +614,7 @@ class ImsVnf(vnf.VnfOnBoarding):
result = True
else:
self.details["vnf"].update(status='FAIL', duration=duration)
- self.logger.error("NSR: %s", self.baton['details'].get('nsr'))
+ self.logger.error("NSR: %s", self.mano['details'].get('nsr'))
result = False
return result
@@ -615,11 +623,11 @@ class ImsVnf(vnf.VnfOnBoarding):
start_time = time.time()
self.logger.info(
"Testing if %s works properly...",
- self.baton['details']['nsr'].get('name'))
- for vnfr in self.baton['details']['nsr'].get('vnfr'):
+ self.mano['details']['nsr'].get('name'))
+ for vnfr in self.mano['details']['nsr'].get('vnfr'):
self.logger.info(
"Checking ports %s of VNF %s",
- self.ims_conf.get(vnfr.get('name')).get('ports'),
+ self.vnf['test'][vnfr.get('name')]['ports'],
vnfr.get('name'))
for vdu in vnfr.get('vdu'):
for vnfci in vdu.get('vnfc_instance'):
@@ -631,8 +639,8 @@ class ImsVnf(vnf.VnfOnBoarding):
"Testing %s:%s",
vnfci.get('hostname'),
floating_ip.get('ip'))
- for port in self.ims_conf.get(
- vnfr.get('name')).get('ports'):
+ for port in self.vnf['test'][vnfr.get(
+ 'name')]['ports']:
if servertest(floating_ip.get('ip'), port):
self.logger.info(
"VNFC instance %s is reachable at %s:%s",
@@ -662,32 +670,43 @@ class ImsVnf(vnf.VnfOnBoarding):
return True
def clean(self):
- self.logger.info("Cleaning...")
+ self.logger.info("Cleaning %s...", self.case_name)
try:
main_agent = MainAgent(
- nfvo_ip=self.baton['details']['fip'].ip,
+ nfvo_ip=self.mano['details']['fip'].ip,
nfvo_port=8080,
https=False,
version=1,
- username=self.baton['credentials']['username'],
- password=self.baton['credentials']['password'])
- self.logger.info("Terminating OpenIMS VNF...")
- if (self.baton['details'].get('nsr')):
+ username=self.mano['credentials']['username'],
+ password=self.mano['credentials']['password'])
+ self.logger.info("Terminating %s...", self.vnf['name'])
+ if (self.mano['details'].get('nsr')):
main_agent.get_agent(
"nsr",
- project_id=self.baton['details']['project_id'])\
- .delete(self.baton['details']['nsr'].get('id'))
- self.logger.info("Waiting 60sec for terminating OpenIMS VNF..")
+ project_id=self.mano['details']['project_id']).\
+ delete(self.mano['details']['nsr'].get('id'))
+ self.logger.info("Sleeping 60 seconds...")
time.sleep(60)
+ else:
+ self.logger.info("No need to terminate the VNF...")
# os_utils.delete_instance(nova_client=os_utils.get_nova_client(),
- # instance_id=self.baton_instance_id)
+ # instance_id=self.mano_instance_id)
except (NfvoException, KeyError) as exc:
self.logger.error('Unexpected error cleaning - %s', exc)
try:
neutron_client = os_utils.get_neutron_client(self.creds)
+ self.logger.info("Deleting Open Baton Port...")
+ port = snaps_utils.neutron_utils.get_port_by_name(
+ neutron_client, '%s_port' % self.case_name)
+ snaps_utils.neutron_utils.delete_port(neutron_client, port)
+ time.sleep(10)
+ except Exception as exc:
+ self.logger.error('Unexpected error cleaning - %s', exc)
+ try:
+ self.logger.info("Deleting Open Baton Floating IP...")
snaps_utils.neutron_utils.delete_floating_ip(
- neutron_client, self.baton['details']['fip'])
+ neutron_client, self.mano['details']['fip'])
except Exception as exc:
self.logger.error('Unexpected error cleaning - %s', exc)
@@ -697,4 +716,4 @@ class ImsVnf(vnf.VnfOnBoarding):
resource.clean()
except Exception as exc:
self.logger.error('Unexpected error cleaning - %s', exc)
- super(ImsVnf, self).clean()
+ super(OpenImsVnf, self).clean()
diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py
index fb8cb391..7495c40e 100644
--- a/functest/tests/unit/ci/test_run_tests.py
+++ b/functest/tests/unit/ci/test_run_tests.py
@@ -54,11 +54,6 @@ class RunTestsTesting(unittest.TestCase):
self.run_tests_parser = run_tests.RunTestsParser()
- @mock.patch('functest.ci.run_tests.logger.info')
- def test_print_separator(self, mock_logger_info):
- self.runner.print_separator(self.sep)
- mock_logger_info.assert_called_once_with(self.sep * 44)
-
@mock.patch('functest.ci.run_tests.logger.error')
def test_source_rc_file_missing_file(self, mock_logger_error):
with mock.patch('functest.ci.run_tests.os.path.isfile',
@@ -120,8 +115,7 @@ class RunTestsTesting(unittest.TestCase):
args = {'get_name.return_value': 'test_name',
'needs_clean.return_value': False}
mock_test.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.Runner.print_separator'),\
- mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
+ with mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
mock.patch('functest.ci.run_tests.Runner.get_run_dict',
return_value=None), \
self.assertRaises(Exception) as context:
@@ -129,7 +123,6 @@ class RunTestsTesting(unittest.TestCase):
msg = "Cannot import the class for the test case."
self.assertTrue(msg in context)
- @mock.patch('functest.ci.run_tests.Runner.print_separator')
@mock.patch('functest.ci.run_tests.Runner.source_rc_file')
@mock.patch('importlib.import_module', name="module",
return_value=mock.Mock(test_class=mock.Mock(
@@ -145,123 +138,107 @@ class RunTestsTesting(unittest.TestCase):
with mock.patch('functest.ci.run_tests.Runner.get_run_dict',
return_value=test_run_dict):
self.runner.clean_flag = True
- self.runner.run_test(mock_test, 'tier_name')
+ self.runner.run_test(mock_test)
self.assertEqual(self.runner.overall_result,
run_tests.Result.EX_OK)
- @mock.patch('functest.ci.run_tests.logger.info')
- def test_run_tier_default(self, mock_logger_info):
- with mock.patch('functest.ci.run_tests.Runner.print_separator'), \
- mock.patch(
- 'functest.ci.run_tests.Runner.run_test',
- return_value=TestCase.EX_OK) as mock_method:
- self.runner.run_tier(self.tier)
- mock_method.assert_any_call(mock.ANY, 'test_tier')
- self.assertTrue(mock_logger_info.called)
+ @mock.patch('functest.ci.run_tests.Runner.run_test',
+ return_value=TestCase.EX_OK)
+ def test_run_tier_default(self, *mock_methods):
+ self.assertEqual(self.runner.run_tier(self.tier),
+ run_tests.Result.EX_OK)
+ mock_methods[0].assert_called_with(mock.ANY)
@mock.patch('functest.ci.run_tests.logger.info')
def test_run_tier_missing_test(self, mock_logger_info):
- with mock.patch('functest.ci.run_tests.Runner.print_separator'):
- self.tier.get_tests.return_value = None
- self.assertEqual(self.runner.run_tier(self.tier), 0)
- self.assertTrue(mock_logger_info.called)
+ self.tier.get_tests.return_value = None
+ self.assertEqual(self.runner.run_tier(self.tier),
+ run_tests.Result.EX_ERROR)
+ self.assertTrue(mock_logger_info.called)
@mock.patch('functest.ci.run_tests.logger.info')
- def test_run_all_default(self, mock_logger_info):
- with mock.patch(
- 'functest.ci.run_tests.Runner.run_tier') as mock_method:
- CONST.__setattr__('CI_LOOP', 'test_ci_loop')
- self.runner.run_all(self.tiers)
- mock_method.assert_any_call(self.tier)
- self.assertTrue(mock_logger_info.called)
+ @mock.patch('functest.ci.run_tests.Runner.run_tier')
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_run_all_default(self, *mock_methods):
+ CONST.__setattr__('CI_LOOP', 'test_ci_loop')
+ self.runner.run_all()
+ mock_methods[1].assert_not_called()
+ self.assertTrue(mock_methods[2].called)
@mock.patch('functest.ci.run_tests.logger.info')
- def test_run_all_missing_tier(self, mock_logger_info):
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_run_all_missing_tier(self, *mock_methods):
CONST.__setattr__('CI_LOOP', 'loop_re_not_available')
- self.runner.run_all(self.tiers)
- self.assertTrue(mock_logger_info.called)
+ self.runner.run_all()
+ self.assertTrue(mock_methods[1].called)
- def test_main_failed(self):
+ @mock.patch('functest.ci.run_tests.Runner.source_rc_file',
+ side_effect=Exception)
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_main_failed(self, *mock_methods):
kwargs = {'test': 'test_name', 'noclean': True, 'report': True}
- mock_obj = mock.Mock()
args = {'get_tier.return_value': False,
'get_test.return_value': False}
- mock_obj.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder'), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file',
- side_effect=Exception):
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_ERROR)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder',
- return_value=mock_obj), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file',
- side_effect=Exception):
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_ERROR)
-
- def test_main_tier(self, *args):
+ self.runner._tiers = mock.Mock()
+ self.runner._tiers.configure_mock(**args)
+ self.assertEqual(self.runner.main(**kwargs),
+ run_tests.Result.EX_ERROR)
+ mock_methods[1].assert_called_once_with()
+
+ @mock.patch('functest.ci.run_tests.Runner.source_rc_file')
+ @mock.patch('functest.ci.run_tests.Runner.run_test',
+ return_value=TestCase.EX_OK)
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_main_tier(self, *mock_methods):
mock_tier = mock.Mock()
- args = {'get_name.return_value': 'tier_name'}
+ args = {'get_name.return_value': 'tier_name',
+ 'get_tests.return_value': ['test_name']}
mock_tier.configure_mock(**args)
kwargs = {'test': 'tier_name', 'noclean': True, 'report': True}
- mock_obj = mock.Mock()
args = {'get_tier.return_value': mock_tier,
'get_test.return_value': None}
- mock_obj.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder',
- return_value=mock_obj), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
- mock.patch('functest.ci.run_tests.Runner.run_tier') as m:
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_OK)
- self.assertTrue(m.called)
-
- def test_main_test(self, *args):
+ self.runner._tiers = mock.Mock()
+ self.runner._tiers.configure_mock(**args)
+ self.assertEqual(self.runner.main(**kwargs),
+ run_tests.Result.EX_OK)
+ mock_methods[1].assert_called_once_with('test_name')
+
+ @mock.patch('functest.ci.run_tests.Runner.source_rc_file')
+ @mock.patch('functest.ci.run_tests.Runner.run_test',
+ return_value=TestCase.EX_OK)
+ def test_main_test(self, *mock_methods):
kwargs = {'test': 'test_name', 'noclean': True, 'report': True}
- mock_test = mock.Mock()
- args = {'get_name.return_value': 'test_name',
- 'needs_clean.return_value': True}
- mock_test.configure_mock(**args)
- mock_obj = mock.Mock()
args = {'get_tier.return_value': None,
- 'get_test.return_value': mock_test}
- mock_obj.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder',
- return_value=mock_obj), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
- mock.patch('functest.ci.run_tests.Runner.run_test',
- return_value=TestCase.EX_OK) as m:
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_OK)
- self.assertTrue(m.called)
-
- def test_main_all_tier(self, *args):
+ 'get_test.return_value': 'test_name'}
+ self.runner._tiers = mock.Mock()
+ self.runner._tiers.configure_mock(**args)
+ self.assertEqual(self.runner.main(**kwargs),
+ run_tests.Result.EX_OK)
+ mock_methods[0].assert_called_once_with('test_name')
+
+ @mock.patch('functest.ci.run_tests.Runner.source_rc_file')
+ @mock.patch('functest.ci.run_tests.Runner.run_all')
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_main_all_tier(self, *mock_methods):
kwargs = {'test': 'all', 'noclean': True, 'report': True}
- mock_obj = mock.Mock()
args = {'get_tier.return_value': None,
'get_test.return_value': None}
- mock_obj.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder',
- return_value=mock_obj), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
- mock.patch('functest.ci.run_tests.Runner.run_all') as m:
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_OK)
- self.assertTrue(m.called)
-
- def test_main_any_tier_test_ko(self, *args):
+ self.runner._tiers = mock.Mock()
+ self.runner._tiers.configure_mock(**args)
+ self.assertEqual(self.runner.main(**kwargs),
+ run_tests.Result.EX_OK)
+ mock_methods[1].assert_called_once_with()
+
+ @mock.patch('functest.ci.run_tests.Runner.source_rc_file')
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_main_any_tier_test_ko(self, *mock_methods):
kwargs = {'test': 'any', 'noclean': True, 'report': True}
- mock_obj = mock.Mock()
args = {'get_tier.return_value': None,
'get_test.return_value': None}
- mock_obj.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder',
- return_value=mock_obj), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
- mock.patch('functest.ci.run_tests.logger.debug') as m:
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_ERROR)
- self.assertTrue(m.called)
+ self.runner._tiers = mock.Mock()
+ self.runner._tiers.configure_mock(**args)
+ self.assertEqual(self.runner.main(**kwargs),
+ run_tests.Result.EX_ERROR)
if __name__ == "__main__":
diff --git a/functest/tests/unit/ci/test_tier_builder.py b/functest/tests/unit/ci/test_tier_builder.py
index ab75e15b..700c6e91 100644
--- a/functest/tests/unit/ci/test_tier_builder.py
+++ b/functest/tests/unit/ci/test_tier_builder.py
@@ -24,7 +24,8 @@ class TierBuilderTesting(unittest.TestCase):
'case_name': 'test_name',
'criteria': 'test_criteria',
'blocking': 'test_blocking',
- 'description': 'test_desc'}
+ 'description': 'test_desc',
+ 'project_name': 'project_name'}
self.dic_tier = {'name': 'test_tier',
'order': 'test_order',
diff --git a/functest/tests/unit/vnf/ims/test_orchestra_clearwaterims.py b/functest/tests/unit/vnf/ims/test_orchestra_clearwaterims.py
new file mode 100644
index 00000000..ef227ca4
--- /dev/null
+++ b/functest/tests/unit/vnf/ims/test_orchestra_clearwaterims.py
@@ -0,0 +1,227 @@
+#!/usr/bin/env python
+
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+"""Test module for orchestra_clearwaterims"""
+
+import logging
+import unittest
+
+import mock
+from snaps.openstack.os_credentials import OSCreds
+
+from functest.core import vnf
+from functest.opnfv_tests.vnf.ims import orchestra_clearwaterims
+
+
+class OrchestraClearwaterImsTesting(unittest.TestCase):
+ """Test class for orchestra_clearwaterims"""
+ def setUp(self):
+
+ self.tenant = 'orchestra_clearwaterims'
+ self.creds = {'username': 'mocked_username',
+ 'password': 'mocked_password'}
+ self.tenant_images = {
+ 'image1': 'mocked_image_url_1',
+ 'image2': 'mocked_image_url_2'
+ }
+ self.mano = {
+ 'name': 'openbaton',
+ 'version': '3.2.0',
+ 'object': 'foo',
+ 'requirements': {
+ 'flavor': {
+ 'name': 'mocked_flavor',
+ 'ram_min': 4096,
+ 'disk': 5,
+ 'vcpus': 2
+ },
+ 'os_image': 'mocked_image'
+ },
+ 'bootstrap': {
+ 'url': 'mocked_bootstrap_url',
+ 'config': {
+ 'url': 'mocked_config_url'}
+ },
+ 'gvnfm': {
+ 'userdata': {
+ 'url': 'mocked_userdata_url'
+ }
+ },
+ 'credentials': {
+ 'username': 'mocked_username',
+ 'password': 'mocked_password'
+ }
+ }
+ self.vnf = {
+ 'name': 'openims',
+ 'descriptor': {
+ 'url': 'mocked_descriptor_url'
+ },
+ 'requirements': {
+ 'flavor': {
+ 'name': 'mocked_flavor',
+ 'ram_min': 2048,
+ 'disk': 5,
+ 'vcpus': 2}
+ }
+ }
+ self.clearwaterims = {
+ 'scscf': {
+ 'ports': [3870, 6060]
+ },
+ 'pcscf': {
+ 'ports': [4060]
+ },
+ 'icscf': {
+ 'ports': [3869, 5060]
+ },
+ 'fhoss': {
+ 'ports': [3868]
+ },
+ 'bind9': {
+ 'ports': []
+ }
+ }
+ with mock.patch('functest.opnfv_tests.vnf.ims.orchestra_clearwaterims.'
+ 'os.makedirs'),\
+ mock.patch('functest.opnfv_tests.vnf.ims.orchestra_clearwaterims.'
+ 'get_config', return_value={
+ 'orchestrator': self.mano,
+ 'name': self.mano['name'],
+ 'version': self.mano['version'],
+ 'requirements': self.mano['requirements'],
+ 'credentials': self.mano['credentials'],
+ 'bootstrap': self.mano['bootstrap'],
+ 'gvnfm': self.mano['gvnfm'],
+ 'os_image': self.mano['requirements']['os_image'],
+ 'flavor': self.mano['requirements']['flavor'],
+ 'url': self.mano['bootstrap']['url'],
+ 'config': self.mano['bootstrap']['config'],
+ 'tenant_images': self.tenant_images,
+ 'vnf': self.vnf,
+ 'orchestra_clearwaterims': self.clearwaterims}):
+ self.ims_vnf = orchestra_clearwaterims.ClearwaterImsVnf()
+
+ self.details = {'orchestrator': {'status': 'PASS', 'duration': 120},
+ 'vnf': {},
+ 'test_vnf': {}}
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ return_value='test')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_credentials',
+ return_value={'auth_url': 'test/v1'})
+ @mock.patch(
+ 'functest.utils.openstack_utils.get_tenant_id',
+ return_value={'mocked_tenant_id'})
+ @mock.patch(
+ 'functest.utils.openstack_utils.get_floating_ips',
+ return_value=[])
+ @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
+ @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create')
+ @mock.patch(
+ 'snaps.openstack.create_security_group.OpenStackSecurityGroup.create')
+ @mock.patch('snaps.openstack.create_network.OpenStackNetwork.create')
+ @mock.patch('snaps.openstack.create_router.OpenStackRouter.create')
+ @mock.patch(
+ 'functest.opnfv_tests.openstack.snaps.snaps_utils.get_ext_net_name')
+ @mock.patch(
+ 'functest.opnfv_tests.openstack.snaps.'
+ 'snaps_utils.neutron_utils.create_floating_ip')
+ def test_prepare_default(self, *args):
+ """Testing prepare function without any exceptions expected"""
+ self.assertIsNone(self.ims_vnf.prepare())
+ args[4].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ return_value='test')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_credentials',
+ return_value={'auth_url': 'test/no_v'})
+ @mock.patch('snaps.openstack.create_image.OpenStackImage.create')
+ def test_prepare_bad_auth_url(self, *args):
+ """Testing prepare function with bad auth url"""
+ with self.assertRaises(Exception):
+ self.ims_vnf.image_creator(
+ OSCreds(username='user', password='pass', auth_url='url',
+ project_name='project', identity_api_version=3),
+ mock.Mock())
+ args[0].assert_not_called()
+
+ def test_prepare_missing_param(self):
+ """Testing prepare function with missing param"""
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.ims_vnf.prepare()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ side_effect=Exception)
+ def test_prepare_keystone_exception(self, *args):
+ """Testing prepare function with keystone exception"""
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.ims_vnf.prepare()
+ args[0].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ return_value='test')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ side_effect=Exception)
+ def test_prepare_tenant_exception(self, *args):
+ """Testing prepare function with tenant exception"""
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.ims_vnf.prepare()
+ args[1].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ return_value='test')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
+ side_effect=Exception)
+ def test_prepare_user_exception(self, *args):
+ """Testing prepare function with user exception"""
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.ims_vnf.prepare()
+ args[2].assert_called_once_with()
+
+ @mock.patch('functest.core.vnf.os_utils.get_keystone_client',
+ return_value='test')
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_tenant_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_or_create_user_for_vnf',
+ return_value=True)
+ @mock.patch('functest.core.vnf.os_utils.get_credentials',
+ side_effect=Exception)
+ def test_prepare_credentials_exception(self, *args):
+ """Testing prepare function with credentials exception"""
+ with self.assertRaises(vnf.VnfPreparationException):
+ self.ims_vnf.prepare()
+ args[0].assert_called_once_with()
+
+ # # @mock.patch('functest.opnfv_tests.vnf.
+ # ims.orchestra_clearwaterims.get_userdata')
+ # def test_deploy_orchestrator(self, *args):
+ # floating_ip = FloatingIp
+ # floating_ip.ip = 'mocked_ip'
+ # details = {'fip':floating_ip,'flavor':{'name':'mocked_name'}}
+ # self.mano['details'] = details
+ # with mock.patch.dict(self.mano, {'details':
+ # {'fip':floating_ip,'flavor':{'name':'mocked_name'}}}):
+ # # with mock.patch.dict(self.mano, details):
+ # orchestra_clearwaterims.get_userdata(self.mano)
+ # self.assertIsNone(self.ims_vnf.deploy_orchestrator())
+ # args[4].assert_called_once_with()
+
+
+if __name__ == "__main__":
+ logging.disable(logging.CRITICAL)
+ unittest.main(verbosity=2)
diff --git a/functest/tests/unit/vnf/ims/test_orchestra_ims.py b/functest/tests/unit/vnf/ims/test_orchestra_openims.py
index 5a1efc7f..5911cf77 100644
--- a/functest/tests/unit/vnf/ims/test_orchestra_ims.py
+++ b/functest/tests/unit/vnf/ims/test_orchestra_openims.py
@@ -5,29 +5,30 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
-"""Test module for orchestra_ims"""
+"""Test module for orchestra_openims"""
import logging
import unittest
import mock
+from snaps.openstack.os_credentials import OSCreds
from functest.core import vnf
-from functest.opnfv_tests.vnf.ims import orchestra_ims
+from functest.opnfv_tests.vnf.ims import orchestra_openims
-class OrchestraImsTesting(unittest.TestCase):
- """Test class for orchestra_ims"""
+class OrchestraOpenImsTesting(unittest.TestCase):
+ """Test class for orchestra_openims"""
def setUp(self):
- self.tenant = 'orchestra_ims'
+ self.tenant = 'orchestra_openims'
self.creds = {'username': 'mocked_username',
'password': 'mocked_password'}
self.tenant_images = {
'image1': 'mocked_image_url_1',
'image2': 'mocked_image_url_2'
}
- self.orchestrator = {
+ self.mano = {
'name': 'openbaton',
'version': '3.2.0',
'object': 'foo',
@@ -68,7 +69,7 @@ class OrchestraImsTesting(unittest.TestCase):
'vcpus': 2}
}
}
- self.vIMS = {
+ self.openims = {
'scscf': {
'ports': [3870, 6060]
},
@@ -85,27 +86,27 @@ class OrchestraImsTesting(unittest.TestCase):
'ports': []
}
}
- with mock.patch('functest.opnfv_tests.vnf.ims.orchestra_ims.'
+ with mock.patch('functest.opnfv_tests.vnf.ims.orchestra_openims.'
'os.makedirs'),\
- mock.patch('functest.opnfv_tests.vnf.ims.orchestra_ims.'
+ mock.patch('functest.opnfv_tests.vnf.ims.orchestra_openims.'
'get_config', return_value={
- 'orchestrator': self.orchestrator,
- 'name': self.orchestrator['name'],
- 'version': self.orchestrator['version'],
- 'requirements': self.orchestrator['requirements'],
- 'credentials': self.orchestrator['credentials'],
- 'bootstrap': self.orchestrator['bootstrap'],
- 'gvnfm': self.orchestrator['gvnfm'],
+ 'orchestrator': self.mano,
+ 'name': self.mano['name'],
+ 'version': self.mano['version'],
+ 'requirements': self.mano['requirements'],
+ 'credentials': self.mano['credentials'],
+ 'bootstrap': self.mano['bootstrap'],
+ 'gvnfm': self.mano['gvnfm'],
'os_image':
- self.orchestrator['requirements']['os_image'],
+ self.mano['requirements']['os_image'],
'flavor':
- self.orchestrator['requirements']['flavor'],
- 'url': self.orchestrator['bootstrap']['url'],
- 'config': self.orchestrator['bootstrap']['config'],
+ self.mano['requirements']['flavor'],
+ 'url': self.mano['bootstrap']['url'],
+ 'config': self.mano['bootstrap']['config'],
'tenant_images': self.tenant_images,
'vnf': self.vnf,
- 'vIMS': self.vIMS}):
- self.ims_vnf = orchestra_ims.ImsVnf()
+ 'orchestra_openims': self.openims}):
+ self.ims_vnf = orchestra_openims.OpenImsVnf()
self.details = {'orchestrator': {'status': 'PASS', 'duration': 120},
'vnf': {},
@@ -153,7 +154,10 @@ class OrchestraImsTesting(unittest.TestCase):
def test_prepare_bad_auth_url(self, *args):
"""Testing prepare function with bad auth url"""
with self.assertRaises(Exception):
- self.ims_vnf.prepare()
+ self.ims_vnf.image_creator(
+ OSCreds(username='user', password='pass', auth_url='url',
+ project_name='project', identity_api_version=3),
+ mock.Mock())
args[0].assert_not_called()
def test_prepare_missing_param(self):
@@ -205,16 +209,17 @@ class OrchestraImsTesting(unittest.TestCase):
self.ims_vnf.prepare()
args[0].assert_called_once_with()
- # # @mock.patch('functest.opnfv_tests.vnf.ims.orchestra_ims.get_userdata')
+ # # @mock.patch('functest.opnfv_tests.
+ # vnf.ims.orchestra_openims.get_userdata')
# def test_deploy_orchestrator(self, *args):
# floating_ip = FloatingIp
# floating_ip.ip = 'mocked_ip'
# details = {'fip':floating_ip,'flavor':{'name':'mocked_name'}}
- # self.orchestrator['details'] = details
- # with mock.patch.dict(self.orchestrator, {'details':
+ # self.mano['details'] = details
+ # with mock.patch.dict(self.mano, {'details':
# {'fip':floating_ip,'flavor':{'name':'mocked_name'}}}):
- # # with mock.patch.dict(self.orchestrator, details):
- # orchestra_ims.get_userdata(self.orchestrator)
+ # # with mock.patch.dict(self.mano, details):
+ # orchestra_openims.get_userdata(self.mano)
# self.assertIsNone(self.ims_vnf.deploy_orchestrator())
# args[4].assert_called_once_with()
diff --git a/requirements.txt b/requirements.txt
index 4f8d06b4..e1d34a36 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -21,6 +21,8 @@ dnspython3!=1.13.0,!=1.14.0,>=1.12.0;python_version>='3.0' # http://www.dnspytho
click
openbaton-cli
cloudify_rest_client
+Flask!=0.11,<1.0,>=0.10 # BSD
+Flask-RESTful>=0.3.5 # BSD
mock>=2.0 # BSD
iniparse==0.4
PrettyTable<0.8,>=0.7.1 # BSD
diff --git a/setup.cfg b/setup.cfg
index 7630a17f..89aa033e 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -22,3 +22,4 @@ console_scripts =
prepare_env = functest.ci.prepare_env:main
run_tests = functest.ci.run_tests:main
check_deployment = functest.ci.check_deployment:main
+ functest_restapi = functest.api.server:main
diff --git a/tox.ini b/tox.ini
index 208091ac..94063c29 100644
--- a/tox.ini
+++ b/tox.ini
@@ -30,6 +30,7 @@ commands = flake8
basepython = python2.7
whitelist_externals = bash
modules =
+ functest.api
functest.core
functest.opnfv_tests.sdn.odl
functest.tests.unit.core