summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/ci/config_functest.yaml6
-rw-r--r--functest/core/vnf_base.py107
-rw-r--r--functest/utils/decorators.py23
-rw-r--r--functest/utils/functest_utils.py2
-rw-r--r--functest/utils/openstack_utils.py18
5 files changed, 81 insertions, 75 deletions
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml
index 95a4408a1..a9ad15cab 100644
--- a/functest/ci/config_functest.yaml
+++ b/functest/ci/config_functest.yaml
@@ -201,6 +201,6 @@ example:
sg_desc: Example Security group
results:
- # you can also set a dir (e.g. /home/opnfv/db) to dump results
- # test_db_url: file:///home/opnfv/db
- test_db_url: http://testresults.opnfv.org/test/api/v1
+ # you can also set a file (e.g. /home/opnfv/functest/results/dump.txt) to dump results
+ # test_db_url: file:///home/opnfv/functest/results/dump.txt
+ test_db_url: http://testresults.opnfv.org/test/api/v1/results
diff --git a/functest/core/vnf_base.py b/functest/core/vnf_base.py
index 6bd6e4311..2de28c124 100644
--- a/functest/core/vnf_base.py
+++ b/functest/core/vnf_base.py
@@ -27,6 +27,12 @@ class VnfOnBoardingBase(base.TestCase):
self.cmd = kwargs.get('cmd', '')
self.details = {}
self.result_dir = CONST.dir_results
+ self.details_step_mapping = dict(
+ deploy_orchestrator='orchestrator',
+ deploy_vnf='vnf',
+ test_vnf='test_vnf',
+ prepare='prepare_env')
+ self.details['prepare_env'] = {}
self.details['orchestrator'] = {}
self.details['vnf'] = {}
self.details['test_vnf'] = {}
@@ -118,48 +124,45 @@ class VnfOnBoardingBase(base.TestCase):
self.logger.info("Prepare OpenStack plateform(create tenant and user)")
admin_user_id = os_utils.get_user_id(self.keystone_client,
self.creds['username'])
- if admin_user_id == '':
- self.step_failure("Failed to get id of " +
- self.creds['username'])
+ if not admin_user_id:
+ self.step_failure("Failed to get id of {0}".format(
+ self.creds['username']))
- tenant_id = os_utils.create_tenant(
- self.keystone_client, self.tenant_name, self.tenant_description)
+ tenant_id = os_utils.get_tenant_id(self.keystone_client,
+ self.tenant_name)
if not tenant_id:
- self.step_failure("Failed to create " +
- self.tenant_name + " tenant")
-
- roles_name = ["admin", "Admin"]
- role_id = ''
- for role_name in roles_name:
- if role_id == '':
- role_id = os_utils.get_role_id(self.keystone_client, role_name)
-
- if role_id == '':
- self.logger.error("Failed to get id for %s role" % role_name)
- self.step_failure("Failed to get role id of " + role_name)
-
- if not os_utils.add_role_user(self.keystone_client, admin_user_id,
- role_id, tenant_id):
- self.logger.error("Failed to add %s on tenant" %
- self.creds['username'])
- self.step_failure("Failed to add %s on tenant" %
- self.creds['username'])
-
- user_id = os_utils.create_user(self.keystone_client,
- self.tenant_name,
- self.tenant_name,
- None,
- tenant_id)
+ tenant_id = os_utils.create_tenant(self.keystone_client,
+ self.tenant_name,
+ self.tenant_description)
+ if not tenant_id:
+ self.step_failure("Failed to get or create {0} tenant".format(
+ self.tenant_name))
+ roles_name = ["admin", "Admin"]
+ role_id = ''
+ for role_name in roles_name:
+ if not role_id:
+ role_id = os_utils.get_role_id(self.keystone_client,
+ role_name)
+
+ if not role_id:
+ self.step_failure("Failed to get id for {0} role".format(
+ role_name))
+
+ if not os_utils.add_role_user(self.keystone_client, admin_user_id,
+ role_id, tenant_id):
+ self.step_failure("Failed to add {0} on tenant".format(
+ self.creds['username']))
+
+ user_id = os_utils.get_or_create_user(self.keystone_client,
+ self.tenant_name,
+ self.tenant_name,
+ tenant_id)
if not user_id:
- self.logger.error("Failed to create %s user" % self.tenant_name)
- self.step_failure("Failed to create user ")
+ self.step_failure("Failed to get or create {0} user".format(
+ self.tenant_name))
- if not os_utils.add_role_user(self.keystone_client, user_id,
- role_id, tenant_id):
- self.logger.error("Failed to add %s on tenant" %
- self.tenant_name)
- self.step_failure("Failed to add %s on tenant" %
- self.tenant_name)
+ os_utils.add_role_user(self.keystone_client, user_id,
+ role_id, tenant_id)
self.logger.info("Update OpenStack creds informations")
self.admin_creds = self.creds.copy()
@@ -187,31 +190,10 @@ class VnfOnBoardingBase(base.TestCase):
self.logger.error("VNF must be tested")
raise Exception("VNF not tested")
+ # clean before openstack clean run
def clean(self):
self.logger.info("test cleaning")
- self.logger.info("Removing %s tenant .." % self.tenant_name)
- tenant_id = os_utils.get_tenant_id(self.keystone_client,
- self.tenant_name)
- if tenant_id == '':
- self.logger.error("Error : Failed to get id of %s tenant" %
- self.tenant_name)
- else:
- if not os_utils.delete_tenant(self.keystone_client, tenant_id):
- self.logger.error("Error : Failed to remove %s tenant" %
- self.tenant_name)
-
- self.logger.info("Removing %s user .." % self.tenant_name)
- user_id = os_utils.get_user_id(
- self.keystone_client, self.tenant_name)
- if user_id == '':
- self.logger.error("Error : Failed to get id of %s user" %
- self.tenant_name)
- else:
- if not os_utils.delete_user(self.keystone_client, user_id):
- self.logger.error("Error : Failed to remove %s user" %
- self.tenant_name)
-
def parse_results(self):
exit_code = self.EX_OK
self.criteria = "PASS"
@@ -231,9 +213,10 @@ class VnfOnBoardingBase(base.TestCase):
def step_failure(self, error_msg):
part = inspect.stack()[1][3]
- self.logger.error("Step '%s' failed: %s", part, error_msg)
+ self.logger.error("Step {0} failed: {1}".format(part, error_msg))
try:
- part_info = self.details[part]
+ step_name = self.details_step_mapping[part]
+ part_info = self.details[step_name]
except KeyError:
self.details[part] = {}
part_info = self.details[part]
diff --git a/functest/utils/decorators.py b/functest/utils/decorators.py
index 276235d96..46ffe35d1 100644
--- a/functest/utils/decorators.py
+++ b/functest/utils/decorators.py
@@ -1,37 +1,42 @@
#!/usr/bin/env python
+# pylint: disable=missing-docstring
+
import errno
-import mock
import os
-import requests.sessions
import urlparse
+import mock
+import requests.sessions
+
def can_dump_request_to_file(method):
def dump_preparedrequest(request, **kwargs):
+ # pylint: disable=unused-argument
parseresult = urlparse.urlparse(request.url)
if parseresult.scheme == "file":
try:
- os.makedirs(parseresult.path)
- except OSError as e:
- if e.errno != errno.EEXIST:
+ dirname = os.path.dirname(parseresult.path)
+ os.makedirs(dirname)
+ except OSError as ex:
+ if ex.errno != errno.EEXIST:
raise
- with open(os.path.join(parseresult.path, 'dump.txt'), 'a') as f:
+ with open(parseresult.path, 'a') as dumpfile:
headers = ""
for key in request.headers:
headers += key + " " + request.headers[key] + "\n"
message = "{} {}\n{}\n{}\n\n\n".format(
request.method, request.url, headers, request.body)
- f.write(message)
+ dumpfile.write(message)
return mock.Mock()
def patch_request(method, url, **kwargs):
with requests.sessions.Session() as session:
parseresult = urlparse.urlparse(url)
if parseresult.scheme == "file":
- with mock.patch.object(
- session, 'send', side_effect=dump_preparedrequest):
+ with mock.patch.object(session, 'send',
+ side_effect=dump_preparedrequest):
return session.request(method=method, url=url, **kwargs)
else:
return session.request(method=method, url=url, **kwargs)
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py
index ef9d3da94..0d612412f 100644
--- a/functest/utils/functest_utils.py
+++ b/functest/utils/functest_utils.py
@@ -197,7 +197,7 @@ def push_results_to_db(project, case_name,
POST results to the Result target DB
"""
# Retrieve params from CI and conf
- url = get_db_url() + "/results"
+ url = get_db_url()
try:
installer = os.environ['INSTALLER_TYPE']
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py
index 4663f7ba6..929a761e0 100644
--- a/functest/utils/openstack_utils.py
+++ b/functest/utils/openstack_utils.py
@@ -1394,6 +1394,15 @@ def create_tenant(keystone_client, tenant_name, tenant_description):
return None
+def get_or_create_tenant(keystone_client, tenant_name, tenant_description):
+ tenant_id = get_tenant_id(keystone_client, tenant_name)
+ if not tenant_id:
+ tenant_id = create_tenant(keystone_client, tenant_name,
+ tenant_description)
+
+ return tenant_id
+
+
def create_user(keystone_client, user_name, user_password,
user_email, tenant_id):
try:
@@ -1417,6 +1426,15 @@ def create_user(keystone_client, user_name, user_password,
return None
+def get_or_create_user(keystone_client, user_name, user_password,
+ tenant_id, user_email=None):
+ user_id = get_user_id(keystone_client, user_name)
+ if not user_id:
+ user_id = create_user(keystone_client, user_name, user_password,
+ user_email, tenant_id)
+ return user_id
+
+
def add_role_user(keystone_client, user_id, role_id, tenant_id):
try:
if is_keystone_v3():