diff options
author | Juha Kosonen <juha.kosonen@nokia.com> | 2018-02-09 17:35:46 +0200 |
---|---|---|
committer | Juha Kosonen <juha.kosonen@nokia.com> | 2018-02-09 17:35:46 +0200 |
commit | 918eafbc4b9a71a2e7be062aaccaa073a86772ee (patch) | |
tree | 97d29b23ad9b24026cbcea798bce33b6cf94f3b8 /functest/opnfv_tests/openstack/tempest/tempest.py | |
parent | 9fd0361c6361b061eae3851e61f9d16edffc6de7 (diff) |
Fix pylint errors/warnings in tempest modules
JIRA: FUNCTEST-913
Change-Id: I37b25bbcf43fb1d6f7de0c815ad49070d1e1af12
Signed-off-by: Juha Kosonen <juha.kosonen@nokia.com>
Diffstat (limited to 'functest/opnfv_tests/openstack/tempest/tempest.py')
-rw-r--r-- | functest/opnfv_tests/openstack/tempest/tempest.py | 206 |
1 files changed, 112 insertions, 94 deletions
diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py index e75192b9..c5ad4ecb 100644 --- a/functest/opnfv_tests/openstack/tempest/tempest.py +++ b/functest/opnfv_tests/openstack/tempest/tempest.py @@ -8,6 +8,8 @@ # http://www.apache.org/licenses/LICENSE-2.0 # +"""Tempest testcases implementation.""" + from __future__ import division import logging @@ -37,36 +39,68 @@ from snaps.openstack.tests import openstack_tests from snaps.openstack.utils import deploy_utils -""" logging configuration """ -logger = logging.getLogger(__name__) +LOGGER = logging.getLogger(__name__) class TempestCommon(testcase.TestCase): + # pylint: disable=too-many-instance-attributes + """TempestCommon testcases implementation class.""" def __init__(self, **kwargs): super(TempestCommon, self).__init__(**kwargs) self.resources = TempestResourcesManager(**kwargs) - self.MODE = "" - self.OPTION = [] - self.VERIFIER_ID = conf_utils.get_verifier_id() - self.VERIFIER_REPO_DIR = conf_utils.get_verifier_repo_dir( - self.VERIFIER_ID) - self.DEPLOYMENT_ID = conf_utils.get_verifier_deployment_id() - self.DEPLOYMENT_DIR = conf_utils.get_verifier_deployment_dir( - self.VERIFIER_ID, self.DEPLOYMENT_ID) - self.VERIFICATION_ID = None + self.mode = "" + self.option = [] + self.verifier_id = conf_utils.get_verifier_id() + self.verifier_repo_dir = conf_utils.get_verifier_repo_dir( + self.verifier_id) + self.deployment_id = conf_utils.get_verifier_deployment_id() + self.deployment_dir = conf_utils.get_verifier_deployment_dir( + self.verifier_id, self.deployment_id) + self.verification_id = None @staticmethod def read_file(filename): + """Read file and return content as a stripped list.""" with open(filename) as src: return [line.strip() for line in src.readlines()] + @staticmethod + def get_verifier_result(verif_id): + """Retrieve verification results.""" + result = { + 'num_tests': 0, + 'num_success': 0, + 'num_failures': 0, + 'num_skipped': 0 + } + cmd = ["rally", "verify", "show", "--uuid", verif_id] + LOGGER.info("Showing result for a verification: '%s'.", cmd) + proc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + for line in proc.stdout: + new_line = line.replace(' ', '').split('|') + if 'Tests' in new_line: + break + LOGGER.info(line) + if 'Testscount' in new_line: + result['num_tests'] = int(new_line[2]) + elif 'Success' in new_line: + result['num_success'] = int(new_line[2]) + elif 'Skipped' in new_line: + result['num_skipped'] = int(new_line[2]) + elif 'Failures' in new_line: + result['num_failures'] = int(new_line[2]) + return result + def generate_test_list(self, verifier_repo_dir): - logger.debug("Generating test case list...") - if self.MODE == 'defcore': + """Generate test list based on the test mode.""" + LOGGER.debug("Generating test case list...") + if self.mode == 'defcore': shutil.copyfile( conf_utils.TEMPEST_DEFCORE, conf_utils.TEMPEST_RAW_LIST) - elif self.MODE == 'custom': + elif self.mode == 'custom': if os.path.isfile(conf_utils.TEMPEST_CUSTOM): shutil.copyfile( conf_utils.TEMPEST_CUSTOM, conf_utils.TEMPEST_RAW_LIST) @@ -74,12 +108,12 @@ class TempestCommon(testcase.TestCase): raise Exception("Tempest test list file %s NOT found." % conf_utils.TEMPEST_CUSTOM) else: - if self.MODE == 'smoke': + if self.mode == 'smoke': testr_mode = "smoke" - elif self.MODE == 'full': + elif self.mode == 'full': testr_mode = "" else: - testr_mode = 'tempest.api.' + self.MODE + testr_mode = 'tempest.api.' + self.mode cmd = ("cd {0};" "testr list-tests {1} > {2};" "cd -;".format(verifier_repo_dir, @@ -88,14 +122,15 @@ class TempestCommon(testcase.TestCase): ft_utils.execute_command(cmd) def apply_tempest_blacklist(self): - logger.debug("Applying tempest blacklist...") + """Exclude blacklisted test cases.""" + LOGGER.debug("Applying tempest blacklist...") cases_file = self.read_file(conf_utils.TEMPEST_RAW_LIST) result_file = open(conf_utils.TEMPEST_LIST, 'w') black_tests = [] try: installer_type = CONST.__getattribute__('INSTALLER_TYPE') deploy_scenario = CONST.__getattribute__('DEPLOY_SCENARIO') - if (bool(installer_type) * bool(deploy_scenario)): + if bool(installer_type) * bool(deploy_scenario): # if INSTALLER_TYPE and DEPLOY_SCENARIO are set we read the # file black_list_file = open(conf_utils.TEMPEST_BLACKLIST) @@ -110,9 +145,9 @@ class TempestCommon(testcase.TestCase): for test in tests: black_tests.append(test) break - except Exception: + except Exception: # pylint: disable=broad-except black_tests = [] - logger.debug("Tempest blacklist file does not exist.") + LOGGER.debug("Tempest blacklist file does not exist.") for cases_line in cases_file: for black_tests_line in black_tests: @@ -123,10 +158,11 @@ class TempestCommon(testcase.TestCase): result_file.close() def run_verifier_tests(self): + """Execute tempest test cases.""" cmd = ["rally", "verify", "start", "--load-list", conf_utils.TEMPEST_LIST] - cmd.extend(self.OPTION) - logger.info("Starting Tempest test suite: '%s'." % cmd) + cmd.extend(self.option) + LOGGER.info("Starting Tempest test suite: '%s'.", cmd) header = ("Tempest environment:\n" " SUT: %s\n Scenario: %s\n Node: %s\n Date: %s\n" % @@ -144,63 +180,45 @@ class TempestCommon(testcase.TestCase): "environment.log"), 'w+') f_env.write(header) - p = subprocess.Popen( + proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=f_stderr, bufsize=1) - with p.stdout: - for line in iter(p.stdout.readline, b''): - if re.search("\} tempest\.", line): - logger.info(line.replace('\n', '')) + with proc.stdout: + for line in iter(proc.stdout.readline, b''): + if re.search(r"\} tempest\.", line): + LOGGER.info(line.replace('\n', '')) elif re.search('Starting verification', line): - logger.info(line.replace('\n', '')) + LOGGER.info(line.replace('\n', '')) first_pos = line.index("UUID=") + len("UUID=") last_pos = line.index(") for deployment") - self.VERIFICATION_ID = line[first_pos:last_pos] - logger.debug('Verification UUID: %s', self.VERIFICATION_ID) + self.verification_id = line[first_pos:last_pos] + LOGGER.debug('Verification UUID: %s', self.verification_id) f_stdout.write(line) - p.wait() + proc.wait() f_stdout.close() f_stderr.close() f_env.close() def parse_verifier_result(self): - if self.VERIFICATION_ID is None: + """Parse and save test results.""" + if self.verification_id is None: raise Exception('Verification UUID not found') - cmd = ["rally", "verify", "show", "--uuid", self.VERIFICATION_ID] - logger.info("Showing result for a verification: '%s'." % cmd) - p = subprocess.Popen(cmd, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) - for line in p.stdout: - new_line = line.replace(' ', '').split('|') - if 'Tests' in new_line: - break - - logger.info(line) - if 'Testscount' in new_line: - num_tests = new_line[2] - elif 'Success' in new_line: - num_success = new_line[2] - elif 'Skipped' in new_line: - num_skipped = new_line[2] - elif 'Failures' in new_line: - num_failures = new_line[2] - + stat = self.get_verifier_result(self.verification_id) try: - num_executed = int(num_tests) - int(num_skipped) + num_executed = stat['num_tests'] - stat['num_skipped'] try: - self.result = 100 * int(num_success) / int(num_executed) + self.result = 100 * stat['num_success'] / num_executed except ZeroDivisionError: self.result = 0 - if int(num_tests) > 0: - logger.info("All tests have been skipped") + if stat['num_tests'] > 0: + LOGGER.info("All tests have been skipped") else: - logger.error("No test has been executed") + LOGGER.error("No test has been executed") return with open(os.path.join(conf_utils.TEMPEST_RESULTS_DIR, @@ -208,25 +226,25 @@ class TempestCommon(testcase.TestCase): output = logfile.read() success_testcases = [] - for match in re.findall('.*\{0\} (.*?)[. ]*success ', output): + for match in re.findall(r'.*\{0\} (.*?)[. ]*success ', output): success_testcases.append(match) failed_testcases = [] - for match in re.findall('.*\{0\} (.*?)[. ]*fail ', output): + for match in re.findall(r'.*\{0\} (.*?)[. ]*fail ', output): failed_testcases.append(match) skipped_testcases = [] - for match in re.findall('.*\{0\} (.*?)[. ]*skip:', output): + for match in re.findall(r'.*\{0\} (.*?)[. ]*skip:', output): skipped_testcases.append(match) - self.details = {"tests": int(num_tests), - "failures": int(num_failures), + self.details = {"tests": stat['num_tests'], + "failures": stat['num_failures'], "success": success_testcases, - "errors": failed_testcases, - "skipped": skipped_testcases} - except Exception: + "skipped": skipped_testcases, + "errors": failed_testcases} + except Exception: # pylint: disable=broad-except self.result = 0 - logger.info("Tempest %s success_rate is %s%%" - % (self.case_name, self.result)) + LOGGER.info("Tempest %s success_rate is %s%%", + self.case_name, self.result) def run(self): @@ -238,17 +256,17 @@ class TempestCommon(testcase.TestCase): compute_cnt = snaps_utils.get_active_compute_cnt( self.resources.os_creds) conf_utils.configure_tempest( - self.DEPLOYMENT_DIR, + self.deployment_dir, image_id=resources.get("image_id"), flavor_id=resources.get("flavor_id"), compute_cnt=compute_cnt) - self.generate_test_list(self.VERIFIER_REPO_DIR) + self.generate_test_list(self.verifier_repo_dir) self.apply_tempest_blacklist() self.run_verifier_tests() self.parse_verifier_result() res = testcase.TestCase.EX_OK - except Exception as e: - logger.error('Error with run: %s' % e) + except Exception as err: # pylint: disable=broad-except + LOGGER.error('Error with run: %s', err) res = testcase.TestCase.EX_RUN_ERROR finally: self.resources.cleanup() @@ -258,55 +276,55 @@ class TempestCommon(testcase.TestCase): class TempestSmokeSerial(TempestCommon): - + """Tempest smoke serial testcase implementation.""" 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"] + self.mode = "smoke" + self.option = ["--concurrency", "1"] class TempestSmokeParallel(TempestCommon): - + """Tempest smoke parallel testcase implementation.""" def __init__(self, **kwargs): if "case_name" not in kwargs: kwargs["case_name"] = 'tempest_smoke_parallel' TempestCommon.__init__(self, **kwargs) - self.MODE = "smoke" + self.mode = "smoke" class TempestFullParallel(TempestCommon): - + """Tempest full parallel testcase implementation.""" def __init__(self, **kwargs): if "case_name" not in kwargs: kwargs["case_name"] = 'tempest_full_parallel' TempestCommon.__init__(self, **kwargs) - self.MODE = "full" + self.mode = "full" class TempestCustom(TempestCommon): - + """Tempest custom testcase implementation.""" 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"] + self.mode = "custom" + self.option = ["--concurrency", "1"] class TempestDefcore(TempestCommon): - + """Tempest Defcore testcase implementation.""" 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"] + self.mode = "defcore" + self.option = ["--concurrency", "1"] class TempestResourcesManager(object): - + """Tempest resource manager.""" def __init__(self, **kwargs): self.os_creds = kwargs.get('os_creds') or snaps_utils.get_credentials() self.guid = '-' + str(uuid.uuid4()) @@ -423,34 +441,34 @@ class TempestResourcesManager(object): project_name = None if create_project: - logger.debug("Creating project and user for Tempest suite") + LOGGER.debug("Creating project and user for Tempest suite") project_name = CONST.__getattribute__( 'tempest_identity_tenant_name') + self.guid result['project_id'] = self._create_project() result['user_id'] = self._create_user() result['tenant_id'] = result['project_id'] # for compatibility - logger.debug("Creating private network for Tempest suite") + LOGGER.debug("Creating private network for Tempest suite") self._create_network(project_name) - logger.debug("Creating image for Tempest suite") + LOGGER.debug("Creating image for Tempest suite") image_name = CONST.__getattribute__('openstack_image_name') + self.guid result['image_id'] = self._create_image(image_name) if use_custom_images: - logger.debug("Creating 2nd image for Tempest suite") + LOGGER.debug("Creating 2nd image for Tempest suite") image_name = CONST.__getattribute__( 'openstack_image_name_alt') + self.guid result['image_id_alt'] = self._create_image(image_name) if (CONST.__getattribute__('tempest_use_custom_flavors') == 'True' or use_custom_flavors): - logger.info("Creating flavor for Tempest suite") + LOGGER.info("Creating flavor for Tempest suite") name = CONST.__getattribute__('openstack_flavor_name') + self.guid result['flavor_id'] = self._create_flavor(name) if use_custom_flavors: - logger.info("Creating 2nd flavor for Tempest suite") + LOGGER.info("Creating 2nd flavor for Tempest suite") scenario = CONST.__getattribute__('DEPLOY_SCENARIO') if 'ovs' in scenario or 'fdio' in scenario: CONST.__setattr__('openstack_flavor_ram', 1024) @@ -467,5 +485,5 @@ class TempestResourcesManager(object): for creator in reversed(self.creators): try: creator.clean() - except Exception as e: - logger.error('Unexpected error cleaning - %s', e) + except Exception as err: # pylint: disable=broad-except + LOGGER.error('Unexpected error cleaning - %s', err) |