diff options
author | Morgan Richomme <morgan.richomme@orange.com> | 2017-03-16 07:29:04 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-03-16 07:29:04 +0000 |
commit | 661e542b39bbbf1c6f104a793631edb9cf3903e2 (patch) | |
tree | a34bf75e03ee586b22491677d23e847bf5a46449 | |
parent | c88fd9ac48589b4cb28a5ba5486adde1a21ae74c (diff) | |
parent | 0c194ede4dd9eb46b61af49e85527fcc368a8fca (diff) |
Merge "env variable support for test DB url"
-rw-r--r-- | functest/tests/unit/utils/test_functest_utils.py | 12 | ||||
-rw-r--r-- | functest/utils/functest_utils.py | 10 |
2 files changed, 20 insertions, 2 deletions
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py index bb8360119..8bfdb5e49 100644 --- a/functest/tests/unit/utils/test_functest_utils.py +++ b/functest/tests/unit/utils/test_functest_utils.py @@ -56,6 +56,7 @@ class FunctestUtilsTesting(unittest.TestCase): self.testcase_dict = {'name': 'testname', 'criteria': self.criteria} self.parameter = 'general.openstack.image_name' self.config_yaml = 'test_config_yaml-' + self.db_url_env = 'http://foo/testdb' self.file_yaml = {'general': {'openstack': {'image_name': 'test_image_name'}}} @@ -196,8 +197,17 @@ class FunctestUtilsTesting(unittest.TestCase): self.assertEqual(functest_utils.get_build_tag(), self.build_tag) + def test_get_db_url_env_var(self): + with mock.patch.dict(os.environ, + {'TEST_DB_URL': self.db_url_env, + 'CONFIG_FUNCTEST_YAML': + "./functest/ci/config_functest.yaml"}, + clear=True): + self.assertEqual(functest_utils.get_db_url(), + self.db_url_env) + @mock.patch('functest.utils.functest_utils.get_functest_config') - def test_get_db_url(self, mock_get_functest_config): + def test_get_db_url_default(self, mock_get_functest_config): mock_get_functest_config.return_value = self.db_url self.assertEqual(functest_utils.get_db_url(), self.db_url) mock_get_functest_config.assert_called_once_with('results.test_db_url') diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index dbed811a7..e5e755d7f 100644 --- a/functest/utils/functest_utils.py +++ b/functest/utils/functest_utils.py @@ -151,7 +151,15 @@ def get_db_url(): """ Returns DB URL """ - return get_functest_config('results.test_db_url') + # TODO use CONST mechanism + try: + # if TEST_DB_URL declared in env variable, use it! + db_url = os.environ['TEST_DB_URL'] + except KeyError: + logger.info("DB URL not declared as env variable," + "use local configuration") + db_url = get_functest_config('results.test_db_url') + return db_url def logger_test_results(project, case_name, status, details): |