blob: c6b5b741939cf71c76ad4dfe874d442a06912940 [file] [log] [blame]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +03001# Copyright 2016 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14import copy
15import os
16import pkg_resources
17
18from oslo_config import cfg
19from oslo_config import generator
20
21from tcp_tests.helpers import ext
22from tcp_tests.helpers import oslo_cfg_types as ct
23from tcp_tests import settings
24
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020025print ("\n" + "-" * 10 + " Initialize oslo.config variables with defaults"
26 " from environment" + "-" * 10)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030027
28_default_conf = pkg_resources.resource_filename(
Dennis Dmitrievab83ea42017-05-12 16:52:45 +030029 __name__, 'templates/{0}/underlay.yaml'.format(settings.LAB_CONFIG_NAME))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020030
31_default_salt_steps = pkg_resources.resource_filename(
Dennis Dmitrievab83ea42017-05-12 16:52:45 +030032 __name__, 'templates/{0}/salt.yaml'.format(settings.LAB_CONFIG_NAME))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020033_default_common_services_steps = pkg_resources.resource_filename(
34 __name__,
Dennis Dmitrievab83ea42017-05-12 16:52:45 +030035 'templates/{0}/common-services.yaml'.format(
Dennis Dmitriev2a13a132016-11-04 00:56:23 +020036 settings.LAB_CONFIG_NAME))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020037_default_openstack_steps = pkg_resources.resource_filename(
Dennis Dmitrievab83ea42017-05-12 16:52:45 +030038 __name__, 'templates/{0}/openstack.yaml'.format(
Dennis Dmitriev2a13a132016-11-04 00:56:23 +020039 settings.LAB_CONFIG_NAME))
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020040_default_opencontrail_prepare_tests_steps_path = pkg_resources.resource_filename(
Dennis Dmitrievab83ea42017-05-12 16:52:45 +030041 __name__, 'templates/{0}/opencontrail.yaml'.format(
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020042 settings.LAB_CONFIG_NAME))
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030043_default_sl_prepare_tests_steps_path = pkg_resources.resource_filename(
44 __name__, 'templates/{0}/sl.yaml'.format(
45 settings.LAB_CONFIG_NAME))
vrovachevbc2f5ce2017-05-22 19:37:24 +040046_default_virtlet_prepare_tests_steps_path = pkg_resources.resource_filename(
47 __name__, 'templates/{0}/virtlet.yaml'.format(
48 settings.LAB_CONFIG_NAME))
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030049
50hardware_opts = [
51 ct.Cfg('manager', ct.String(),
52 help="Hardware manager name", default="devops"),
53 ct.Cfg('conf_path', ct.String(),
54 help="Hardware config file", default=_default_conf),
55 ct.Cfg('current_snapshot', ct.String(),
56 help="Latest environment status name",
57 default=ext.SNAPSHOT.hardware),
58]
59
60
61underlay_opts = [
62 ct.Cfg('ssh', ct.JSONList(),
63 help="""SSH Settings for Underlay: [{
64 'node_name': node1,
Dennis Dmitriev23e5d192016-10-31 11:27:10 +020065 'roles': ['salt-master', 'salt-minion', ],
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030066 'host': hostname,
67 'login': login,
68 'password': password,
69 'address_pool': (optional),
70 'port': (optional),
71 'keys': [(optional)],
72 }, ...]""", default=[]),
73 ct.Cfg('roles', ct.JSONList(),
74 help="Node roles managed by underlay in the environment",
Dennis Dmitriev53d3b772016-10-18 14:31:58 +030075 default=[ext.UNDERLAY_NODE_ROLES.salt_master,
76 ext.UNDERLAY_NODE_ROLES.salt_minion, ]),
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +030077 ct.Cfg('bootstrap_timeout', ct.Integer(),
78 help="Timeout of waiting SSH for nodes with specified roles",
79 default=480),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030080 ct.Cfg('nameservers', ct.JSONList(),
81 help="IP addresses of DNS servers",
82 default=[]),
83 ct.Cfg('upstream_dns_servers', ct.JSONList(),
84 help="IP addresses of upstream DNS servers (dnsmasq)",
85 default=[]),
86 ct.Cfg('lvm', ct.JSONDict(),
87 help="LVM settings for Underlay", default={}),
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030088 ct.Cfg('address_pools', ct.JSONDict(),
89 help="""Address pools (dynamically) allocated for the environment.
90 May be used to determine CIDR for a specific network from
91 tests or during the deployment process.
92 {'pool_name1': '<cidr>', 'pool_name2': '<cidr>', ...}""",
93 default={}),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030094]
95
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020096
97salt_deploy_opts = [
98 ct.Cfg('salt_steps_path', ct.String(),
99 help="Path to YAML with steps to deploy salt",
100 default=_default_salt_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300101]
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200102salt_opts = [
103 ct.Cfg('salt_master_host', ct.IPAddress(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300104 help="", default='0.0.0.0'),
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300105 ct.Cfg('salt_master_port', ct.String(),
106 help="", default='6969'),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300107]
108
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200109common_services_deploy_opts = [
110 ct.Cfg('common_services_steps_path', ct.String(),
111 help="Path to YAML with steps to deploy common services",
112 default=_default_common_services_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300113]
114
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200115common_services_opts = [
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200116 ct.Cfg('common_services_installed', ct.Boolean(),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200117 help="", default=False),
118]
119
120openstack_deploy_opts = [
121 ct.Cfg('openstack_steps_path', ct.String(),
122 help="Path to YAML with steps to deploy openstack",
123 default=_default_openstack_steps),
124]
125openstack_opts = [
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200126 ct.Cfg('openstack_installed', ct.Boolean(),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200127 help="", default=False),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200128 ct.Cfg('openstack_keystone_endpoint', ct.String(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300129 help="", default=''),
130]
131
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200132opencontrail_opts = [
133 ct.Cfg('opencontrail_tags', ct.String(),
134 help="", default=''),
135 ct.Cfg('opencontrail_features', ct.String(),
136 help="", default=''),
137 ct.Cfg('opencontrail_prepare_tests_steps_path', ct.String(),
138 help="Path to YAML with steps to prepare contrail-tests",
139 default=_default_opencontrail_prepare_tests_steps_path),
140]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300141
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300142sl_deploy_opts = [
143 ct.Cfg('sl_steps_path', ct.String(),
144 help="Path to YAML with steps to deploy sl",
145 default=_default_sl_prepare_tests_steps_path),
146]
147sl_opts = [
148 ct.Cfg('sl_installed', ct.Boolean(),
149 help="", default=False),
150]
151
vrovachevbc2f5ce2017-05-22 19:37:24 +0400152virtlet_deploy_opts = [
153 ct.Cfg('virtlet_steps_path', ct.String(),
154 help="Path to YAML with steps to deploy virtlet",
155 default=_default_virtlet_prepare_tests_steps_path)
156]
157
158virtlet_opts = [
159 ct.Cfg('virtlet_installed', ct.Boolean(),
160 help="", default=False),
161]
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300162
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300163_group_opts = [
164 ('hardware', hardware_opts),
165 ('underlay', underlay_opts),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200166 ('salt_deploy', salt_deploy_opts),
167 ('salt', salt_opts),
168 ('common_services_deploy', common_services_deploy_opts),
169 ('common_services', common_services_opts),
170 ('openstack_deploy', openstack_deploy_opts),
171 ('openstack', openstack_opts),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200172 ('opencontrail', opencontrail_opts),
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300173 ('stack_light', sl_opts),
174 ('sl_deploy', sl_deploy_opts),
vrovachevbc2f5ce2017-05-22 19:37:24 +0400175 ('virtlet_deploy', virtlet_deploy_opts),
176 ('virtlet', virtlet_opts),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300177]
178
179
180def register_opts(config):
181 config.register_group(cfg.OptGroup(name='hardware',
182 title="Hardware settings", help=""))
183 config.register_opts(group='hardware', opts=hardware_opts)
184
185 config.register_group(cfg.OptGroup(name='underlay',
186 title="Underlay configuration", help=""))
187 config.register_opts(group='underlay', opts=underlay_opts)
188
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200189 config.register_group(cfg.OptGroup(name='salt_deploy',
190 title="salt deploy configuration", help=""))
191 config.register_opts(group='salt_deploy', opts=salt_deploy_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300192
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200193 config.register_group(cfg.OptGroup(name='salt',
194 title="salt config and credentials", help=""))
195 config.register_opts(group='salt', opts=salt_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300196
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200197 config.register_group(cfg.OptGroup(name='common_services',
198 title="Common services for Openstack", help=""))
199 config.register_opts(group='common_services', opts=common_services_opts)
200
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300201 config.register_group(
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200202 cfg.OptGroup(name='common_services_deploy',
203 title="Common services for Openstack deploy config",
204 help=""))
205 config.register_opts(group='common_services_deploy',
206 opts=common_services_deploy_opts)
207
208 config.register_group(cfg.OptGroup(name='openstack',
209 title="Openstack config and credentials", help=""))
210 config.register_opts(group='openstack', opts=openstack_opts)
211
212 config.register_group(
213 cfg.OptGroup(name='openstack_deploy',
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300214 title="Openstack deploy config and credentials",
215 help=""))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200216 config.register_opts(group='openstack_deploy', opts=openstack_deploy_opts)
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200217
218 config.register_group(cfg.OptGroup(name='opencontrail',
219 title="Options for Juniper contrail-tests", help=""))
220 config.register_opts(group='opencontrail', opts=opencontrail_opts)
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300221 config.register_group(cfg.OptGroup(name='stack_light',
222 title="StackLight config and credentials", help=""))
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300223 config.register_opts(group='stack_light', opts=sl_opts)
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300224 config.register_group(
225 cfg.OptGroup(name='sl_deploy',
226 title="SL deploy config and credentials",
227 help=""))
228 config.register_opts(group='sl_deploy', opts=sl_deploy_opts)
vrovachevbc2f5ce2017-05-22 19:37:24 +0400229 config.register_group(cfg.OptGroup(name='virtlet_deploy',
230 title='Virtlet deploy config', help=""))
231 config.register_opts(group='virtlet_deploy', opts=virtlet_deploy_opts)
232 config.register_group(cfg.OptGroup(name='virtlet',
233 title='Virtlet config', help=""))
234 config.register_opts(group='virtlet', opts=virtlet_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300235 return config
236
237
238def load_config(config_files):
239 config = cfg.CONF
240 register_opts(config)
241 config(args=[], default_config_files=config_files)
242 return config
243
244
245def reload_snapshot_config(config, test_config_path):
246 """Reset config to the state from test_config file"""
247 config(args=[], default_config_files=[test_config_path])
248 return config
249
250
251def list_opts():
252 """Return a list of oslo.config options available in the tcp_tests.
253 """
254 return [(group, copy.deepcopy(opts)) for group, opts in _group_opts]
255
256
257def list_current_opts(config):
258 """Return a list of oslo.config options available in the tcp_tests.
259 """
260 result_opts = []
261 for group, opts in _group_opts:
262 current_opts = copy.deepcopy(opts)
263 for opt in current_opts:
264 if hasattr(config, group):
265 if hasattr(config[group], opt.name):
266 opt.default = getattr(config[group], opt.name)
267 result_opts.append((group, current_opts))
268 return result_opts
269
270
271def save_config(config, snapshot_name, env_name=None):
272 if env_name is None:
273 env_name = 'config'
274 test_config_path = os.path.join(
275 settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))
276
277 with open(test_config_path, 'w') as output_file:
278 formatter = generator._OptFormatter(output_file=output_file)
279 for group, opts in list_current_opts(config):
280 formatter.format_group(group)
281 for opt in opts:
282 formatter.format(opt, group, minimal=True)
283 formatter.write('\n')
284 formatter.write('\n')