aboutsummaryrefslogtreecommitdiffstats
path: root/functest/utils
diff options
context:
space:
mode:
Diffstat (limited to 'functest/utils')
-rw-r--r--functest/utils/config.py7
-rw-r--r--functest/utils/constants.py4
-rw-r--r--functest/utils/env.py63
-rw-r--r--functest/utils/functest_utils.py6
-rw-r--r--functest/utils/openstack_utils.py10
5 files changed, 48 insertions, 42 deletions
diff --git a/functest/utils/config.py b/functest/utils/config.py
index c569856b..61d8401c 100644
--- a/functest/utils/config.py
+++ b/functest/utils/config.py
@@ -2,12 +2,13 @@
# pylint: disable=missing-docstring
-import os
import pkg_resources
import yaml
import six
+from functest.utils import env
+
class Config(object):
def __init__(self):
@@ -37,7 +38,7 @@ class Config(object):
patch_file = yaml.safe_load(yfile)
for key in patch_file:
- if key in os.environ.get('DEPLOY_SCENARIO', ""):
+ if key in env.get('DEPLOY_SCENARIO'):
self.functest_yaml = dict(Config._merge_dicts(
self.functest_yaml, patch_file[key]))
@@ -64,7 +65,7 @@ class Config(object):
CONF = Config()
CONF.patch_file(pkg_resources.resource_filename(
'functest', 'ci/config_patch.yaml'))
-if os.getenv("POD_ARCH", None) and os.getenv("POD_ARCH", None) in ['aarch64']:
+if env.get("POD_ARCH") in ['aarch64']:
CONF.patch_file(pkg_resources.resource_filename(
'functest', 'ci/config_aarch64_patch.yaml'))
CONF.fill()
diff --git a/functest/utils/constants.py b/functest/utils/constants.py
index c19e0fc5..d8a1d54d 100644
--- a/functest/utils/constants.py
+++ b/functest/utils/constants.py
@@ -2,6 +2,7 @@
# pylint: disable=missing-docstring
+import pkg_resources
import six
from functest.utils import config
@@ -10,6 +11,9 @@ from functest.utils import env
class Constants(object): # pylint: disable=too-few-public-methods
+ CONFIG_FUNCTEST_YAML = pkg_resources.resource_filename(
+ 'functest', 'ci/config_functest.yaml')
+
def __init__(self):
for attr_n, attr_v in six.iteritems(config.CONF.__dict__):
setattr(self, attr_n, attr_v)
diff --git a/functest/utils/env.py b/functest/utils/env.py
index b626473a..0c0515ba 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()
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py
index e84a2b42..b31b392d 100644
--- a/functest/utils/functest_utils.py
+++ b/functest/utils/functest_utils.py
@@ -11,7 +11,6 @@
from __future__ import print_function
import logging
-import os
import re
import shutil
import subprocess
@@ -22,6 +21,7 @@ from six.moves import urllib
import yaml
from functest.utils import constants
+from functest.utils import env
LOGGER = logging.getLogger(__name__)
@@ -90,8 +90,8 @@ def get_ci_envvars():
Get the CI env variables
"""
ci_env_var = {
- "installer": os.environ.get('INSTALLER_TYPE'),
- "scenario": os.environ.get('DEPLOY_SCENARIO')}
+ "installer": env.get('INSTALLER_TYPE'),
+ "scenario": env.get('DEPLOY_SCENARIO')}
return ci_env_var
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py
index b779997c..98da48b8 100644
--- a/functest/utils/openstack_utils.py
+++ b/functest/utils/openstack_utils.py
@@ -22,7 +22,7 @@ from novaclient import client as novaclient
from keystoneclient import client as keystoneclient
from neutronclient.neutron import client as neutronclient
-from functest.utils.constants import CONST
+from functest.utils import env
import functest.utils.functest_utils as ft_utils
logger = logging.getLogger(__name__)
@@ -659,8 +659,8 @@ def get_private_net(neutron_client):
def get_external_net(neutron_client):
- if (hasattr(CONST, 'EXTERNAL_NETWORK')):
- return CONST.__getattribute__('EXTERNAL_NETWORK')
+ if (env.get('EXTERNAL_NETWORK')):
+ return env.get('EXTERNAL_NETWORK')
for network in neutron_client.list_networks()['networks']:
if network['router:external']:
return network['name']
@@ -668,9 +668,9 @@ def get_external_net(neutron_client):
def get_external_net_id(neutron_client):
- if (hasattr(CONST, 'EXTERNAL_NETWORK')):
+ if (env.get('EXTERNAL_NETWORK')):
networks = neutron_client.list_networks(
- name=CONST.__getattribute__('EXTERNAL_NETWORK'))
+ name=env.get('EXTERNAL_NETWORK'))
net_id = networks['networks'][0]['id']
return net_id
for network in neutron_client.list_networks()['networks']: