Change log level when pod, scenario or build_tag cannot be retrieved 09/28109/1
authorMorgan Richomme <morgan.richomme@orange.com>
Mon, 6 Feb 2017 09:58:40 +0000 (10:58 +0100)
committerMorgan Richomme <morgan.richomme@orange.com>
Mon, 6 Feb 2017 09:58:40 +0000 (10:58 +0100)
when using Functest out of CI, such env variables may not be set
This shall not result in Error messages

JIRA: FUNCTEST-716

Change-Id: I86d2023145480dfa9c8d593ea274acbd9e431ef7
Signed-off-by: Morgan Richomme <morgan.richomme@orange.com>
functest/tests/unit/utils/test_functest_utils.py
functest/utils/functest_utils.py

index ce9086a..bb83601 100644 (file)
@@ -131,15 +131,17 @@ class FunctestUtilsTesting(unittest.TestCase):
             self.assertEqual(functest_utils.get_installer_type(),
                              self.installer)
 
-    @mock.patch('functest.utils.functest_utils.logger.error')
-    def test_get_scenario_failed(self, mock_logger_error):
+    @mock.patch('functest.utils.functest_utils.logger.info')
+    def test_get_scenario_failed(self, mock_logger_info):
         with mock.patch.dict(os.environ,
                              {},
                              clear=True):
             self.assertEqual(functest_utils.get_scenario(),
-                             "Unknown_scenario")
-            mock_logger_error.assert_called_once_with("Impossible to retrieve"
-                                                      " the scenario")
+                             "os-nosdn-nofeature-noha")
+            mock_logger_info.assert_called_once_with("Impossible to retrieve "
+                                                     "the scenario.Use "
+                                                     "default "
+                                                     "os-nosdn-nofeature-noha")
 
     def test_get_scenario_default(self):
         with mock.patch.dict(os.environ,
@@ -158,17 +160,17 @@ class FunctestUtilsTesting(unittest.TestCase):
         mock_get_build_tag.return_value = "unknown_build_tag"
         self.assertEqual(functest_utils.get_version(), "unknown")
 
-    @mock.patch('functest.utils.functest_utils.logger.error')
-    def test_get_pod_name_failed(self, mock_logger_error):
+    @mock.patch('functest.utils.functest_utils.logger.info')
+    def test_get_pod_name_failed(self, mock_logger_info):
         with mock.patch.dict(os.environ,
                              {},
                              clear=True):
             self.assertEqual(functest_utils.get_pod_name(),
                              "unknown-pod")
-            mock_logger_error.assert_called_once_with("Unable to retrieve "
-                                                      "the POD name from "
-                                                      "environment. Using "
-                                                      "pod name 'unknown-pod'")
+            mock_logger_info.assert_called_once_with("Unable to retrieve "
+                                                     "the POD name from "
+                                                     "environment. Using "
+                                                     "pod name 'unknown-pod'")
 
     def test_get_pod_name_default(self):
         with mock.patch.dict(os.environ,
@@ -177,15 +179,15 @@ class FunctestUtilsTesting(unittest.TestCase):
             self.assertEqual(functest_utils.get_pod_name(),
                              self.node_name)
 
-    @mock.patch('functest.utils.functest_utils.logger.error')
-    def test_get_build_tag_failed(self, mock_logger_error):
+    @mock.patch('functest.utils.functest_utils.logger.info')
+    def test_get_build_tag_failed(self, mock_logger_info):
         with mock.patch.dict(os.environ,
                              {},
                              clear=True):
             self.assertEqual(functest_utils.get_build_tag(),
-                             "unknown_build_tag")
-            mock_logger_error.assert_called_once_with("Impossible to retrieve"
-                                                      " the build tag")
+                             "none")
+            mock_logger_info.assert_called_once_with("Impossible to retrieve"
+                                                     " the build tag")
 
     def test_get_build_tag_default(self):
         with mock.patch.dict(os.environ,
index 2bf87a0..0405546 100644 (file)
@@ -96,8 +96,9 @@ def get_scenario():
     try:
         scenario = os.environ['DEPLOY_SCENARIO']
     except KeyError:
-        logger.error("Impossible to retrieve the scenario")
-        scenario = "Unknown_scenario"
+        logger.info("Impossible to retrieve the scenario."
+                    "Use default os-nosdn-nofeature-noha")
+        scenario = "os-nosdn-nofeature-noha"
 
     return scenario
 
@@ -128,7 +129,7 @@ def get_pod_name():
     try:
         return os.environ['NODE_NAME']
     except KeyError:
-        logger.error(
+        logger.info(
             "Unable to retrieve the POD name from environment. " +
             "Using pod name 'unknown-pod'")
         return "unknown-pod"
@@ -141,8 +142,8 @@ def get_build_tag():
     try:
         build_tag = os.environ['BUILD_TAG']
     except KeyError:
-        logger.error("Impossible to retrieve the build tag")
-        build_tag = "unknown_build_tag"
+        logger.info("Impossible to retrieve the build tag")
+        build_tag = "none"
 
     return build_tag