blob: bde95c49e99b0837bd37832bf667231e550dcfec [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
25
26_default_conf = pkg_resources.resource_filename(
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020027 __name__, 'templates/underlay/mk22-lab-advanced.yaml')
28
29_default_salt_steps = pkg_resources.resource_filename(
30 __name__, 'templates/salt/mk22-lab-advanced-salt.yaml')
31_default_common_services_steps = pkg_resources.resource_filename(
32 __name__,
33 'templates/common-services/mk22-lab-advanced-common-services.yaml')
34_default_openstack_steps = pkg_resources.resource_filename(
35 __name__, 'templates/openstack/mk22-lab-advanced-openstack.yaml')
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030036
37
38hardware_opts = [
39 ct.Cfg('manager', ct.String(),
40 help="Hardware manager name", default="devops"),
41 ct.Cfg('conf_path', ct.String(),
42 help="Hardware config file", default=_default_conf),
43 ct.Cfg('current_snapshot', ct.String(),
44 help="Latest environment status name",
45 default=ext.SNAPSHOT.hardware),
46]
47
48
49underlay_opts = [
50 ct.Cfg('ssh', ct.JSONList(),
51 help="""SSH Settings for Underlay: [{
52 'node_name': node1,
Dennis Dmitriev23e5d192016-10-31 11:27:10 +020053 'roles': ['salt-master', 'salt-minion', ],
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030054 'host': hostname,
55 'login': login,
56 'password': password,
57 'address_pool': (optional),
58 'port': (optional),
59 'keys': [(optional)],
60 }, ...]""", default=[]),
61 ct.Cfg('roles', ct.JSONList(),
62 help="Node roles managed by underlay in the environment",
Dennis Dmitriev53d3b772016-10-18 14:31:58 +030063 default=[ext.UNDERLAY_NODE_ROLES.salt_master,
64 ext.UNDERLAY_NODE_ROLES.salt_minion, ]),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030065 ct.Cfg('nameservers', ct.JSONList(),
66 help="IP addresses of DNS servers",
67 default=[]),
68 ct.Cfg('upstream_dns_servers', ct.JSONList(),
69 help="IP addresses of upstream DNS servers (dnsmasq)",
70 default=[]),
71 ct.Cfg('lvm', ct.JSONDict(),
72 help="LVM settings for Underlay", default={}),
73]
74
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020075
76salt_deploy_opts = [
77 ct.Cfg('salt_steps_path', ct.String(),
78 help="Path to YAML with steps to deploy salt",
79 default=_default_salt_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030080]
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020081salt_opts = [
82 ct.Cfg('salt_master_host', ct.IPAddress(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030083 help="", default='0.0.0.0'),
84]
85
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020086common_services_deploy_opts = [
87 ct.Cfg('common_services_steps_path', ct.String(),
88 help="Path to YAML with steps to deploy common services",
89 default=_default_common_services_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030090]
91
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020092common_services_opts = [
93 ct.Cfg('installed', ct.Boolean(),
94 help="", default=False),
95]
96
97openstack_deploy_opts = [
98 ct.Cfg('openstack_steps_path', ct.String(),
99 help="Path to YAML with steps to deploy openstack",
100 default=_default_openstack_steps),
101]
102openstack_opts = [
103 ct.Cfg('installed', ct.Boolean(),
104 help="", default=False),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300105 ct.Cfg('keystone_endpoint', ct.String(),
106 help="", default=''),
107]
108
109
110_group_opts = [
111 ('hardware', hardware_opts),
112 ('underlay', underlay_opts),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200113 ('salt_deploy', salt_deploy_opts),
114 ('salt', salt_opts),
115 ('common_services_deploy', common_services_deploy_opts),
116 ('common_services', common_services_opts),
117 ('openstack_deploy', openstack_deploy_opts),
118 ('openstack', openstack_opts),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300119]
120
121
122def register_opts(config):
123 config.register_group(cfg.OptGroup(name='hardware',
124 title="Hardware settings", help=""))
125 config.register_opts(group='hardware', opts=hardware_opts)
126
127 config.register_group(cfg.OptGroup(name='underlay',
128 title="Underlay configuration", help=""))
129 config.register_opts(group='underlay', opts=underlay_opts)
130
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200131 config.register_group(cfg.OptGroup(name='salt_deploy',
132 title="salt deploy configuration", help=""))
133 config.register_opts(group='salt_deploy', opts=salt_deploy_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300134
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200135 config.register_group(cfg.OptGroup(name='salt',
136 title="salt config and credentials", help=""))
137 config.register_opts(group='salt', opts=salt_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300138
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200139 config.register_group(cfg.OptGroup(name='common_services',
140 title="Common services for Openstack", help=""))
141 config.register_opts(group='common_services', opts=common_services_opts)
142
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300143 config.register_group(
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200144 cfg.OptGroup(name='common_services_deploy',
145 title="Common services for Openstack deploy config",
146 help=""))
147 config.register_opts(group='common_services_deploy',
148 opts=common_services_deploy_opts)
149
150 config.register_group(cfg.OptGroup(name='openstack',
151 title="Openstack config and credentials", help=""))
152 config.register_opts(group='openstack', opts=openstack_opts)
153
154 config.register_group(
155 cfg.OptGroup(name='openstack_deploy',
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300156 title="Openstack deploy config and credentials",
157 help=""))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200158 config.register_opts(group='openstack_deploy', opts=openstack_deploy_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300159 return config
160
161
162def load_config(config_files):
163 config = cfg.CONF
164 register_opts(config)
165 config(args=[], default_config_files=config_files)
166 return config
167
168
169def reload_snapshot_config(config, test_config_path):
170 """Reset config to the state from test_config file"""
171 config(args=[], default_config_files=[test_config_path])
172 return config
173
174
175def list_opts():
176 """Return a list of oslo.config options available in the tcp_tests.
177 """
178 return [(group, copy.deepcopy(opts)) for group, opts in _group_opts]
179
180
181def list_current_opts(config):
182 """Return a list of oslo.config options available in the tcp_tests.
183 """
184 result_opts = []
185 for group, opts in _group_opts:
186 current_opts = copy.deepcopy(opts)
187 for opt in current_opts:
188 if hasattr(config, group):
189 if hasattr(config[group], opt.name):
190 opt.default = getattr(config[group], opt.name)
191 result_opts.append((group, current_opts))
192 return result_opts
193
194
195def save_config(config, snapshot_name, env_name=None):
196 if env_name is None:
197 env_name = 'config'
198 test_config_path = os.path.join(
199 settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))
200
201 with open(test_config_path, 'w') as output_file:
202 formatter = generator._OptFormatter(output_file=output_file)
203 for group, opts in list_current_opts(config):
204 formatter.format_group(group)
205 for opt in opts:
206 formatter.format(opt, group, minimal=True)
207 formatter.write('\n')
208 formatter.write('\n')