From f15a4f277fb61b86074e949e2323b8f652969dd1 Mon Sep 17 00:00:00 2001 From: Morgan Richomme Date: Fri, 17 Mar 2017 14:41:06 +0100 Subject: Bug Fix: retrieve version from build tag in weekly jobs - fix regex issue - add unit test to cover weekly and dummy build tags - remove useless logs JIRA: FUNCTEST-765 Change-Id: I7a8d40b4662f4557cd080669da46fb1c32d2ad6d Signed-off-by: Morgan Richomme --- functest/tests/unit/utils/test_functest_utils.py | 13 ++++++++++++- functest/utils/functest_utils.py | 7 +++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py index 8bfdb5e4..e5bae62f 100644 --- a/functest/tests/unit/utils/test_functest_utils.py +++ b/functest/tests/unit/utils/test_functest_utils.py @@ -33,6 +33,7 @@ class FunctestUtilsTesting(unittest.TestCase): self.installer = 'test_installer' self.scenario = 'test_scenario' self.build_tag = 'jenkins-functest-fuel-opnfv-jump-2-daily-master-190' + self.build_tag_week = 'jenkins-functest-fuel-baremetal-weekly-master-8' self.version = 'master' self.node_name = 'test_node_name' self.project = 'test_project' @@ -152,10 +153,20 @@ class FunctestUtilsTesting(unittest.TestCase): self.scenario) @mock.patch('functest.utils.functest_utils.get_build_tag') - def test_get_version_default(self, mock_get_build_tag): + def test_get_version_daily_job(self, mock_get_build_tag): mock_get_build_tag.return_value = self.build_tag self.assertEqual(functest_utils.get_version(), self.version) + @mock.patch('functest.utils.functest_utils.get_build_tag') + def test_get_version_weekly_job(self, mock_get_build_tag): + mock_get_build_tag.return_value = self.build_tag_week + self.assertEqual(functest_utils.get_version(), self.version) + + @mock.patch('functest.utils.functest_utils.get_build_tag') + def test_get_version_with_dummy_build_tag(self, mock_get_build_tag): + mock_get_build_tag.return_value = 'whatever' + self.assertEqual(functest_utils.get_version(), 'unknown') + @mock.patch('functest.utils.functest_utils.get_build_tag') def test_get_version_unknown(self, mock_get_build_tag): mock_get_build_tag.return_value = "unknown_build_tag" diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index e5e755d7..9e13ffe9 100644 --- a/functest/utils/functest_utils.py +++ b/functest/utils/functest_utils.py @@ -111,12 +111,13 @@ def get_version(): # if launched through CI the build tag has the following format # jenkins------ # e.g. jenkins-functest-fuel-opnfv-jump-2-daily-master-190 + # jenkins-functest-fuel-baremetal-weekly-master-8 # use regex to match branch info - rule = "daily-(.+?)-[0-9]*" + rule = "(dai|week)ly-(.+?)-[0-9]*" build_tag = get_build_tag() m = re.search(rule, build_tag) if m: - return m.group(1) + return m.group(2) else: return "unknown" @@ -156,8 +157,6 @@ def get_db_url(): # 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 -- cgit 1.2.3-korg