blob: 81907206f6f18bab64a9ab0dba25d4114942f890 [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 Dmitriev2a13a132016-11-04 00:56:23 +020029 __name__, 'templates/underlay/{0}.yaml'.format(settings.LAB_CONFIG_NAME))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020030
31_default_salt_steps = pkg_resources.resource_filename(
Dennis Dmitriev2a13a132016-11-04 00:56:23 +020032 __name__, 'templates/salt/{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 Dmitriev2a13a132016-11-04 00:56:23 +020035 'templates/common-services/{0}-common-services.yaml'.format(
36 settings.LAB_CONFIG_NAME))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020037_default_openstack_steps = pkg_resources.resource_filename(
Dennis Dmitriev2a13a132016-11-04 00:56:23 +020038 __name__, 'templates/openstack/{0}-openstack.yaml'.format(
39 settings.LAB_CONFIG_NAME))
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020040_default_opencontrail_prepare_tests_steps_path = pkg_resources.resource_filename(
41 __name__, 'templates/opencontrail/{0}-opencontrail.yaml'.format(
42 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 Dmitriev6f59add2016-10-18 13:45:27 +030072 ct.Cfg('nameservers', ct.JSONList(),
73 help="IP addresses of DNS servers",
74 default=[]),
75 ct.Cfg('upstream_dns_servers', ct.JSONList(),
76 help="IP addresses of upstream DNS servers (dnsmasq)",
77 default=[]),
78 ct.Cfg('lvm', ct.JSONDict(),
79 help="LVM settings for Underlay", default={}),
80]
81
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020082
83salt_deploy_opts = [
84 ct.Cfg('salt_steps_path', ct.String(),
85 help="Path to YAML with steps to deploy salt",
86 default=_default_salt_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030087]
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020088salt_opts = [
89 ct.Cfg('salt_master_host', ct.IPAddress(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030090 help="", default='0.0.0.0'),
91]
92
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020093common_services_deploy_opts = [
94 ct.Cfg('common_services_steps_path', ct.String(),
95 help="Path to YAML with steps to deploy common services",
96 default=_default_common_services_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030097]
98
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020099common_services_opts = [
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200100 ct.Cfg('common_services_installed', ct.Boolean(),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200101 help="", default=False),
102]
103
104openstack_deploy_opts = [
105 ct.Cfg('openstack_steps_path', ct.String(),
106 help="Path to YAML with steps to deploy openstack",
107 default=_default_openstack_steps),
108]
109openstack_opts = [
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200110 ct.Cfg('openstack_installed', ct.Boolean(),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200111 help="", default=False),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200112 ct.Cfg('openstack_keystone_endpoint', ct.String(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300113 help="", default=''),
114]
115
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200116opencontrail_opts = [
117 ct.Cfg('opencontrail_tags', ct.String(),
118 help="", default=''),
119 ct.Cfg('opencontrail_features', ct.String(),
120 help="", default=''),
121 ct.Cfg('opencontrail_prepare_tests_steps_path', ct.String(),
122 help="Path to YAML with steps to prepare contrail-tests",
123 default=_default_opencontrail_prepare_tests_steps_path),
124]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300125
126_group_opts = [
127 ('hardware', hardware_opts),
128 ('underlay', underlay_opts),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200129 ('salt_deploy', salt_deploy_opts),
130 ('salt', salt_opts),
131 ('common_services_deploy', common_services_deploy_opts),
132 ('common_services', common_services_opts),
133 ('openstack_deploy', openstack_deploy_opts),
134 ('openstack', openstack_opts),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200135 ('opencontrail', opencontrail_opts),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300136]
137
138
139def register_opts(config):
140 config.register_group(cfg.OptGroup(name='hardware',
141 title="Hardware settings", help=""))
142 config.register_opts(group='hardware', opts=hardware_opts)
143
144 config.register_group(cfg.OptGroup(name='underlay',
145 title="Underlay configuration", help=""))
146 config.register_opts(group='underlay', opts=underlay_opts)
147
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200148 config.register_group(cfg.OptGroup(name='salt_deploy',
149 title="salt deploy configuration", help=""))
150 config.register_opts(group='salt_deploy', opts=salt_deploy_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300151
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200152 config.register_group(cfg.OptGroup(name='salt',
153 title="salt config and credentials", help=""))
154 config.register_opts(group='salt', opts=salt_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300155
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200156 config.register_group(cfg.OptGroup(name='common_services',
157 title="Common services for Openstack", help=""))
158 config.register_opts(group='common_services', opts=common_services_opts)
159
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300160 config.register_group(
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200161 cfg.OptGroup(name='common_services_deploy',
162 title="Common services for Openstack deploy config",
163 help=""))
164 config.register_opts(group='common_services_deploy',
165 opts=common_services_deploy_opts)
166
167 config.register_group(cfg.OptGroup(name='openstack',
168 title="Openstack config and credentials", help=""))
169 config.register_opts(group='openstack', opts=openstack_opts)
170
171 config.register_group(
172 cfg.OptGroup(name='openstack_deploy',
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300173 title="Openstack deploy config and credentials",
174 help=""))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200175 config.register_opts(group='openstack_deploy', opts=openstack_deploy_opts)
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200176
177 config.register_group(cfg.OptGroup(name='opencontrail',
178 title="Options for Juniper contrail-tests", help=""))
179 config.register_opts(group='opencontrail', opts=opencontrail_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300180 return config
181
182
183def load_config(config_files):
184 config = cfg.CONF
185 register_opts(config)
186 config(args=[], default_config_files=config_files)
187 return config
188
189
190def reload_snapshot_config(config, test_config_path):
191 """Reset config to the state from test_config file"""
192 config(args=[], default_config_files=[test_config_path])
193 return config
194
195
196def list_opts():
197 """Return a list of oslo.config options available in the tcp_tests.
198 """
199 return [(group, copy.deepcopy(opts)) for group, opts in _group_opts]
200
201
202def list_current_opts(config):
203 """Return a list of oslo.config options available in the tcp_tests.
204 """
205 result_opts = []
206 for group, opts in _group_opts:
207 current_opts = copy.deepcopy(opts)
208 for opt in current_opts:
209 if hasattr(config, group):
210 if hasattr(config[group], opt.name):
211 opt.default = getattr(config[group], opt.name)
212 result_opts.append((group, current_opts))
213 return result_opts
214
215
216def save_config(config, snapshot_name, env_name=None):
217 if env_name is None:
218 env_name = 'config'
219 test_config_path = os.path.join(
220 settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))
221
222 with open(test_config_path, 'w') as output_file:
223 formatter = generator._OptFormatter(output_file=output_file)
224 for group, opts in list_current_opts(config):
225 formatter.format_group(group)
226 for opt in opts:
227 formatter.format(opt, group, minimal=True)
228 formatter.write('\n')
229 formatter.write('\n')