aboutsummaryrefslogtreecommitdiffstats
path: root/functest/energy/energy.py
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-02-14 16:02:53 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2018-02-16 10:24:22 +0100
commitd589e4e5345ed82c68d9a011ac89f8cdbefe2ca3 (patch)
tree1ec221f1f95e6abaec9b1465e9e46b76f8777a27 /functest/energy/energy.py
parent98e2806cb674d206dea65647c0644dc5b2871b4b (diff)
Get properly env vars or their default values
It defines env.get() as an unique way to get Functest env vars or their default values. It can be considered as a wrapper above os.environ. It enforces backward compatibility via CONST which mustn't be used for that purpose. It should be noted that it also stops using CONST for getting OpenStack env vars. Change-Id: I333dc1afbc0123166a7eaff8b551370098efa341 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/energy/energy.py')
-rw-r--r--functest/energy/energy.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/functest/energy/energy.py b/functest/energy/energy.py
index c7da8f04..d5f6871d 100644
--- a/functest/energy/energy.py
+++ b/functest/energy/energy.py
@@ -12,13 +12,14 @@
import json
import logging
-import os
import traceback
from functools import wraps
import requests
from six.moves import urllib
+from functest.utils import env
+
def finish_session(current_scenario):
"""Finish a recording session."""
@@ -93,14 +94,15 @@ class EnergyRecorder(object):
# Singleton pattern for energy_recorder_api static member
# Load only if not previouly done
if EnergyRecorder.energy_recorder_api is None:
- 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"]
+ assert env.get('NODE_NAME')
+ assert env.get('ENERGY_RECORDER_API_URL')
+ environment = env.get('NODE_NAME')
+ energy_recorder_uri = env.get(
+ 'ENERGY_RECORDER_API_URL')
# Creds
- creds_usr = os.environ.get("ENERGY_RECORDER_API_USER", "")
- creds_pass = os.environ.get("ENERGY_RECORDER_API_PASSWORD", "")
+ creds_usr = env.get("ENERGY_RECORDER_API_USER")
+ creds_pass = env.get("ENERGY_RECORDER_API_PASSWORD")
uri_comp = "/recorders/environment/"
uri_comp += urllib.parse.quote_plus(environment)