X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=functest%2Fci%2Frun_tests.py;h=03d62d99208e6f09dbddd38892899303abfdd117;hb=205d3b5eb0c92c604567c56286d1faeeb36b7c13;hp=a129ea73798ef99930eef27487e195dace2ab76e;hpb=d1a14868f9747b64d0e3ab8e5a13aa58e087a3d8;p=functest.git diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py index a129ea737..03d62d992 100644 --- a/functest/ci/run_tests.py +++ b/functest/ci/run_tests.py @@ -19,6 +19,7 @@ import sys import textwrap import prettytable +import yaml import functest.ci.tier_builder as tb import functest.core.testcase as testcase @@ -29,6 +30,16 @@ from functest.utils.constants import CONST # __name__ cannot be used here logger = logging.getLogger('functest.ci.run_tests') +CONFIG_FUNCTEST_PATH = pkg_resources.resource_filename( + 'functest', 'ci/config_functest.yaml') +CONFIG_PATCH_PATH = pkg_resources.resource_filename( + 'functest', 'ci/config_patch.yaml') +CONFIG_AARCH64_PATCH_PATH = pkg_resources.resource_filename( + 'functest', 'ci/config_aarch64_patch.yaml') +# set the architecture to default +pod_arch = os.getenv("POD_ARCH", None) +arch_filter = ['aarch64'] + class Result(enum.Enum): EX_OK = os.EX_OK @@ -75,6 +86,44 @@ class Runner(object): CONST.__getattribute__('DEPLOY_SCENARIO'), pkg_resources.resource_filename('functest', 'ci/testcases.yaml')) + @staticmethod + def update_config_file(): + Runner.patch_file(CONFIG_PATCH_PATH) + + if pod_arch and pod_arch in arch_filter: + Runner.patch_file(CONFIG_AARCH64_PATCH_PATH) + + if "TEST_DB_URL" in os.environ: + Runner.update_db_url() + + @staticmethod + def patch_file(patch_file_path): + logger.debug('Updating file: %s', patch_file_path) + with open(patch_file_path) as f: + patch_file = yaml.safe_load(f) + + updated = False + for key in patch_file: + if key in CONST.__getattribute__('DEPLOY_SCENARIO'): + new_functest_yaml = dict(ft_utils.merge_dicts( + ft_utils.get_functest_yaml(), patch_file[key])) + updated = True + + if updated: + os.remove(CONFIG_FUNCTEST_PATH) + with open(CONFIG_FUNCTEST_PATH, "w") as f: + f.write(yaml.dump(new_functest_yaml, default_style='"')) + + @staticmethod + def update_db_url(): + with open(CONFIG_FUNCTEST_PATH) as f: + functest_yaml = yaml.safe_load(f) + + with open(CONFIG_FUNCTEST_PATH, "w") as f: + functest_yaml["results"]["test_db_url"] = os.environ.get( + 'TEST_DB_URL') + f.write(yaml.dump(functest_yaml, default_style='"')) + @staticmethod def source_rc_file(): rc_file = CONST.__getattribute__('openstack_creds') @@ -124,16 +173,18 @@ class Runner(object): self.executed_test_cases[test.get_name()] = test_case if self.clean_flag: if test_case.create_snapshot() != test_case.EX_OK: - return result + return testcase.TestCase.EX_RUN_ERROR try: kwargs = run_dict['args'] - result = test_case.run(**kwargs) + test_case.run(**kwargs) except KeyError: - result = test_case.run() - if result == testcase.TestCase.EX_OK: - if self.report_flag: - test_case.push_to_db() + test_case.run() + if self.report_flag: + test_case.push_to_db() + if test.get_project() == "functest": result = test_case.is_successful() + else: + result = testcase.TestCase.EX_OK logger.info("Test result:\n\n%s\n", test_case) if self.clean_flag: test_case.clean() @@ -157,10 +208,12 @@ class Runner(object): else: logger.info("Running tier '%s'" % tier_name) for test in tests: - result = self.run_test(test) - if result != testcase.TestCase.EX_OK: + self.run_test(test) + test_case = self.executed_test_cases[test.get_name()] + if test_case.is_successful() != testcase.TestCase.EX_OK: logger.error("The test case '%s' failed.", test.get_name()) - self.overall_result = Result.EX_ERROR + if test.get_project() == "functest": + self.overall_result = Result.EX_ERROR if test.is_blocking(): raise BlockingTestFailed( "The test case {} failed and is blocking".format( @@ -188,6 +241,8 @@ class Runner(object): self.run_tier(tier) def main(self, **kwargs): + Runner.update_config_file() + if 'noclean' in kwargs: self.clean_flag = not kwargs['noclean'] if 'report' in kwargs: