summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/energy/energy.py3
-rw-r--r--functest/tests/unit/energy/test_functest_energy.py36
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py26
-rw-r--r--functest/utils/functest_utils.py15
4 files changed, 18 insertions, 62 deletions
diff --git a/functest/energy/energy.py b/functest/energy/energy.py
index 580bc6b09..ec03e1801 100644
--- a/functest/energy/energy.py
+++ b/functest/energy/energy.py
@@ -17,6 +17,7 @@ import urllib
from functools import wraps
import requests
+from functest.utils.constants import CONST
import functest.utils.functest_utils as ft_utils
@@ -90,7 +91,7 @@ class EnergyRecorder(object):
# Singleton pattern for energy_recorder_api static member
# Load only if not previouly done
if EnergyRecorder.energy_recorder_api is None:
- environment = ft_utils.get_pod_name()
+ environment = CONST.__getattribute__('NODE_NAME')
# API URL
energy_recorder_uri = ft_utils.get_functest_config(
diff --git a/functest/tests/unit/energy/test_functest_energy.py b/functest/tests/unit/energy/test_functest_energy.py
index a576e2c3f..5e2254ad1 100644
--- a/functest/tests/unit/energy/test_functest_energy.py
+++ b/functest/tests/unit/energy/test_functest_energy.py
@@ -17,7 +17,7 @@ import mock
from functest.energy.energy import EnergyRecorder
import functest.energy.energy as energy
-
+from functest.utils.constants import CONST
CASE_NAME = "UNIT_TEST_CASE"
STEP_NAME = "UNIT_TEST_STEP"
@@ -237,16 +237,14 @@ class EnergyRecorderTest(unittest.TestCase):
return_value={"scenario": PREVIOUS_SCENARIO,
"step": PREVIOUS_STEP})
@mock.patch("functest.energy.energy.EnergyRecorder")
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch("functest.utils.functest_utils.get_functest_config",
side_effect=config_loader_mock)
def test_decorators_with_previous(self,
loader_mock=None,
- pod_mock=None,
recorder_mock=None,
cur_scenario_mock=None):
"""Test energy module decorators."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
self.__decorated_method()
calls = [mock.call.start(self.case_name),
mock.call.submit_scenario(PREVIOUS_SCENARIO,
@@ -274,13 +272,11 @@ class EnergyRecorderTest(unittest.TestCase):
@mock.patch("functest.utils.functest_utils.get_functest_config",
side_effect=config_loader_mock)
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch("functest.energy.energy.requests.get",
return_value=API_OK)
- def test_load_config(self, loader_mock=None, pod_mock=None,
- get_mock=None):
+ def test_load_config(self, loader_mock=None, get_mock=None):
"""Test load config."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
@@ -295,13 +291,11 @@ class EnergyRecorderTest(unittest.TestCase):
@mock.patch("functest.utils.functest_utils.get_functest_config",
side_effect=config_loader_mock_no_creds)
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch("functest.energy.energy.requests.get",
return_value=API_OK)
- def test_load_config_no_creds(self, loader_mock=None, pod_mock=None,
- get_mock=None):
+ def test_load_config_no_creds(self, loader_mock=None, get_mock=None):
"""Test load config without creds."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
self.assertEquals(EnergyRecorder.energy_recorder_api["auth"], None)
@@ -312,13 +306,11 @@ class EnergyRecorderTest(unittest.TestCase):
@mock.patch("functest.utils.functest_utils.get_functest_config",
return_value=None)
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch("functest.energy.energy.requests.get",
return_value=API_OK)
- def test_load_config_ex(self, loader_mock=None, pod_mock=None,
- get_mock=None):
+ def test_load_config_ex(self, loader_mock=None, get_mock=None):
"""Test load config with exception."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
with self.assertRaises(AssertionError):
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
@@ -326,13 +318,11 @@ class EnergyRecorderTest(unittest.TestCase):
@mock.patch("functest.utils.functest_utils.get_functest_config",
side_effect=config_loader_mock)
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch("functest.energy.energy.requests.get",
return_value=API_KO)
- def test_load_config_api_ko(self, loader_mock=None, pod_mock=None,
- get_mock=None):
+ def test_load_config_api_ko(self, loader_mock=None, get_mock=None):
"""Test load config with API unavailable."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
EnergyRecorder.energy_recorder_api = None
EnergyRecorder.load_config()
self.assertEquals(EnergyRecorder.energy_recorder_api["available"],
@@ -340,13 +330,11 @@ class EnergyRecorderTest(unittest.TestCase):
@mock.patch("functest.utils.functest_utils.get_functest_config",
return_value=None)
- @mock.patch("functest.utils.functest_utils.get_pod_name",
- return_value="MOCK_POD")
@mock.patch('functest.energy.energy.requests.get',
return_value=RECORDER_OK)
- def test_get_current_scenario(self, loader_mock=None,
- pod_mock=None, get_mock=None):
+ def test_get_current_scenario(self, loader_mock=None, get_mock=None):
"""Test get_current_scenario."""
+ CONST.__setattr__('NODE_NAME', 'MOCK_POD')
self.test_load_config()
scenario = EnergyRecorder.get_current_scenario()
self.assertTrue(scenario is not None)
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index b4cc5b73b..cd3693c71 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -150,32 +150,12 @@ class FunctestUtilsTesting(unittest.TestCase):
self.assertEqual(functest_utils.get_version(), "unknown")
@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_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,
- {'NODE_NAME': 'test_node_name'},
- clear=True):
- self.assertEqual(functest_utils.get_pod_name(),
- self.node_name)
-
- @mock.patch('functest.utils.functest_utils.logger.info')
def test_logger_test_results(self, mock_logger_info):
CONST.__setattr__('results_test_db_url', self.db_url)
CONST.__setattr__('BUILD_TAG', self.build_tag)
- with mock.patch('functest.utils.functest_utils.get_pod_name',
- return_value=self.node_name), \
- mock.patch('functest.utils.functest_utils.get_scenario',
- return_value=self.scenario), \
+ CONST.__setattr__('NODE_NAME', self.node_name)
+ with mock.patch('functest.utils.functest_utils.get_scenario',
+ return_value=self.scenario), \
mock.patch('functest.utils.functest_utils.get_version',
return_value=self.version):
functest_utils.logger_test_results(self.project, self.case_name,
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py
index bf68e43a3..ce9a205c0 100644
--- a/functest/utils/functest_utils.py
+++ b/functest/utils/functest_utils.py
@@ -117,24 +117,11 @@ def get_version():
return "unknown"
-def get_pod_name():
- """
- Get PoD Name from env variable NODE_NAME
- """
- try:
- return os.environ['NODE_NAME']
- except KeyError:
- logger.info(
- "Unable to retrieve the POD name from environment. " +
- "Using pod name 'unknown-pod'")
- return "unknown-pod"
-
-
def logger_test_results(project, case_name, status, details):
"""
Format test case results for the logger
"""
- pod_name = get_pod_name()
+ pod_name = CONST.__getattribute__('NODE_NAME')
scenario = get_scenario()
version = get_version()
build_tag = CONST.__getattribute__('BUILD_TAG')