110164bee94cca8ecb559fb88bd972dd3ed6b032
[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         'INSTALLER_IP': None,
20         'BUILD_TAG': None,
21         'OS_ENDPOINT_TYPE': None,
22         'OS_AUTH_URL': None,
23         'CONFIG_FUNCTEST_YAML': pkg_resources.resource_filename(
24             'functest', 'ci/config_functest.yaml'),
25         'OS_INSECURE': '',
26         'OS_REGION_NAME': 'RegionOne'
27     }
28
29     def __init__(self):
30         for key, value in six.iteritems(os.environ):
31             setattr(self, key, value)
32         for key, value in six.iteritems(self.default_envs):
33             if key not in os.environ:
34                 setattr(self, key, value)
35         if 'CI_LOOP' not in os.environ:
36             self._set_ci_loop()
37
38     def _set_ci_loop(self):
39         if (getattr(self, "BUILD_TAG") and
40                 re.search("daily", getattr(self, "BUILD_TAG"))):
41             setattr(self, "CI_LOOP", "daily")
42         else:
43             setattr(self, "CI_LOOP", "weekly")
44
45
46 ENV = Environment()