From 67e9875d82d1ee2de3ed64d756092b1f5698c9c0 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Sat, 24 Feb 2018 11:41:33 +0100 Subject: Print env vars and env_file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It simply eases detecting wrong inputs [1]. [1] https://build.opnfv.org/ci/view/functest/job/functest-apex-baremetal-daily-master/796/console Change-Id: I0784c29265c69a6ba4a049226196bcdd70b0a572 Signed-off-by: Cédric Ollivier --- functest/ci/run_tests.py | 15 ++++----------- functest/tests/unit/ci/test_run_tests.py | 3 +-- functest/utils/env.py | 11 +++++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py index 0b980303..651a3851 100644 --- a/functest/ci/run_tests.py +++ b/functest/ci/run_tests.py @@ -101,7 +101,6 @@ class Runner(object): LOGGER.debug("No env file %s found", rc_file) return with open(rc_file, "r") as rcfd: - LOGGER.info("Sourcing env file %s", rc_file) for line in rcfd: var = (line.rstrip('"\n').replace('export ', '').split( "=") if re.search(r'(.*)=(.*)', line) else None) @@ -112,6 +111,8 @@ class Runner(object): key = re.sub(r'^["\' ]*|[ \'"]*$', '', var[0]) value = re.sub(r'^["\' ]*|[ \'"]*$', '', "".join(var[1:])) os.environ[key] = value + rcfd.seek(0, 0) + LOGGER.info("Sourcing env file %s\n\n%s", rc_file, rcfd.read()) @staticmethod def get_dict_by_test(testname): @@ -228,10 +229,9 @@ class Runner(object): if 'report' in kwargs: self.report_flag = kwargs['report'] try: + LOGGER.info("Deployment description:\n\n%s\n", env.string()) + self.source_envfile() if 'test' in kwargs: - LOGGER.debug("Sourcing the credential file...") - self.source_envfile() - LOGGER.debug("Test args: %s", kwargs['test']) if self.tiers.get_tier(kwargs['test']): self.run_tier(self.tiers.get_tier(kwargs['test'])) @@ -266,13 +266,6 @@ class Runner(object): def summary(self, tier=None): """To generate functest report showing the overall results""" - msg = prettytable.PrettyTable( - header_style='upper', padding_width=5, - field_names=['env var', 'value']) - for env_var in ['INSTALLER_TYPE', 'DEPLOY_SCENARIO', 'BUILD_TAG', - 'CI_LOOP']: - msg.add_row([env_var, env.get(env_var)]) - LOGGER.info("Deployment description:\n\n%s\n", msg) msg = prettytable.PrettyTable( header_style='upper', padding_width=5, field_names=['test case', 'project', 'tier', diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py index bc967743..b8dca20c 100644 --- a/functest/tests/unit/ci/test_run_tests.py +++ b/functest/tests/unit/ci/test_run_tests.py @@ -91,8 +91,7 @@ class RunTestsTesting(unittest.TestCase): pass envfile = 'rc_file' with mock.patch('six.moves.builtins.open', - mock.mock_open(read_data=msg), - create=True) as mock_method,\ + mock.mock_open(read_data=msg)) as mock_method,\ mock.patch('os.path.isfile', return_value=True): mock_method.return_value.__iter__ = lambda self: iter( self.readline, '') diff --git a/functest/utils/env.py b/functest/utils/env.py index ed09d9f0..5ad870ed 100644 --- a/functest/utils/env.py +++ b/functest/utils/env.py @@ -11,6 +11,8 @@ import os +import prettytable + INPUTS = { 'EXTERNAL_NETWORK': None, 'CI_LOOP': 'daily', @@ -31,3 +33,12 @@ def get(env_var): if env_var not in INPUTS.keys(): return os.environ.get(env_var, None) return os.environ.get(env_var, INPUTS[env_var]) + + +def string(): + msg = prettytable.PrettyTable( + header_style='upper', padding_width=5, + field_names=['env var', 'value']) + for env_var in INPUTS: + msg.add_row([env_var, get(env_var) if get(env_var) else '']) + return msg -- cgit 1.2.3-korg