blob: 47c18d16699ae9e742f00a96bbc6450fff6156ec [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))
Victor Ryzhenkin655587f2017-05-24 20:00:07 +040049_default_virtlet_ceph_prepare_tests_steps_path = pkg_resources.resource_filename(
50 __name__, 'templates/{0}/virtlet_ceph.yaml'.format(
51 settings.LAB_CONFIG_NAME))
Artem Panchenko0594cd72017-06-12 13:25:26 +030052_default_k8s_steps = pkg_resources.resource_filename(
53 __name__, 'templates/{0}/k8s.yaml'.format(
54 settings.LAB_CONFIG_NAME))
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030055
56hardware_opts = [
57 ct.Cfg('manager', ct.String(),
58 help="Hardware manager name", default="devops"),
59 ct.Cfg('conf_path', ct.String(),
60 help="Hardware config file", default=_default_conf),
61 ct.Cfg('current_snapshot', ct.String(),
62 help="Latest environment status name",
63 default=ext.SNAPSHOT.hardware),
64]
65
66
67underlay_opts = [
68 ct.Cfg('ssh', ct.JSONList(),
69 help="""SSH Settings for Underlay: [{
70 'node_name': node1,
Dennis Dmitriev23e5d192016-10-31 11:27:10 +020071 'roles': ['salt-master', 'salt-minion', ],
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030072 'host': hostname,
73 'login': login,
74 'password': password,
75 'address_pool': (optional),
76 'port': (optional),
77 'keys': [(optional)],
78 }, ...]""", default=[]),
79 ct.Cfg('roles', ct.JSONList(),
80 help="Node roles managed by underlay in the environment",
Dennis Dmitriev53d3b772016-10-18 14:31:58 +030081 default=[ext.UNDERLAY_NODE_ROLES.salt_master,
vrovachev99228d32017-06-08 19:46:10 +040082 ext.UNDERLAY_NODE_ROLES.salt_minion,
83 ext.UNDERLAY_NODE_ROLES.k8s_virtlet, ]),
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +030084 ct.Cfg('bootstrap_timeout', ct.Integer(),
85 help="Timeout of waiting SSH for nodes with specified roles",
86 default=480),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030087 ct.Cfg('nameservers', ct.JSONList(),
88 help="IP addresses of DNS servers",
89 default=[]),
90 ct.Cfg('upstream_dns_servers', ct.JSONList(),
91 help="IP addresses of upstream DNS servers (dnsmasq)",
92 default=[]),
93 ct.Cfg('lvm', ct.JSONDict(),
94 help="LVM settings for Underlay", default={}),
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030095 ct.Cfg('address_pools', ct.JSONDict(),
96 help="""Address pools (dynamically) allocated for the environment.
97 May be used to determine CIDR for a specific network from
98 tests or during the deployment process.
99 {'pool_name1': '<cidr>', 'pool_name2': '<cidr>', ...}""",
100 default={}),
Artem Panchenkodb0a97f2017-06-27 19:09:13 +0300101 ct.Cfg('ssh_keys', ct.JSONList(), default=[],
102 help="SSH key pair(s) for root. If the option is left empty, "
103 "then a key pair will be generated automatically"),
104 ct.Cfg('ssh_key_file', ct.String(), default=os.path.abspath('./id_rsa'),
105 help='Path (local) to file with private key authorized on nodes'),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300106]
107
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200108
109salt_deploy_opts = [
110 ct.Cfg('salt_steps_path', ct.String(),
111 help="Path to YAML with steps to deploy salt",
112 default=_default_salt_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300113]
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200114salt_opts = [
115 ct.Cfg('salt_master_host', ct.IPAddress(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300116 help="", default='0.0.0.0'),
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300117 ct.Cfg('salt_master_port', ct.String(),
118 help="", default='6969'),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300119]
120
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200121common_services_deploy_opts = [
122 ct.Cfg('common_services_steps_path', ct.String(),
123 help="Path to YAML with steps to deploy common services",
124 default=_default_common_services_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300125]
126
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200127common_services_opts = [
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200128 ct.Cfg('common_services_installed', ct.Boolean(),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200129 help="", default=False),
130]
131
132openstack_deploy_opts = [
133 ct.Cfg('openstack_steps_path', ct.String(),
134 help="Path to YAML with steps to deploy openstack",
135 default=_default_openstack_steps),
136]
137openstack_opts = [
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200138 ct.Cfg('openstack_installed', ct.Boolean(),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200139 help="", default=False),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200140 ct.Cfg('openstack_keystone_endpoint', ct.String(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300141 help="", default=''),
142]
143
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200144opencontrail_opts = [
145 ct.Cfg('opencontrail_tags', ct.String(),
146 help="", default=''),
147 ct.Cfg('opencontrail_features', ct.String(),
148 help="", default=''),
149 ct.Cfg('opencontrail_prepare_tests_steps_path', ct.String(),
150 help="Path to YAML with steps to prepare contrail-tests",
151 default=_default_opencontrail_prepare_tests_steps_path),
152]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300153
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300154sl_deploy_opts = [
155 ct.Cfg('sl_steps_path', ct.String(),
156 help="Path to YAML with steps to deploy sl",
157 default=_default_sl_prepare_tests_steps_path),
Tatyana Leontovichf00b2342017-07-04 18:26:25 +0300158 ct.Cfg('docker_image_alertmanager', ct.String(),
159 default='{}/openstack-docker/alertmanager:latest'.format(
160 settings.DOCKER_REGISTRY)),
161 ct.Cfg('docker_image_pushgateway', ct.String(),
162 default='{}/openstack-docker/pushgateway:latest'.format(
163 settings.DOCKER_REGISTRY)),
164 ct.Cfg('docker_image_prometheus', ct.String(),
165 default='{}/openstack-docker/prometheus:latest'.format(
166 settings.DOCKER_REGISTRY)),
167 ct.Cfg('docker_image_remote_agent', ct.String(),
168 default='{}/openstack-docker/telegraf:latest'.format(
169 settings.DOCKER_REGISTRY)),
170 ct.Cfg('docker_image_remote_storage_adapter', ct.String(),
171 default='{}/openstack-docker/remote_storage_adapter:latest'.format(
172 settings.DOCKER_REGISTRY)),
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300173]
Tatyana Leontovichf00b2342017-07-04 18:26:25 +0300174
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300175sl_opts = [
176 ct.Cfg('sl_installed', ct.Boolean(),
177 help="", default=False),
178]
179
vrovachevbc2f5ce2017-05-22 19:37:24 +0400180virtlet_deploy_opts = [
181 ct.Cfg('virtlet_steps_path', ct.String(),
182 help="Path to YAML with steps to deploy virtlet",
Victor Ryzhenkin655587f2017-05-24 20:00:07 +0400183 default=_default_virtlet_prepare_tests_steps_path),
184 ct.Cfg('virtlet_ceph_steps_path', ct.String(),
185 help="Path to YAML with steps to deploy one-node ceph cluster for "
186 "Virtlet Flexvolumes testing",
187 default=_default_virtlet_ceph_prepare_tests_steps_path)
vrovachevbc2f5ce2017-05-22 19:37:24 +0400188]
189
190virtlet_opts = [
191 ct.Cfg('virtlet_installed', ct.Boolean(),
192 help="", default=False),
Victor Ryzhenkin655587f2017-05-24 20:00:07 +0400193 ct.Cfg('ceph_installed', ct.Boolean(),
194 help="Determine, installed one-node ceph cluster or not",
195 default=False)
vrovachevbc2f5ce2017-05-22 19:37:24 +0400196]
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300197
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300198k8s_deploy_opts = [
Artem Panchenko0594cd72017-06-12 13:25:26 +0300199 ct.Cfg('k8s_steps_path', ct.String(),
200 help="Path to YAML with steps to deploy Kubernetes",
201 default=_default_k8s_steps),
202 ct.Cfg('kubernetes_admin_user', ct.String(), default='admin'),
203 ct.Cfg('kubernetes_admin_password', ct.String(),
204 default='sbPfel23ZigJF3Bm'),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300205 ct.Cfg('kubernetes_docker_package', ct.String(), default=''),
206 ct.Cfg('kubernetes_hyperkube_image', ct.String(),
vrovacheva9d08332017-06-22 20:01:59 +0400207 default='{}/mirantis/kubernetes/hyperkube-amd64:v1.6.4-3'.format(
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300208 settings.DOCKER_REGISTRY)),
209 ct.Cfg('kubernetes_calico_image', ct.String(),
210 default='{}/mirantis/projectcalico/calico/node:latest'.format(
211 settings.DOCKER_REGISTRY)),
212 ct.Cfg('kubernetes_calicoctl_image', ct.String(),
213 default='{}/mirantis/projectcalico/calico/ctl:latest'.format(
214 settings.DOCKER_REGISTRY)),
215 ct.Cfg('kubernetes_calico_cni_image', ct.String(),
216 default='{}/mirantis/projectcalico/calico/cni:latest'.format(
217 settings.DOCKER_REGISTRY)),
Artem Panchenko0594cd72017-06-12 13:25:26 +0300218 ct.Cfg('kubernetes_netchecker_enabled', ct.Boolean(),
219 help="", default=True),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300220 ct.Cfg('kubernetes_netchecker_agent_image', ct.String(),
Tatyana Leontovichf00b2342017-07-04 18:26:25 +0300221 default='mirantis/k8s-netchecker-agent:stable'),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300222 ct.Cfg('kubernetes_netchecker_server_image', ct.String(),
Tatyana Leontovichf00b2342017-07-04 18:26:25 +0300223 default='mirantis/k8s-netchecker-server:stable'),
Artem Panchenko501e67e2017-06-14 14:59:18 +0300224 ct.Cfg('kubernetes_calico_policy_enabled', ct.Boolean(),
225 help="", default=False),
226 ct.Cfg('kubernetes_calico_policy_image', ct.String(),
227 default='calico/kube-policy-controller:v0.5.4'),
228 ct.Cfg('kubernetes_helm_enabled', ct.Boolean(),
229 help="", default=True),
Victor Ryzhenkin0bf0bb02017-07-06 18:57:05 +0400230 ct.Cfg('kubernetes_virtlet_enabled', ct.Boolean(),
231 help="", default=False),
232 ct.Cfg('kubernetes_virtlet_image', ct.String(),
233 help="", default='mirantis/virtlet:latest')
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300234]
235
236k8s_opts = [
Artem Panchenko0594cd72017-06-12 13:25:26 +0300237 ct.Cfg('k8s_installed', ct.Boolean(),
238 help="", default=False),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300239 ct.Cfg('kube_host', ct.IPAddress(),
240 help="", default='0.0.0.0'),
241 ct.Cfg('kube_apiserver_port', ct.Integer(),
242 help="", default=443),
vrovacheva9d08332017-06-22 20:01:59 +0400243 ct.Cfg("k8s_conformance_run", ct.Boolean(),
244 default=False),
245 ct.Cfg('k8s_conformance_image', ct.String(),
246 default='docker-dev-virtual.docker.mirantis.net/mirantis/'
247 'kubernetes/k8s-conformance:v1.6.4-3_1495550936267')
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300248]
249
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300250_group_opts = [
251 ('hardware', hardware_opts),
252 ('underlay', underlay_opts),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200253 ('salt_deploy', salt_deploy_opts),
254 ('salt', salt_opts),
255 ('common_services_deploy', common_services_deploy_opts),
256 ('common_services', common_services_opts),
257 ('openstack_deploy', openstack_deploy_opts),
258 ('openstack', openstack_opts),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200259 ('opencontrail', opencontrail_opts),
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300260 ('stack_light', sl_opts),
261 ('sl_deploy', sl_deploy_opts),
vrovachevbc2f5ce2017-05-22 19:37:24 +0400262 ('virtlet_deploy', virtlet_deploy_opts),
263 ('virtlet', virtlet_opts),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300264 ('k8s_deploy', k8s_deploy_opts),
265 ('k8s', k8s_opts),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300266]
267
268
269def register_opts(config):
270 config.register_group(cfg.OptGroup(name='hardware',
271 title="Hardware settings", help=""))
272 config.register_opts(group='hardware', opts=hardware_opts)
273
274 config.register_group(cfg.OptGroup(name='underlay',
275 title="Underlay configuration", help=""))
276 config.register_opts(group='underlay', opts=underlay_opts)
277
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200278 config.register_group(cfg.OptGroup(name='salt_deploy',
279 title="salt deploy configuration", help=""))
280 config.register_opts(group='salt_deploy', opts=salt_deploy_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300281
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200282 config.register_group(cfg.OptGroup(name='salt',
283 title="salt config and credentials", help=""))
284 config.register_opts(group='salt', opts=salt_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300285
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200286 config.register_group(cfg.OptGroup(name='common_services',
287 title="Common services for Openstack", help=""))
288 config.register_opts(group='common_services', opts=common_services_opts)
289
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300290 config.register_group(
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200291 cfg.OptGroup(name='common_services_deploy',
292 title="Common services for Openstack deploy config",
293 help=""))
294 config.register_opts(group='common_services_deploy',
295 opts=common_services_deploy_opts)
296
297 config.register_group(cfg.OptGroup(name='openstack',
298 title="Openstack config and credentials", help=""))
299 config.register_opts(group='openstack', opts=openstack_opts)
300
301 config.register_group(
302 cfg.OptGroup(name='openstack_deploy',
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300303 title="Openstack deploy config and credentials",
304 help=""))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200305 config.register_opts(group='openstack_deploy', opts=openstack_deploy_opts)
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200306
307 config.register_group(cfg.OptGroup(name='opencontrail',
308 title="Options for Juniper contrail-tests", help=""))
309 config.register_opts(group='opencontrail', opts=opencontrail_opts)
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300310 config.register_group(cfg.OptGroup(name='stack_light',
311 title="StackLight config and credentials", help=""))
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300312 config.register_opts(group='stack_light', opts=sl_opts)
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300313 config.register_group(
314 cfg.OptGroup(name='sl_deploy',
315 title="SL deploy config and credentials",
316 help=""))
317 config.register_opts(group='sl_deploy', opts=sl_deploy_opts)
vrovachevbc2f5ce2017-05-22 19:37:24 +0400318 config.register_group(cfg.OptGroup(name='virtlet_deploy',
319 title='Virtlet deploy config', help=""))
320 config.register_opts(group='virtlet_deploy', opts=virtlet_deploy_opts)
321 config.register_group(cfg.OptGroup(name='virtlet',
322 title='Virtlet config', help=""))
323 config.register_opts(group='virtlet', opts=virtlet_opts)
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300324
325 config.register_group(cfg.OptGroup(name='k8s_deploy',
326 title="K8s deploy configuration"))
327 config.register_opts(group='k8s_deploy', opts=k8s_deploy_opts)
328
329 config.register_group(cfg.OptGroup(name='k8s',
330 title="K8s config and credentials"))
331 config.register_opts(group='k8s', opts=k8s_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300332 return config
333
334
335def load_config(config_files):
336 config = cfg.CONF
337 register_opts(config)
338 config(args=[], default_config_files=config_files)
339 return config
340
341
342def reload_snapshot_config(config, test_config_path):
343 """Reset config to the state from test_config file"""
344 config(args=[], default_config_files=[test_config_path])
345 return config
346
347
348def list_opts():
349 """Return a list of oslo.config options available in the tcp_tests.
350 """
351 return [(group, copy.deepcopy(opts)) for group, opts in _group_opts]
352
353
354def list_current_opts(config):
355 """Return a list of oslo.config options available in the tcp_tests.
356 """
357 result_opts = []
358 for group, opts in _group_opts:
359 current_opts = copy.deepcopy(opts)
360 for opt in current_opts:
361 if hasattr(config, group):
362 if hasattr(config[group], opt.name):
363 opt.default = getattr(config[group], opt.name)
364 result_opts.append((group, current_opts))
365 return result_opts
366
367
368def save_config(config, snapshot_name, env_name=None):
369 if env_name is None:
370 env_name = 'config'
371 test_config_path = os.path.join(
372 settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))
373
374 with open(test_config_path, 'w') as output_file:
375 formatter = generator._OptFormatter(output_file=output_file)
376 for group, opts in list_current_opts(config):
377 formatter.format_group(group)
378 for opt in opts:
379 formatter.format(opt, group, minimal=True)
380 formatter.write('\n')
381 formatter.write('\n')