aboutsummaryrefslogtreecommitdiffstats
path: root/functest/core
diff options
context:
space:
mode:
Diffstat (limited to 'functest/core')
-rw-r--r--functest/core/feature_base.py11
-rw-r--r--functest/core/testcase_base.py47
-rw-r--r--functest/core/vnf_base.py55
3 files changed, 40 insertions, 73 deletions
diff --git a/functest/core/feature_base.py b/functest/core/feature_base.py
index 873e21da..2bd1ec83 100644
--- a/functest/core/feature_base.py
+++ b/functest/core/feature_base.py
@@ -7,6 +7,7 @@ from functest.utils.constants import CONST
class FeatureBase(base.TestcaseBase):
+
def __init__(self, project='functest', case='', repo='', cmd=''):
super(FeatureBase, self).__init__()
self.project_name = project
@@ -19,13 +20,21 @@ class FeatureBase(base.TestcaseBase):
def run(self, **kwargs):
self.prepare()
self.start_time = time.time()
- ret = ft_utils.execute_command(self.cmd, output_file=self.result_file)
+ ret = self.execute()
self.stop_time = time.time()
self.post()
self.parse_results(ret)
self.log_results()
+ self.logger.info("Test result is stored in '%s'" % self.result_file)
return base.TestcaseBase.EX_OK
+ def execute(self):
+ '''
+ Executer method that can be overwritten
+ By default it executes a shell command.
+ '''
+ return ft_utils.execute_command(self.cmd, output_file=self.result_file)
+
def prepare(self, **kwargs):
pass
diff --git a/functest/core/testcase_base.py b/functest/core/testcase_base.py
index ec46bc64..838b6398 100644
--- a/functest/core/testcase_base.py
+++ b/functest/core/testcase_base.py
@@ -9,7 +9,6 @@
import os
-from functest.utils.constants import CONST
import functest.utils.functest_logger as ft_logger
import functest.utils.functest_utils as ft_utils
@@ -18,7 +17,7 @@ class TestcaseBase(object):
EX_OK = os.EX_OK
EX_RUN_ERROR = os.EX_SOFTWARE
- EX_PUBLISH_RESULT_FAILED = os.EX_SOFTWARE - 1
+ EX_PUSH_TO_DB_ERROR = os.EX_SOFTWARE - 1
EX_TESTCASE_FAILED = os.EX_SOFTWARE - 2
logger = ft_logger.Logger(__name__).getLogger()
@@ -44,45 +43,21 @@ class TestcaseBase(object):
self.logger.error("Run must be implemented")
return TestcaseBase.EX_RUN_ERROR
- def publish_report(self):
- if "RESULTS_STORE" in os.environ:
- CONST.results_test_db_url = os.environ['RESULTS_STORE']
-
+ def push_to_db(self):
try:
assert self.project_name
assert self.case_name
assert self.criteria
assert self.start_time
assert self.stop_time
- if CONST.results_test_db_url.lower().startswith(
- ("http://", "https://")):
- self.push_to_db()
- elif CONST.results_test_db_url.lower().startswith("file://"):
- self.write_to_file()
+ if ft_utils.push_results_to_db(
+ self.project_name, self.case_name, self.start_time,
+ self.stop_time, self.criteria, self.details):
+ self.logger.info("The results were successfully pushed to DB")
+ return TestcaseBase.EX_OK
else:
- self.logger.error("Please check parameter test_db_url and "
- "OS environ variable RESTULTS_STORE")
- return TestcaseBase.EX_PUBLISH_RESULT_FAILED
+ self.logger.error("The results cannot be pushed to DB")
+ return TestcaseBase.EX_PUSH_TO_DB_ERROR
except Exception:
- self.logger.exception("The results cannot be stored")
- return TestcaseBase.EX_PUBLISH_RESULT_FAILED
-
- def write_to_file(self):
- if ft_utils.write_results_to_file(
- self.project_name, self.case_name, self.start_time,
- self.stop_time, self.criteria, self.details):
- self.logger.info("The results were successfully written to a file")
- return TestcaseBase.EX_OK
- else:
- self.logger.error("write results to a file failed")
- return TestcaseBase.EX_PUBLISH_RESULT_FAILED
-
- def push_to_db(self):
- if ft_utils.push_results_to_db(
- self.project_name, self.case_name, self.start_time,
- self.stop_time, self.criteria, self.details):
- self.logger.info("The results were successfully pushed to DB")
- return TestcaseBase.EX_OK
- else:
- self.logger.error("The results cannot be pushed to DB")
- return TestcaseBase.EX_PUBLISH_RESULT_FAILED
+ self.logger.exception("The results cannot be pushed to DB")
+ return TestcaseBase.EX_PUSH_TO_DB_ERROR
diff --git a/functest/core/vnf_base.py b/functest/core/vnf_base.py
index 4d019858..9438dca1 100644
--- a/functest/core/vnf_base.py
+++ b/functest/core/vnf_base.py
@@ -7,12 +7,10 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
-import os
import time
import inspect
-
import functest.utils.functest_logger as ft_logger
import functest.utils.openstack_utils as os_utils
import functest.utils.functest_utils as ft_utils
@@ -69,8 +67,8 @@ class VnfOnBoardingBase(base.TestcaseBase):
res_orchestrator['result'])
self.details['orchestrator']['duration'] = round(
orchestrator_ready_time - self.start_time, 1)
- except:
- self.logger.warn("Problem with the Orchestrator")
+ except Exception:
+ self.logger.warn("Problem with the Orchestrator", exc_info=True)
# Deploy VNF
try:
@@ -113,9 +111,9 @@ class VnfOnBoardingBase(base.TestcaseBase):
self.keystone_client = os_utils.get_keystone_client()
self.logger.info("Prepare OpenStack plateform(create tenant and user)")
- user_id = os_utils.get_user_id(self.keystone_client,
- self.creds['username'])
- if user_id == '':
+ 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'])
@@ -135,7 +133,7 @@ class VnfOnBoardingBase(base.TestcaseBase):
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, user_id,
+ 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'])
@@ -151,40 +149,25 @@ class VnfOnBoardingBase(base.TestcaseBase):
self.logger.error("Failed to create %s user" % self.tenant_name)
self.step_failure("Failed to create user ")
+ 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)
+
self.logger.info("Update OpenStack creds informations")
- self.creds.update({
- "tenant": self.tenant_name,
+ self.admin_creds = self.creds.copy()
+ self.admin_creds.update({
+ "tenant": self.tenant_name
})
- self.neutron_client = os_utils.get_neutron_client(self.creds)
- self.nova_client = os_utils.get_nova_client(self.creds)
+ self.neutron_client = os_utils.get_neutron_client(self.admin_creds)
+ self.nova_client = os_utils.get_nova_client(self.admin_creds)
self.creds.update({
+ "tenant": self.tenant_name,
"username": self.tenant_name,
"password": self.tenant_name,
})
- self.glance_client = os_utils.get_glance_client(self.creds)
- self.logger.info("Upload some OS images if it doesn't exist")
-
- temp_dir = os.path.join(self.data_dir, "tmp/")
- for image_name, image_url in self.images.iteritems():
- image_id = os_utils.get_image_id(self.glance_client, image_name)
-
- if image_id == '':
- self.logger.info("""%s image doesn't exist on glance repository. Try
- downloading this image and upload on glance !""" % image_name)
- image_id = os_utils.download_and_add_image_on_glance(
- self.glance_client, image_name, image_url, temp_dir)
-
- if image_id == '':
- self.step_failure(
- "Failed to find or upload required OS "
- "image for this deployment")
-
- self.logger.info("Update security group quota for this tenant")
-
- if not os_utils.update_sg_quota(self.neutron_client,
- tenant_id, 50, 100):
- self.step_failure("Failed to update security group quota" +
- " for tenant " + self.tenant_name)
# orchestrator is not mandatory to dpeloy and test VNF
def deploy_orchestrator(self, **kwargs):