Fully cover vnf
[functest.git] / functest / ci / run_tests.py
index feafa89..03d62d9 100644 (file)
@@ -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:
@@ -264,6 +319,7 @@ class Runner(object):
 def main():
     logging.config.fileConfig(pkg_resources.resource_filename(
         'functest', 'ci/logging.ini'))
+    logging.captureWarnings(True)
     parser = RunTestsParser()
     args = parser.parse_args(sys.argv[1:])
     runner = Runner()