aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/ci/run_tests.py22
-rw-r--r--functest/tests/unit/ci/test_run_tests.py12
2 files changed, 16 insertions, 18 deletions
diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py
index 9edf13477..2122e7f31 100644
--- a/functest/ci/run_tests.py
+++ b/functest/ci/run_tests.py
@@ -29,7 +29,6 @@ import yaml
import functest.ci.tier_builder as tb
import functest.core.testcase as testcase
-from functest.utils.constants import CONST
# __name__ cannot be used here
LOGGER = logging.getLogger('functest.ci.run_tests')
@@ -37,6 +36,8 @@ LOGGER = logging.getLogger('functest.ci.run_tests')
CONFIG_FUNCTEST_PATH = pkg_resources.resource_filename(
'functest', 'ci/config_functest.yaml')
+ENV_FILE = "/home/opnfv/functest/conf/env_file"
+
class Result(enum.Enum):
"""The overall result in enumerated type"""
@@ -93,12 +94,12 @@ class Runner(object):
self.clean_flag = True
self.report_flag = False
self.tiers = tb.TierBuilder(
- CONST.__getattribute__('INSTALLER_TYPE'),
- CONST.__getattribute__('DEPLOY_SCENARIO'),
+ os.environ.get('INSTALLER_TYPE', None),
+ os.environ.get('DEPLOY_SCENARIO', None),
pkg_resources.resource_filename('functest', 'ci/testcases.yaml'))
@staticmethod
- def source_envfile(rc_file):
+ def source_envfile(rc_file=ENV_FILE):
"""Source the env file passed as arg"""
with open(rc_file, "r") as rcfd:
for line in rcfd:
@@ -111,7 +112,6 @@ class Runner(object):
key = re.sub(r'^["\' ]*|[ \'"]*$', '', var[0])
value = re.sub(r'^["\' ]*|[ \'"]*$', '', "".join(var[1:]))
os.environ[key] = value
- setattr(CONST, key, value)
@staticmethod
def get_dict_by_test(testname):
@@ -208,9 +208,9 @@ class Runner(object):
field_names=['tiers', 'order', 'CI Loop', 'description',
'testcases'])
for tier in self.tiers.get_tiers():
- if (tier.get_tests() and
- re.search(CONST.__getattribute__('CI_LOOP'),
- tier.get_ci_loop()) is not None):
+ ci_loop = os.environ.get('CI_LOOP', None)
+ if (tier.get_tests() and ci_loop and
+ re.search(ci_loop, tier.get_ci_loop()) is not None):
tiers_to_run.append(tier)
msg.add_row([tier.get_name(), tier.get_order(),
tier.get_ci_loop(),
@@ -230,7 +230,7 @@ class Runner(object):
try:
if 'test' in kwargs:
LOGGER.debug("Sourcing the credential file...")
- self.source_envfile(getattr(CONST, 'env_file'))
+ self.source_envfile()
LOGGER.debug("Test args: %s", kwargs['test'])
if self.tiers.get_tier(kwargs['test']):
@@ -248,7 +248,7 @@ class Runner(object):
LOGGER.error("Unknown test case or tier '%s', or not "
"supported by the given scenario '%s'.",
kwargs['test'],
- CONST.__getattribute__('DEPLOY_SCENARIO'))
+ os.environ.get('DEPLOY_SCENARIO', ""))
LOGGER.debug("Available tiers are:\n\n%s",
self.tiers)
return Result.EX_ERROR
@@ -271,7 +271,7 @@ class Runner(object):
field_names=['env var', 'value'])
for env_var in ['INSTALLER_TYPE', 'DEPLOY_SCENARIO', 'BUILD_TAG',
'CI_LOOP']:
- msg.add_row([env_var, CONST.__getattribute__(env_var)])
+ msg.add_row([env_var, os.environ.get(env_var, "")])
LOGGER.info("Deployment description:\n\n%s\n", msg)
msg = prettytable.PrettyTable(
header_style='upper', padding_width=5,
diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py
index 0b89ce271..aaa265c50 100644
--- a/functest/tests/unit/ci/test_run_tests.py
+++ b/functest/tests/unit/ci/test_run_tests.py
@@ -14,7 +14,6 @@ import os
import mock
from functest.ci import run_tests
-from functest.utils.constants import CONST
from functest.core.testcase import TestCase
@@ -177,7 +176,7 @@ class RunTestsTesting(unittest.TestCase):
@mock.patch('functest.ci.run_tests.Runner.run_tier')
@mock.patch('functest.ci.run_tests.Runner.summary')
def test_run_all_default(self, *mock_methods):
- CONST.__setattr__('CI_LOOP', 'test_ci_loop')
+ os.environ['CI_LOOP'] = 'test_ci_loop'
self.runner.run_all()
mock_methods[1].assert_not_called()
self.assertTrue(mock_methods[2].called)
@@ -185,7 +184,7 @@ class RunTestsTesting(unittest.TestCase):
@mock.patch('functest.ci.run_tests.LOGGER.info')
@mock.patch('functest.ci.run_tests.Runner.summary')
def test_run_all_missing_tier(self, *mock_methods):
- CONST.__setattr__('CI_LOOP', 'loop_re_not_available')
+ os.environ['CI_LOOP'] = 'loop_re_not_available'
self.runner.run_all()
self.assertTrue(mock_methods[1].called)
@@ -200,8 +199,7 @@ class RunTestsTesting(unittest.TestCase):
self.runner.tiers.configure_mock(**args)
self.assertEqual(self.runner.main(**kwargs),
run_tests.Result.EX_ERROR)
- mock_methods[1].assert_called_once_with(
- '/home/opnfv/functest/conf/env_file')
+ mock_methods[1].assert_called_once_with()
@mock.patch('functest.ci.run_tests.Runner.source_envfile')
@mock.patch('functest.ci.run_tests.Runner.run_test',
@@ -250,7 +248,7 @@ class RunTestsTesting(unittest.TestCase):
run_tests.Result.EX_OK)
args[0].assert_called_once_with(None)
args[1].assert_called_once_with()
- args[2].assert_called_once_with('/home/opnfv/functest/conf/env_file')
+ args[2].assert_called_once_with()
@mock.patch('functest.ci.run_tests.Runner.source_envfile')
def test_main_any_tier_test_ko(self, *args):
@@ -261,7 +259,7 @@ class RunTestsTesting(unittest.TestCase):
self.assertEqual(
self.runner.main(test='any', noclean=True, report=True),
run_tests.Result.EX_ERROR)
- args[0].assert_called_once_with('/home/opnfv/functest/conf/env_file')
+ args[0].assert_called_once_with()
if __name__ == "__main__":