diff options
Diffstat (limited to 'functest/energy/energy.py')
-rw-r--r-- | functest/energy/energy.py | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/functest/energy/energy.py b/functest/energy/energy.py index 2835e05c..c7da8f04 100644 --- a/functest/energy/energy.py +++ b/functest/energy/energy.py @@ -12,14 +12,13 @@ import json import logging +import os +import traceback from functools import wraps import requests from six.moves import urllib -from functest.utils.constants import CONST -import functest.utils.functest_utils as ft_utils - def finish_session(current_scenario): """Finish a recording session.""" @@ -94,23 +93,18 @@ 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 = CONST.__getattribute__('NODE_NAME') + assert os.environ['NODE_NAME'] + assert os.environ["ENERGY_RECORDER_API_URL"] + environment = os.environ['NODE_NAME'] + energy_recorder_uri = os.environ["ENERGY_RECORDER_API_URL"] - # API URL - energy_recorder_uri = ft_utils.get_functest_config( - "energy_recorder.api_url") - assert energy_recorder_uri - assert environment + # Creds + creds_usr = os.environ.get("ENERGY_RECORDER_API_USER", "") + creds_pass = os.environ.get("ENERGY_RECORDER_API_PASSWORD", "") uri_comp = "/recorders/environment/" uri_comp += urllib.parse.quote_plus(environment) - # Creds - creds_usr = ft_utils.get_functest_config( - "energy_recorder.api_user") - creds_pass = ft_utils.get_functest_config( - "energy_recorder.api_password") - if creds_usr != "" and creds_pass != "": energy_recorder_api_auth = (creds_usr, creds_pass) else: @@ -184,8 +178,9 @@ class EnergyRecorder(object): except Exception: # pylint: disable=broad-except # Default exception handler to ensure that method # is safe for caller - EnergyRecorder.logger.exception( - "Error while submitting scenarion to energy recorder API" + EnergyRecorder.logger.info( + "Error while submitting scenarion to energy recorder API\n%s", + traceback.format_exc() ) return_status = False return return_status @@ -210,8 +205,9 @@ class EnergyRecorder(object): except Exception: # pylint: disable=broad-except # Default exception handler to ensure that method # is safe for caller - EnergyRecorder.logger.exception( - "Error while starting energy recorder API" + EnergyRecorder.logger.info( + "Error while starting energy recorder API\n%s", + traceback.format_exc() ) return_status = False return return_status @@ -246,8 +242,9 @@ class EnergyRecorder(object): except Exception: # pylint: disable=broad-except # Default exception handler to ensure that method # is safe for caller - EnergyRecorder.logger.exception( - "Error while stoping energy recorder API" + EnergyRecorder.logger.info( + "Error while stoping energy recorder API\n%s", + traceback.format_exc() ) return_status = False return return_status @@ -288,8 +285,9 @@ class EnergyRecorder(object): except Exception: # pylint: disable=broad-except # Default exception handler to ensure that method # is safe for caller - EnergyRecorder.logger.exception( - "Error while setting step on energy recorder API" + EnergyRecorder.logger.info( + "Error while setting step on energy recorder API\n%s", + traceback.format_exc() ) return_status = False return return_status @@ -328,8 +326,9 @@ class EnergyRecorder(object): except Exception: # pylint: disable=broad-except # Default exception handler to ensure that method # is safe for caller - EnergyRecorder.logger.exception( + EnergyRecorder.logger.info( "Error while getting current scenario from energy recorder API" + "\n%s", traceback.format_exc() ) return_value = None return return_value |