blob: f51f8ce4deaa3e2a7aba0f2bc256e1d43ef2919e [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))
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030043
44
45hardware_opts = [
46 ct.Cfg('manager', ct.String(),
47 help="Hardware manager name", default="devops"),
48 ct.Cfg('conf_path', ct.String(),
49 help="Hardware config file", default=_default_conf),
50 ct.Cfg('current_snapshot', ct.String(),
51 help="Latest environment status name",
52 default=ext.SNAPSHOT.hardware),
53]
54
55
56underlay_opts = [
57 ct.Cfg('ssh', ct.JSONList(),
58 help="""SSH Settings for Underlay: [{
59 'node_name': node1,
Dennis Dmitriev23e5d192016-10-31 11:27:10 +020060 'roles': ['salt-master', 'salt-minion', ],
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030061 'host': hostname,
62 'login': login,
63 'password': password,
64 'address_pool': (optional),
65 'port': (optional),
66 'keys': [(optional)],
67 }, ...]""", default=[]),
68 ct.Cfg('roles', ct.JSONList(),
69 help="Node roles managed by underlay in the environment",
Dennis Dmitriev53d3b772016-10-18 14:31:58 +030070 default=[ext.UNDERLAY_NODE_ROLES.salt_master,
71 ext.UNDERLAY_NODE_ROLES.salt_minion, ]),
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +030072 ct.Cfg('bootstrap_timeout', ct.Integer(),
73 help="Timeout of waiting SSH for nodes with specified roles",
74 default=480),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030075 ct.Cfg('nameservers', ct.JSONList(),
76 help="IP addresses of DNS servers",
77 default=[]),
78 ct.Cfg('upstream_dns_servers', ct.JSONList(),
79 help="IP addresses of upstream DNS servers (dnsmasq)",
80 default=[]),
81 ct.Cfg('lvm', ct.JSONDict(),
82 help="LVM settings for Underlay", default={}),
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030083 ct.Cfg('address_pools', ct.JSONDict(),
84 help="""Address pools (dynamically) allocated for the environment.
85 May be used to determine CIDR for a specific network from
86 tests or during the deployment process.
87 {'pool_name1': '<cidr>', 'pool_name2': '<cidr>', ...}""",
88 default={}),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030089]
90
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020091
92salt_deploy_opts = [
93 ct.Cfg('salt_steps_path', ct.String(),
94 help="Path to YAML with steps to deploy salt",
95 default=_default_salt_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030096]
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020097salt_opts = [
98 ct.Cfg('salt_master_host', ct.IPAddress(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030099 help="", default='0.0.0.0'),
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300100 ct.Cfg('salt_master_port', ct.String(),
101 help="", default='6969'),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300102]
103
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200104common_services_deploy_opts = [
105 ct.Cfg('common_services_steps_path', ct.String(),
106 help="Path to YAML with steps to deploy common services",
107 default=_default_common_services_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300108]
109
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200110common_services_opts = [
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200111 ct.Cfg('common_services_installed', ct.Boolean(),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200112 help="", default=False),
113]
114
115openstack_deploy_opts = [
116 ct.Cfg('openstack_steps_path', ct.String(),
117 help="Path to YAML with steps to deploy openstack",
118 default=_default_openstack_steps),
119]
120openstack_opts = [
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200121 ct.Cfg('openstack_installed', ct.Boolean(),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200122 help="", default=False),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200123 ct.Cfg('openstack_keystone_endpoint', ct.String(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300124 help="", default=''),
125]
126
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200127opencontrail_opts = [
128 ct.Cfg('opencontrail_tags', ct.String(),
129 help="", default=''),
130 ct.Cfg('opencontrail_features', ct.String(),
131 help="", default=''),
132 ct.Cfg('opencontrail_prepare_tests_steps_path', ct.String(),
133 help="Path to YAML with steps to prepare contrail-tests",
134 default=_default_opencontrail_prepare_tests_steps_path),
135]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300136
137_group_opts = [
138 ('hardware', hardware_opts),
139 ('underlay', underlay_opts),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200140 ('salt_deploy', salt_deploy_opts),
141 ('salt', salt_opts),
142 ('common_services_deploy', common_services_deploy_opts),
143 ('common_services', common_services_opts),
144 ('openstack_deploy', openstack_deploy_opts),
145 ('openstack', openstack_opts),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200146 ('opencontrail', opencontrail_opts),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300147]
148
149
150def register_opts(config):
151 config.register_group(cfg.OptGroup(name='hardware',
152 title="Hardware settings", help=""))
153 config.register_opts(group='hardware', opts=hardware_opts)
154
155 config.register_group(cfg.OptGroup(name='underlay',
156 title="Underlay configuration", help=""))
157 config.register_opts(group='underlay', opts=underlay_opts)
158
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200159 config.register_group(cfg.OptGroup(name='salt_deploy',
160 title="salt deploy configuration", help=""))
161 config.register_opts(group='salt_deploy', opts=salt_deploy_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300162
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200163 config.register_group(cfg.OptGroup(name='salt',
164 title="salt config and credentials", help=""))
165 config.register_opts(group='salt', opts=salt_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300166
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200167 config.register_group(cfg.OptGroup(name='common_services',
168 title="Common services for Openstack", help=""))
169 config.register_opts(group='common_services', opts=common_services_opts)
170
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300171 config.register_group(
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200172 cfg.OptGroup(name='common_services_deploy',
173 title="Common services for Openstack deploy config",
174 help=""))
175 config.register_opts(group='common_services_deploy',
176 opts=common_services_deploy_opts)
177
178 config.register_group(cfg.OptGroup(name='openstack',
179 title="Openstack config and credentials", help=""))
180 config.register_opts(group='openstack', opts=openstack_opts)
181
182 config.register_group(
183 cfg.OptGroup(name='openstack_deploy',
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300184 title="Openstack deploy config and credentials",
185 help=""))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200186 config.register_opts(group='openstack_deploy', opts=openstack_deploy_opts)
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200187
188 config.register_group(cfg.OptGroup(name='opencontrail',
189 title="Options for Juniper contrail-tests", help=""))
190 config.register_opts(group='opencontrail', opts=opencontrail_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300191 return config
192
193
194def load_config(config_files):
195 config = cfg.CONF
196 register_opts(config)
197 config(args=[], default_config_files=config_files)
198 return config
199
200
201def reload_snapshot_config(config, test_config_path):
202 """Reset config to the state from test_config file"""
203 config(args=[], default_config_files=[test_config_path])
204 return config
205
206
207def list_opts():
208 """Return a list of oslo.config options available in the tcp_tests.
209 """
210 return [(group, copy.deepcopy(opts)) for group, opts in _group_opts]
211
212
213def list_current_opts(config):
214 """Return a list of oslo.config options available in the tcp_tests.
215 """
216 result_opts = []
217 for group, opts in _group_opts:
218 current_opts = copy.deepcopy(opts)
219 for opt in current_opts:
220 if hasattr(config, group):
221 if hasattr(config[group], opt.name):
222 opt.default = getattr(config[group], opt.name)
223 result_opts.append((group, current_opts))
224 return result_opts
225
226
227def save_config(config, snapshot_name, env_name=None):
228 if env_name is None:
229 env_name = 'config'
230 test_config_path = os.path.join(
231 settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))
232
233 with open(test_config_path, 'w') as output_file:
234 formatter = generator._OptFormatter(output_file=output_file)
235 for group, opts in list_current_opts(config):
236 formatter.format_group(group)
237 for opt in opts:
238 formatter.format(opt, group, minimal=True)
239 formatter.write('\n')
240 formatter.write('\n')