Search config files in tree 42/73242/2
authorCédric Ollivier <cedric.ollivier@orange.com>
Thu, 3 Mar 2022 14:29:16 +0000 (15:29 +0100)
committerCédric Ollivier <cedric.ollivier@orange.com>
Thu, 3 Mar 2022 14:44:28 +0000 (15:44 +0100)
It allows putting configurations in classical dirs.
It fallbacks to the python package for backward compatibility.

Change-Id: Ie33b9482fb197926c7d7d66ace815fa4ae01d02d
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
docker/core/Dockerfile
docker/mts/Dockerfile
xtesting/ci/run_tests.py
xtesting/ci/testcases.yaml
xtesting/utils/constants.py

index c91c636..aca1a46 100644 (file)
@@ -25,5 +25,5 @@ RUN apk -U upgrade && \
         /src/functest-xtesting && \
     rm -r /src/functest-xtesting upper-constraints.txt && \
     apk del .build-deps
-COPY testcases.yaml /usr/lib/python3.9/site-packages/xtesting/ci/testcases.yaml
+COPY testcases.yaml /etc/xtesting/testcases.yaml
 CMD ["run_tests", "-t", "all"]
index eae61aa..dba860f 100644 (file)
@@ -21,5 +21,5 @@ RUN case $(uname -m) in x86_64) \
             java -jar target/mts-${MTS_TAG}-installer.jar -options /src/mts-installer.properties) && \
         rm -rf /root/.m2/ ${APP_FOLDER}/tutorial /src/mts-installer.properties /src/git-mts && \
         apk del .build-deps;; esac
-COPY testcases.yaml /usr/lib/python3.9/site-packages/xtesting/ci/testcases.yaml
+COPY testcases.yaml /etc/xtesting/testcases.yaml
 CMD ["run_tests", "-t", "all"]
index 16e7ef1..c88c828 100644 (file)
@@ -88,8 +88,9 @@ class Runner():
         self.clean_flag = True
         self.report_flag = False
         self.push_flag = False
-        self.tiers = tier_builder.TierBuilder(
-            pkg_resources.resource_filename('xtesting', 'ci/testcases.yaml'))
+        self.tiers = tier_builder.TierBuilder(_get_xtesting_config(
+            constants.TESTCASE_DESCRIPTION,
+            constants.TESTCASE_DESCRIPTION_DEFAULT))
 
     @staticmethod
     def source_envfile(rc_file=constants.ENV_FILE):
@@ -304,6 +305,14 @@ class Runner():
         LOGGER.info("Xtesting report:\n\n%s\n", msg)
 
 
+def _get_xtesting_config(filename, default):
+    for path in constants.XTESTING_PATHES:
+        abspath = os.path.abspath(os.path.expanduser(path))
+        if os.path.isfile(os.path.join(abspath, filename)):
+            return os.path.join(abspath, filename)
+    return default
+
+
 def main():
     """Entry point"""
     try:
@@ -313,11 +322,11 @@ def main():
             print(f"Cannot create {constants.RESULTS_DIR}")
             return testcase.TestCase.EX_RUN_ERROR
     if env.get('DEBUG').lower() == 'true':
-        logging.config.fileConfig(pkg_resources.resource_filename(
-            'xtesting', constants.DEBUG_INI_PATH))
+        logging.config.fileConfig(_get_xtesting_config(
+            'logging.debug.ini', constants.DEBUG_INI_PATH_DEFAULT))
     else:
-        logging.config.fileConfig(pkg_resources.resource_filename(
-            'xtesting', constants.INI_PATH))
+        logging.config.fileConfig(_get_xtesting_config(
+            'logging.ini', constants.INI_PATH_DEFAULT))
     logging.captureWarnings(True)
     parser = RunTestsParser()
     args = parser.parse_args(sys.argv[1:])
index 16dd263..a5f3f8e 100644 (file)
@@ -51,7 +51,7 @@ tiers:
           args:
             suites:
               - >-
-                /usr/lib/python3.8/site-packages/xtesting/samples/HelloWorld.robot
+                /usr/lib/python3.9/site-packages/xtesting/samples/HelloWorld.robot
             variable:
               - 'var01:foo'
               - 'var02:bar'
@@ -66,7 +66,7 @@ tiers:
           name: behaveframework
           args:
             suites:
-              - /usr/lib/python3.8/site-packages/xtesting/samples/features
+              - /usr/lib/python3.9/site-packages/xtesting/samples/features
             tags:
               - foo
       - case_name: seventh
@@ -97,5 +97,5 @@ tiers:
         run:
           name: ansible
           args:
-            private_data_dir: /usr/lib/python3.8/site-packages/xtesting/samples
+            private_data_dir: /usr/lib/python3.9/site-packages/xtesting/samples
             playbook: helloworld.yml
index acd0d31..d99a0e3 100644 (file)
@@ -3,12 +3,24 @@
 # pylint: disable=missing-docstring
 
 import os
+import sys
+
+import pkg_resources
 
 ENV_FILE = '/var/lib/xtesting/conf/env_file'
 
+XTESTING_PATHES = [
+    "~/.xtesting", "/etc/xtesting", os.path.join(sys.prefix + "/etc/xtesting")]
+
+TESTCASE_DESCRIPTION = 'testcases.yaml'
+TESTCASE_DESCRIPTION_DEFAULT = pkg_resources.resource_filename(
+    'xtesting', f'ci/{TESTCASE_DESCRIPTION}')
+
 RESULTS_DIR = '/var/lib/xtesting/results'
 LOG_PATH = os.path.join(RESULTS_DIR, 'xtesting.log')
 DEBUG_LOG_PATH = os.path.join(RESULTS_DIR, 'xtesting.debug.log')
 
-INI_PATH = 'ci/logging.ini'
-DEBUG_INI_PATH = 'ci/logging.debug.ini'
+INI_PATH_DEFAULT = pkg_resources.resource_filename(
+    'xtesting', 'ci/logging.ini')
+DEBUG_INI_PATH_DEFAULT = pkg_resources.resource_filename(
+    'xtesting', 'ci/logging.debug.ini')