blob: c01c74394b08b65a95779332bb7d215f4a38a230 [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),
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300178 ct.Cfg('sl_vip_host', ct.IPAddress(),
179 help="Vip address for SL services", default='0.0.0.0'),
180 ct.Cfg('sl_prometheus_port', ct.String(),
181 help="Prometheus port", default='15010'),
182 ct.Cfg('sl_prometheus_proto', ct.String(),
183 help="Proemtheus protocol", default='http'),
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300184]
185
vrovachevbc2f5ce2017-05-22 19:37:24 +0400186virtlet_deploy_opts = [
187 ct.Cfg('virtlet_steps_path', ct.String(),
188 help="Path to YAML with steps to deploy virtlet",
Victor Ryzhenkin655587f2017-05-24 20:00:07 +0400189 default=_default_virtlet_prepare_tests_steps_path),
190 ct.Cfg('virtlet_ceph_steps_path', ct.String(),
191 help="Path to YAML with steps to deploy one-node ceph cluster for "
192 "Virtlet Flexvolumes testing",
193 default=_default_virtlet_ceph_prepare_tests_steps_path)
vrovachevbc2f5ce2017-05-22 19:37:24 +0400194]
195
196virtlet_opts = [
197 ct.Cfg('virtlet_installed', ct.Boolean(),
198 help="", default=False),
Victor Ryzhenkin655587f2017-05-24 20:00:07 +0400199 ct.Cfg('ceph_installed', ct.Boolean(),
200 help="Determine, installed one-node ceph cluster or not",
201 default=False)
vrovachevbc2f5ce2017-05-22 19:37:24 +0400202]
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300203
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300204k8s_deploy_opts = [
Artem Panchenko0594cd72017-06-12 13:25:26 +0300205 ct.Cfg('k8s_steps_path', ct.String(),
206 help="Path to YAML with steps to deploy Kubernetes",
207 default=_default_k8s_steps),
208 ct.Cfg('kubernetes_admin_user', ct.String(), default='admin'),
209 ct.Cfg('kubernetes_admin_password', ct.String(),
210 default='sbPfel23ZigJF3Bm'),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300211 ct.Cfg('kubernetes_docker_package', ct.String(), default=''),
212 ct.Cfg('kubernetes_hyperkube_image', ct.String(),
vrovacheva9d08332017-06-22 20:01:59 +0400213 default='{}/mirantis/kubernetes/hyperkube-amd64:v1.6.4-3'.format(
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300214 settings.DOCKER_REGISTRY)),
215 ct.Cfg('kubernetes_calico_image', ct.String(),
216 default='{}/mirantis/projectcalico/calico/node:latest'.format(
217 settings.DOCKER_REGISTRY)),
218 ct.Cfg('kubernetes_calicoctl_image', ct.String(),
219 default='{}/mirantis/projectcalico/calico/ctl:latest'.format(
220 settings.DOCKER_REGISTRY)),
221 ct.Cfg('kubernetes_calico_cni_image', ct.String(),
222 default='{}/mirantis/projectcalico/calico/cni:latest'.format(
223 settings.DOCKER_REGISTRY)),
Artem Panchenko0594cd72017-06-12 13:25:26 +0300224 ct.Cfg('kubernetes_netchecker_enabled', ct.Boolean(),
225 help="", default=True),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300226 ct.Cfg('kubernetes_netchecker_agent_image', ct.String(),
Tatyana Leontovichf00b2342017-07-04 18:26:25 +0300227 default='mirantis/k8s-netchecker-agent:stable'),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300228 ct.Cfg('kubernetes_netchecker_server_image', ct.String(),
Tatyana Leontovichf00b2342017-07-04 18:26:25 +0300229 default='mirantis/k8s-netchecker-server:stable'),
Artem Panchenko501e67e2017-06-14 14:59:18 +0300230 ct.Cfg('kubernetes_calico_policy_enabled', ct.Boolean(),
231 help="", default=False),
232 ct.Cfg('kubernetes_calico_policy_image', ct.String(),
233 default='calico/kube-policy-controller:v0.5.4'),
234 ct.Cfg('kubernetes_helm_enabled', ct.Boolean(),
235 help="", default=True),
Victor Ryzhenkin0bf0bb02017-07-06 18:57:05 +0400236 ct.Cfg('kubernetes_virtlet_enabled', ct.Boolean(),
237 help="", default=False),
238 ct.Cfg('kubernetes_virtlet_image', ct.String(),
239 help="", default='mirantis/virtlet:latest')
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300240]
241
242k8s_opts = [
Artem Panchenko0594cd72017-06-12 13:25:26 +0300243 ct.Cfg('k8s_installed', ct.Boolean(),
244 help="", default=False),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300245 ct.Cfg('kube_host', ct.IPAddress(),
246 help="", default='0.0.0.0'),
247 ct.Cfg('kube_apiserver_port', ct.Integer(),
248 help="", default=443),
vrovacheva9d08332017-06-22 20:01:59 +0400249 ct.Cfg("k8s_conformance_run", ct.Boolean(),
250 default=False),
251 ct.Cfg('k8s_conformance_image', ct.String(),
252 default='docker-dev-virtual.docker.mirantis.net/mirantis/'
253 'kubernetes/k8s-conformance:v1.6.4-3_1495550936267')
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300254]
255
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300256_group_opts = [
257 ('hardware', hardware_opts),
258 ('underlay', underlay_opts),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200259 ('salt_deploy', salt_deploy_opts),
260 ('salt', salt_opts),
261 ('common_services_deploy', common_services_deploy_opts),
262 ('common_services', common_services_opts),
263 ('openstack_deploy', openstack_deploy_opts),
264 ('openstack', openstack_opts),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200265 ('opencontrail', opencontrail_opts),
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300266 ('stack_light', sl_opts),
267 ('sl_deploy', sl_deploy_opts),
vrovachevbc2f5ce2017-05-22 19:37:24 +0400268 ('virtlet_deploy', virtlet_deploy_opts),
269 ('virtlet', virtlet_opts),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300270 ('k8s_deploy', k8s_deploy_opts),
271 ('k8s', k8s_opts),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300272]
273
274
275def register_opts(config):
276 config.register_group(cfg.OptGroup(name='hardware',
277 title="Hardware settings", help=""))
278 config.register_opts(group='hardware', opts=hardware_opts)
279
280 config.register_group(cfg.OptGroup(name='underlay',
281 title="Underlay configuration", help=""))
282 config.register_opts(group='underlay', opts=underlay_opts)
283
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200284 config.register_group(cfg.OptGroup(name='salt_deploy',
285 title="salt deploy configuration", help=""))
286 config.register_opts(group='salt_deploy', opts=salt_deploy_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300287
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200288 config.register_group(cfg.OptGroup(name='salt',
289 title="salt config and credentials", help=""))
290 config.register_opts(group='salt', opts=salt_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300291
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200292 config.register_group(cfg.OptGroup(name='common_services',
293 title="Common services for Openstack", help=""))
294 config.register_opts(group='common_services', opts=common_services_opts)
295
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300296 config.register_group(
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200297 cfg.OptGroup(name='common_services_deploy',
298 title="Common services for Openstack deploy config",
299 help=""))
300 config.register_opts(group='common_services_deploy',
301 opts=common_services_deploy_opts)
302
303 config.register_group(cfg.OptGroup(name='openstack',
304 title="Openstack config and credentials", help=""))
305 config.register_opts(group='openstack', opts=openstack_opts)
306
307 config.register_group(
308 cfg.OptGroup(name='openstack_deploy',
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300309 title="Openstack deploy config and credentials",
310 help=""))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200311 config.register_opts(group='openstack_deploy', opts=openstack_deploy_opts)
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200312
313 config.register_group(cfg.OptGroup(name='opencontrail',
314 title="Options for Juniper contrail-tests", help=""))
315 config.register_opts(group='opencontrail', opts=opencontrail_opts)
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300316 config.register_group(cfg.OptGroup(name='stack_light',
317 title="StackLight config and credentials", help=""))
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300318 config.register_opts(group='stack_light', opts=sl_opts)
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300319 config.register_group(
320 cfg.OptGroup(name='sl_deploy',
321 title="SL deploy config and credentials",
322 help=""))
323 config.register_opts(group='sl_deploy', opts=sl_deploy_opts)
vrovachevbc2f5ce2017-05-22 19:37:24 +0400324 config.register_group(cfg.OptGroup(name='virtlet_deploy',
325 title='Virtlet deploy config', help=""))
326 config.register_opts(group='virtlet_deploy', opts=virtlet_deploy_opts)
327 config.register_group(cfg.OptGroup(name='virtlet',
328 title='Virtlet config', help=""))
329 config.register_opts(group='virtlet', opts=virtlet_opts)
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300330
331 config.register_group(cfg.OptGroup(name='k8s_deploy',
332 title="K8s deploy configuration"))
333 config.register_opts(group='k8s_deploy', opts=k8s_deploy_opts)
334
335 config.register_group(cfg.OptGroup(name='k8s',
336 title="K8s config and credentials"))
337 config.register_opts(group='k8s', opts=k8s_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300338 return config
339
340
341def load_config(config_files):
342 config = cfg.CONF
343 register_opts(config)
344 config(args=[], default_config_files=config_files)
345 return config
346
347
348def reload_snapshot_config(config, test_config_path):
349 """Reset config to the state from test_config file"""
350 config(args=[], default_config_files=[test_config_path])
351 return config
352
353
354def list_opts():
355 """Return a list of oslo.config options available in the tcp_tests.
356 """
357 return [(group, copy.deepcopy(opts)) for group, opts in _group_opts]
358
359
360def list_current_opts(config):
361 """Return a list of oslo.config options available in the tcp_tests.
362 """
363 result_opts = []
364 for group, opts in _group_opts:
365 current_opts = copy.deepcopy(opts)
366 for opt in current_opts:
367 if hasattr(config, group):
368 if hasattr(config[group], opt.name):
369 opt.default = getattr(config[group], opt.name)
370 result_opts.append((group, current_opts))
371 return result_opts
372
373
374def save_config(config, snapshot_name, env_name=None):
375 if env_name is None:
376 env_name = 'config'
377 test_config_path = os.path.join(
378 settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))
379
380 with open(test_config_path, 'w') as output_file:
381 formatter = generator._OptFormatter(output_file=output_file)
382 for group, opts in list_current_opts(config):
383 formatter.format_group(group)
384 for opt in opts:
385 formatter.format(opt, group, minimal=True)
386 formatter.write('\n')
387 formatter.write('\n')