f6e6e100f7a601055e28eb4faf1dbbb3f3525212
[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         'CI_DEBUG': 'false',
17         'DEPLOY_SCENARIO': 'os-nosdn-nofeature-noha',
18         'DEPLOY_TYPE': 'virt',
19         'INSTALLER_TYPE': None,
20         'INSTALLER_IP': None,
21         'BUILD_TAG': None,
22         'OS_ENDPOINT_TYPE': None,
23         'OS_AUTH_URL': None,
24         'CONFIG_FUNCTEST_YAML': pkg_resources.resource_filename(
25             'functest', 'ci/config_functest.yaml'),
26         'OS_INSECURE': '',
27         'OS_REGION_NAME': 'RegionOne'
28     }
29
30     def __init__(self):
31         for key, value in six.iteritems(os.environ):
32             setattr(self, key, value)
33         for key, value in six.iteritems(self.default_envs):
34             if key not in os.environ:
35                 setattr(self, key, value)
36         self._set_ci_run()
37         if 'CI_LOOP' not in os.environ:
38             self._set_ci_loop()
39
40     def _set_ci_run(self):
41         if getattr(self, "BUILD_TAG"):
42             setattr(self, "IS_CI_RUN", True)
43         else:
44             setattr(self, "IS_CI_RUN", False)
45
46     def _set_ci_loop(self):
47         if (getattr(self, "BUILD_TAG") and
48                 re.search("daily", getattr(self, "BUILD_TAG"))):
49             setattr(self, "CI_LOOP", "daily")
50         else:
51             setattr(self, "CI_LOOP", "weekly")
52
53
54 ENV = Environment()