summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-02-24 11:41:33 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2018-02-24 15:28:54 +0100
commit67e9875d82d1ee2de3ed64d756092b1f5698c9c0 (patch)
tree994a1c27c8347a975814eeaf4991d1a59e6e6947
parenta1b0f64bccea682e55ec5086aef979df57cf686f (diff)
Print env vars and env_file
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 <cedric.ollivier@orange.com>
-rw-r--r--functest/ci/run_tests.py15
-rw-r--r--functest/tests/unit/ci/test_run_tests.py3
-rw-r--r--functest/utils/env.py11
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']))
@@ -268,13 +268,6 @@ class Runner(object):
"""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',
'duration', 'result'])
tiers = [tier] if tier else self.tiers.get_tiers()
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