b626473a9db5b9216eb7c15c6611b5683b1821c3
[functest.git] / functest / utils / env.py
1 #!/usr/bin/env python
2
3 # pylint: disable=missing-docstring
4
5 import os
6 import re
7
8 import pkg_resources
9 import six
10
11
12 class Environment(object):  # pylint: disable=too-few-public-methods
13
14     default_envs = {
15         'NODE_NAME': 'unknown_pod',
16         'DEPLOY_SCENARIO': 'os-nosdn-nofeature-noha',
17         'DEPLOY_TYPE': 'virt',
18         'INSTALLER_TYPE': None,
19         'BUILD_TAG': None,
20         'OS_ENDPOINT_TYPE': None,
21         'OS_AUTH_URL': None,
22         'CONFIG_FUNCTEST_YAML': pkg_resources.resource_filename(
23             'functest', 'ci/config_functest.yaml'),
24         'OS_INSECURE': '',
25         'OS_REGION_NAME': 'RegionOne'
26     }
27
28     def __init__(self):
29         for key, value in six.iteritems(os.environ):
30             setattr(self, key, value)
31         for key, value in six.iteritems(self.default_envs):
32             if key not in os.environ:
33                 setattr(self, key, value)
34         if 'CI_LOOP' not in os.environ:
35             self._set_ci_loop()
36
37     def _set_ci_loop(self):
38         if (getattr(self, "BUILD_TAG") and
39                 re.search("daily", getattr(self, "BUILD_TAG"))):
40             setattr(self, "CI_LOOP", "daily")
41         else:
42             setattr(self, "CI_LOOP", "weekly")
43
44
45 ENV = Environment()