aboutsummaryrefslogtreecommitdiffstats
path: root/functest/utils/env.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/utils/env.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/utils/env.py')
-rw-r--r--functest/utils/env.py63
1 files changed, 32 insertions, 31 deletions
diff --git a/functest/utils/env.py b/functest/utils/env.py
index b626473a9..0c0515ba1 100644
--- a/functest/utils/env.py
+++ b/functest/utils/env.py
@@ -1,45 +1,46 @@
#!/usr/bin/env python
+# Copyright (c) 2018 Orange and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
# pylint: disable=missing-docstring
import os
-import re
-import pkg_resources
import six
+INPUTS = {
+ 'EXTERNAL_NETWORK': None,
+ 'CI_LOOP': 'daily',
+ 'DEPLOY_SCENARIO': 'os-nosdn-nofeature-noha',
+ 'INSTALLER_TYPE': None,
+ 'SDN_CONTROLLER_IP': None,
+ 'BUILD_TAG': None,
+ 'NODE_NAME': None,
+ 'POD_ARCH': None,
+ 'TEST_DB_URL': 'http://testresults.opnfv.org/test/api/v1/results',
+ 'ENERGY_RECORDER_API_URL': 'http://energy.opnfv.fr/resources',
+ 'ENERGY_RECORDER_API_USER': '',
+ 'ENERGY_RECORDER_API_PASSWORD': ''
+}
-class Environment(object): # pylint: disable=too-few-public-methods
- default_envs = {
- 'NODE_NAME': 'unknown_pod',
- 'DEPLOY_SCENARIO': 'os-nosdn-nofeature-noha',
- 'DEPLOY_TYPE': 'virt',
- 'INSTALLER_TYPE': None,
- 'BUILD_TAG': None,
- 'OS_ENDPOINT_TYPE': None,
- 'OS_AUTH_URL': None,
- 'CONFIG_FUNCTEST_YAML': pkg_resources.resource_filename(
- 'functest', 'ci/config_functest.yaml'),
- 'OS_INSECURE': '',
- 'OS_REGION_NAME': 'RegionOne'
- }
+def get(env_var):
+ if env_var not in INPUTS.keys():
+ return os.environ.get(env_var, None)
+ return os.environ.get(env_var, INPUTS[env_var])
- def __init__(self):
- for key, value in six.iteritems(os.environ):
- setattr(self, key, value)
- for key, value in six.iteritems(self.default_envs):
- if key not in os.environ:
- setattr(self, key, value)
- if 'CI_LOOP' not in os.environ:
- self._set_ci_loop()
-
- def _set_ci_loop(self):
- if (getattr(self, "BUILD_TAG") and
- re.search("daily", getattr(self, "BUILD_TAG"))):
- setattr(self, "CI_LOOP", "daily")
- else:
- setattr(self, "CI_LOOP", "weekly")
+class Environment(object): # pylint: disable=too-few-public-methods
+
+ # Backward compatibilty (waiting for SDNVPN and SFC)
+ def __init__(self):
+ for key, _ in six.iteritems(INPUTS):
+ setattr(self, key, get(key))
+# Backward compatibilty (waiting for SDNVPN and SFC)
ENV = Environment()