X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=functest%2Fopnfv_tests%2Fopenstack%2Ftempest%2Ftempest.py;h=cb8e9b4a5384881bcb13051f1e89f9d5a2d62316;hb=a28e2b40877f022f6cc8bbc3ad9b586ef3dd126c;hp=f925336d4eb3d6397743e98ef0b00b0b19647904;hpb=0b5f01779a50b36d775a5ed8fed53106d04c450c;p=functest.git diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py index f925336d4..cb8e9b4a5 100644 --- a/functest/opnfv_tests/openstack/tempest/tempest.py +++ b/functest/opnfv_tests/openstack/tempest/tempest.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # # Copyright (c) 2015 All rights reserved # This program and the accompanying materials @@ -8,6 +8,9 @@ # http://www.apache.org/licenses/LICENSE-2.0 # +from __future__ import division + +import logging import os import re import shutil @@ -16,25 +19,21 @@ import time import yaml -from functest.core import testcase_base +from functest.core import testcase from functest.opnfv_tests.openstack.tempest import conf_utils from functest.utils.constants import CONST -import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils -import functest.utils.openstack_utils as os_utils """ logging configuration """ -logger = ft_logger.Logger("Tempest").getLogger() +logger = logging.getLogger(__name__) -class TempestCommon(testcase_base.TestcaseBase): +class TempestCommon(testcase.OSGCTestCase): - def __init__(self): - super(TempestCommon, self).__init__() + def __init__(self, **kwargs): + super(TempestCommon, self).__init__(**kwargs) self.MODE = "" self.OPTION = "" - self.FLAVOR_ID = None - self.IMAGE_ID = None self.VERIFIER_ID = conf_utils.get_verifier_id() self.VERIFIER_REPO_DIR = conf_utils.get_verifier_repo_dir( self.VERIFIER_ID) @@ -48,55 +47,6 @@ class TempestCommon(testcase_base.TestcaseBase): with open(filename) as src: return [line.strip() for line in src.readlines()] - def create_tempest_resources(self): - keystone_client = os_utils.get_keystone_client() - - logger.debug("Creating tenant and user for Tempest suite") - tenant_id = os_utils.create_tenant( - keystone_client, - CONST.tempest_identity_tenant_name, - CONST.tempest_identity_tenant_description) - if not tenant_id: - logger.error("Failed to create %s tenant" - % CONST.tempest_identity_tenant_name) - - user_id = os_utils.create_user(keystone_client, - CONST.tempest_identity_user_name, - CONST.tempest_identity_user_password, - None, tenant_id) - if not user_id: - logger.error("Failed to create %s user" % - CONST.tempest_identity_user_name) - - logger.debug("Creating private network for Tempest suite") - network_dic = os_utils.create_shared_network_full( - CONST.tempest_private_net_name, - CONST.tempest_private_subnet_name, - CONST.tempest_router_name, - CONST.tempest_private_subnet_cidr) - if network_dic is None: - raise Exception('Failed to create private network') - - if CONST.tempest_use_custom_images: - # adding alternative image should be trivial should we need it - logger.debug("Creating image for Tempest suite") - _, self.IMAGE_ID = os_utils.get_or_create_image( - CONST.openstack_image_name, conf_utils.GLANCE_IMAGE_PATH, - CONST.openstack_image_disk_format) - if self.IMAGE_ID is None: - raise Exception('Failed to create image') - - if CONST.tempest_use_custom_flavors: - # adding alternative flavor should be trivial should we need it - logger.debug("Creating flavor for Tempest suite") - _, self.FLAVOR_ID = os_utils.get_or_create_flavor( - CONST.openstack_flavor_name, - CONST.openstack_flavor_ram, - CONST.openstack_flavor_disk, - CONST.openstack_flavor_vcpus) - if self.FLAVOR_ID is None: - raise Exception('Failed to create flavor') - def generate_test_list(self, verifier_repo_dir): logger.debug("Generating test case list...") if self.MODE == 'defcore': @@ -131,8 +81,8 @@ class TempestCommon(testcase_base.TestcaseBase): result_file = open(conf_utils.TEMPEST_LIST, 'w') black_tests = [] try: - installer_type = CONST.INSTALLER_TYPE - deploy_scenario = CONST.DEPLOY_SCENARIO + installer_type = CONST.__getattribute__('INSTALLER_TYPE') + deploy_scenario = CONST.__getattribute__('DEPLOY_SCENARIO') if (bool(installer_type) * bool(deploy_scenario)): # if INSTALLER_TYPE and DEPLOY_SCENARIO are set we read the # file @@ -160,22 +110,18 @@ class TempestCommon(testcase_base.TestcaseBase): result_file.write(str(cases_line) + '\n') result_file.close() - def _parse_verification_id(line): - first_pos = line.index("UUID=") + len("UUID=") - last_pos = line.index(") for deployment") - return line[first_pos:last_pos] - def run_verifier_tests(self): - self.OPTION += (" --load-list {}".format(conf_utils.TEMPEST_LIST)) + self.OPTION += (" --load-list {} --detailed" + .format(conf_utils.TEMPEST_LIST)) cmd_line = "rally verify start " + self.OPTION logger.info("Starting Tempest test suite: '%s'." % cmd_line) header = ("Tempest environment:\n" - " Installer: %s\n Scenario: %s\n Node: %s\n Date: %s\n" % - (CONST.INSTALLER_TYPE, - CONST.DEPLOY_SCENARIO, - CONST.NODE_NAME, + " SUT: %s\n Scenario: %s\n Node: %s\n Date: %s\n" % + (CONST.__getattribute__('INSTALLER_TYPE'), + CONST.__getattribute__('DEPLOY_SCENARIO'), + CONST.__getattribute__('NODE_NAME'), time.strftime("%a %b %d %H:%M:%S %Z %Y"))) f_stdout = open( @@ -202,7 +148,7 @@ class TempestCommon(testcase_base.TestcaseBase): first_pos = line.index("UUID=") + len("UUID=") last_pos = line.index(") for deployment") self.VERIFICATION_ID = line[first_pos:last_pos] - logger.debug('Verication UUID: %s' % self.VERIFICATION_ID) + logger.debug('Verification UUID: %s', self.VERIFICATION_ID) f_stdout.write(line) p.wait() @@ -237,7 +183,13 @@ class TempestCommon(testcase_base.TestcaseBase): try: num_executed = int(num_tests) - int(num_skipped) - success_rate = 100 * int(num_success) / int(num_executed) + try: + self.result = 100 * int(num_success) / int(num_executed) + except ZeroDivisionError: + logger.error("No test has been executed") + self.result = 0 + return + with open(os.path.join(conf_utils.TEMPEST_RESULTS_DIR, "tempest.log"), 'r') as logfile: output = logfile.read() @@ -254,34 +206,31 @@ class TempestCommon(testcase_base.TestcaseBase): "errors": error_logs, "skipped": skipped_testcase} except Exception: - success_rate = 0 + self.result = 0 - self.criteria = ft_utils.check_success_rate( - self.case_name, success_rate) - logger.info("Tempest %s success_rate is %s%%, is marked as %s" - % (self.case_name, success_rate, self.criteria)) + logger.info("Tempest %s success_rate is %s%%" + % (self.case_name, self.result)) def run(self): self.start_time = time.time() - - if not os.path.exists(conf_utils.TEMPEST_RESULTS_DIR): - os.makedirs(conf_utils.TEMPEST_RESULTS_DIR) - try: - self.create_tempest_resources() - conf_utils.configure_tempest(self.DEPLOYMENT_DIR, - self.IMAGE_ID, - self.FLAVOR_ID, - self.MODE) + if not os.path.exists(conf_utils.TEMPEST_RESULTS_DIR): + os.makedirs(conf_utils.TEMPEST_RESULTS_DIR) + image_and_flavor = conf_utils.create_tempest_resources() + conf_utils.configure_tempest( + self.DEPLOYMENT_DIR, + IMAGE_ID=image_and_flavor.get("image_id"), + FLAVOR_ID=image_and_flavor.get("flavor_id"), + MODE=self.MODE) self.generate_test_list(self.VERIFIER_REPO_DIR) self.apply_tempest_blacklist() self.run_verifier_tests() self.parse_verifier_result() - res = testcase_base.TestcaseBase.EX_OK + res = testcase.TestCase.EX_OK except Exception as e: logger.error('Error with run: %s' % e) - res = testcase_base.TestcaseBase.EX_RUN_ERROR + res = testcase.TestCase.EX_RUN_ERROR self.stop_time = time.time() return res @@ -289,43 +238,60 @@ class TempestCommon(testcase_base.TestcaseBase): class TempestSmokeSerial(TempestCommon): - def __init__(self): - TempestCommon.__init__(self) - self.case_name = "tempest_smoke_serial" + def __init__(self, **kwargs): + if "case_name" not in kwargs: + kwargs["case_name"] = 'tempest_smoke_serial' + TempestCommon.__init__(self, **kwargs) self.MODE = "smoke" self.OPTION = "--concurrency 1" class TempestSmokeParallel(TempestCommon): - def __init__(self): - TempestCommon.__init__(self) - self.case_name = "tempest_smoke_parallel" + def __init__(self, **kwargs): + if "case_name" not in kwargs: + kwargs["case_name"] = 'tempest_smoke_parallel' + TempestCommon.__init__(self, **kwargs) self.MODE = "smoke" self.OPTION = "" class TempestFullParallel(TempestCommon): - def __init__(self): - TempestCommon.__init__(self) - self.case_name = "tempest_full_parallel" + def __init__(self, **kwargs): + if "case_name" not in kwargs: + kwargs["case_name"] = 'tempest_full_parallel' + TempestCommon.__init__(self, **kwargs) self.MODE = "full" class TempestMultisite(TempestCommon): - def __init__(self): - TempestCommon.__init__(self) - self.case_name = "multisite" + def __init__(self, **kwargs): + if "case_name" not in kwargs: + kwargs["case_name"] = 'multisite' + TempestCommon.__init__(self, **kwargs) self.MODE = "feature_multisite" self.OPTION = "--concurrency 1" + conf_utils.install_verifier_ext( + CONST.__getattribute__('dir_repo_kingbird')) class TempestCustom(TempestCommon): - def __init__(self, mode, option): - TempestCommon.__init__(self) - self.case_name = "tempest_custom" - self.MODE = mode - self.OPTION = option + def __init__(self, **kwargs): + if "case_name" not in kwargs: + kwargs["case_name"] = 'tempest_custom' + TempestCommon.__init__(self, **kwargs) + self.MODE = "custom" + self.OPTION = "--concurrency 1" + + +class TempestDefcore(TempestCommon): + + def __init__(self, **kwargs): + if "case_name" not in kwargs: + kwargs["case_name"] = 'tempest_defcore' + TempestCommon.__init__(self, **kwargs) + self.MODE = "defcore" + self.OPTION = "--concurrency 1"