blob: f1bb073791e186c81eb1b7e5952349045129ed84 [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 Dmitrieveac3aab2017-07-12 16:36:41 +030037_default_oss_steps = pkg_resources.resource_filename(
38 __name__,
39 'templates/{0}/oss.yaml'.format(
40 settings.LAB_CONFIG_NAME))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +020041_default_openstack_steps = pkg_resources.resource_filename(
Dennis Dmitrievab83ea42017-05-12 16:52:45 +030042 __name__, 'templates/{0}/openstack.yaml'.format(
Dennis Dmitriev2a13a132016-11-04 00:56:23 +020043 settings.LAB_CONFIG_NAME))
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020044_default_opencontrail_prepare_tests_steps_path = pkg_resources.resource_filename(
Dennis Dmitrievab83ea42017-05-12 16:52:45 +030045 __name__, 'templates/{0}/opencontrail.yaml'.format(
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020046 settings.LAB_CONFIG_NAME))
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030047_default_sl_prepare_tests_steps_path = pkg_resources.resource_filename(
48 __name__, 'templates/{0}/sl.yaml'.format(
49 settings.LAB_CONFIG_NAME))
vrovachevbc2f5ce2017-05-22 19:37:24 +040050_default_virtlet_prepare_tests_steps_path = pkg_resources.resource_filename(
51 __name__, 'templates/{0}/virtlet.yaml'.format(
52 settings.LAB_CONFIG_NAME))
Victor Ryzhenkin655587f2017-05-24 20:00:07 +040053_default_virtlet_ceph_prepare_tests_steps_path = pkg_resources.resource_filename(
54 __name__, 'templates/{0}/virtlet_ceph.yaml'.format(
55 settings.LAB_CONFIG_NAME))
Artem Panchenko0594cd72017-06-12 13:25:26 +030056_default_k8s_steps = pkg_resources.resource_filename(
57 __name__, 'templates/{0}/k8s.yaml'.format(
58 settings.LAB_CONFIG_NAME))
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030059
60hardware_opts = [
61 ct.Cfg('manager', ct.String(),
62 help="Hardware manager name", default="devops"),
63 ct.Cfg('conf_path', ct.String(),
64 help="Hardware config file", default=_default_conf),
65 ct.Cfg('current_snapshot', ct.String(),
66 help="Latest environment status name",
67 default=ext.SNAPSHOT.hardware),
68]
69
70
71underlay_opts = [
72 ct.Cfg('ssh', ct.JSONList(),
73 help="""SSH Settings for Underlay: [{
74 'node_name': node1,
Dennis Dmitriev23e5d192016-10-31 11:27:10 +020075 'roles': ['salt-master', 'salt-minion', ],
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030076 'host': hostname,
77 'login': login,
78 'password': password,
79 'address_pool': (optional),
80 'port': (optional),
81 'keys': [(optional)],
82 }, ...]""", default=[]),
83 ct.Cfg('roles', ct.JSONList(),
84 help="Node roles managed by underlay in the environment",
Dennis Dmitriev53d3b772016-10-18 14:31:58 +030085 default=[ext.UNDERLAY_NODE_ROLES.salt_master,
vrovachev99228d32017-06-08 19:46:10 +040086 ext.UNDERLAY_NODE_ROLES.salt_minion,
87 ext.UNDERLAY_NODE_ROLES.k8s_virtlet, ]),
Dennis Dmitriev7b9538f2017-05-15 17:01:34 +030088 ct.Cfg('bootstrap_timeout', ct.Integer(),
89 help="Timeout of waiting SSH for nodes with specified roles",
90 default=480),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030091 ct.Cfg('nameservers', ct.JSONList(),
92 help="IP addresses of DNS servers",
93 default=[]),
94 ct.Cfg('upstream_dns_servers', ct.JSONList(),
95 help="IP addresses of upstream DNS servers (dnsmasq)",
96 default=[]),
97 ct.Cfg('lvm', ct.JSONDict(),
98 help="LVM settings for Underlay", default={}),
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030099 ct.Cfg('address_pools', ct.JSONDict(),
100 help="""Address pools (dynamically) allocated for the environment.
101 May be used to determine CIDR for a specific network from
102 tests or during the deployment process.
103 {'pool_name1': '<cidr>', 'pool_name2': '<cidr>', ...}""",
104 default={}),
Artem Panchenkodb0a97f2017-06-27 19:09:13 +0300105 ct.Cfg('ssh_keys', ct.JSONList(), default=[],
106 help="SSH key pair(s) for root. If the option is left empty, "
107 "then a key pair will be generated automatically"),
108 ct.Cfg('ssh_key_file', ct.String(), default=os.path.abspath('./id_rsa'),
109 help='Path (local) to file with private key authorized on nodes'),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300110]
111
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200112
113salt_deploy_opts = [
114 ct.Cfg('salt_steps_path', ct.String(),
115 help="Path to YAML with steps to deploy salt",
116 default=_default_salt_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300117]
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200118salt_opts = [
119 ct.Cfg('salt_master_host', ct.IPAddress(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300120 help="", default='0.0.0.0'),
Dennis Dmitriev2d60c8e2017-05-12 18:34:01 +0300121 ct.Cfg('salt_master_port', ct.String(),
122 help="", default='6969'),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300123]
124
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200125common_services_deploy_opts = [
126 ct.Cfg('common_services_steps_path', ct.String(),
127 help="Path to YAML with steps to deploy common services",
128 default=_default_common_services_steps),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300129]
130
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200131common_services_opts = [
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200132 ct.Cfg('common_services_installed', ct.Boolean(),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200133 help="", default=False),
134]
135
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300136oss_deploy_opts = [
137 ct.Cfg('oss_steps_path', ct.String(),
138 help="Path to YAML with steps to deploy OSS Tools",
139 default=_default_oss_steps),
140]
141
142oss_opts = [
143 ct.Cfg('oss_installed', ct.Boolean(),
144 help="", default=False),
145]
146
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200147openstack_deploy_opts = [
148 ct.Cfg('openstack_steps_path', ct.String(),
149 help="Path to YAML with steps to deploy openstack",
150 default=_default_openstack_steps),
151]
152openstack_opts = [
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200153 ct.Cfg('openstack_installed', ct.Boolean(),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200154 help="", default=False),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200155 ct.Cfg('openstack_keystone_endpoint', ct.String(),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300156 help="", default=''),
157]
158
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200159opencontrail_opts = [
160 ct.Cfg('opencontrail_tags', ct.String(),
161 help="", default=''),
162 ct.Cfg('opencontrail_features', ct.String(),
163 help="", default=''),
164 ct.Cfg('opencontrail_prepare_tests_steps_path', ct.String(),
165 help="Path to YAML with steps to prepare contrail-tests",
166 default=_default_opencontrail_prepare_tests_steps_path),
167]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300168
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300169sl_deploy_opts = [
170 ct.Cfg('sl_steps_path', ct.String(),
171 help="Path to YAML with steps to deploy sl",
172 default=_default_sl_prepare_tests_steps_path),
Tatyana Leontovichf00b2342017-07-04 18:26:25 +0300173 ct.Cfg('docker_image_alertmanager', ct.String(),
174 default='{}/openstack-docker/alertmanager:latest'.format(
175 settings.DOCKER_REGISTRY)),
176 ct.Cfg('docker_image_pushgateway', ct.String(),
177 default='{}/openstack-docker/pushgateway:latest'.format(
178 settings.DOCKER_REGISTRY)),
179 ct.Cfg('docker_image_prometheus', ct.String(),
180 default='{}/openstack-docker/prometheus:latest'.format(
181 settings.DOCKER_REGISTRY)),
182 ct.Cfg('docker_image_remote_agent', ct.String(),
183 default='{}/openstack-docker/telegraf:latest'.format(
184 settings.DOCKER_REGISTRY)),
185 ct.Cfg('docker_image_remote_storage_adapter', ct.String(),
186 default='{}/openstack-docker/remote_storage_adapter:latest'.format(
187 settings.DOCKER_REGISTRY)),
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300188]
Tatyana Leontovichf00b2342017-07-04 18:26:25 +0300189
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300190sl_opts = [
191 ct.Cfg('sl_installed', ct.Boolean(),
192 help="", default=False),
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300193 ct.Cfg('sl_vip_host', ct.IPAddress(),
194 help="Vip address for SL services", default='0.0.0.0'),
195 ct.Cfg('sl_prometheus_port', ct.String(),
196 help="Prometheus port", default='15010'),
197 ct.Cfg('sl_prometheus_proto', ct.String(),
198 help="Proemtheus protocol", default='http'),
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300199]
200
vrovachevbc2f5ce2017-05-22 19:37:24 +0400201virtlet_deploy_opts = [
202 ct.Cfg('virtlet_steps_path', ct.String(),
203 help="Path to YAML with steps to deploy virtlet",
Victor Ryzhenkin655587f2017-05-24 20:00:07 +0400204 default=_default_virtlet_prepare_tests_steps_path),
205 ct.Cfg('virtlet_ceph_steps_path', ct.String(),
206 help="Path to YAML with steps to deploy one-node ceph cluster for "
207 "Virtlet Flexvolumes testing",
208 default=_default_virtlet_ceph_prepare_tests_steps_path)
vrovachevbc2f5ce2017-05-22 19:37:24 +0400209]
210
211virtlet_opts = [
212 ct.Cfg('virtlet_installed', ct.Boolean(),
213 help="", default=False),
Victor Ryzhenkin655587f2017-05-24 20:00:07 +0400214 ct.Cfg('ceph_installed', ct.Boolean(),
215 help="Determine, installed one-node ceph cluster or not",
216 default=False)
vrovachevbc2f5ce2017-05-22 19:37:24 +0400217]
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300218
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300219k8s_deploy_opts = [
Artem Panchenko0594cd72017-06-12 13:25:26 +0300220 ct.Cfg('k8s_steps_path', ct.String(),
221 help="Path to YAML with steps to deploy Kubernetes",
222 default=_default_k8s_steps),
223 ct.Cfg('kubernetes_admin_user', ct.String(), default='admin'),
224 ct.Cfg('kubernetes_admin_password', ct.String(),
225 default='sbPfel23ZigJF3Bm'),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300226 ct.Cfg('kubernetes_docker_package', ct.String(), default=''),
227 ct.Cfg('kubernetes_hyperkube_image', ct.String(),
vrovacheva9d08332017-06-22 20:01:59 +0400228 default='{}/mirantis/kubernetes/hyperkube-amd64:v1.6.4-3'.format(
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300229 settings.DOCKER_REGISTRY)),
230 ct.Cfg('kubernetes_calico_image', ct.String(),
231 default='{}/mirantis/projectcalico/calico/node:latest'.format(
232 settings.DOCKER_REGISTRY)),
233 ct.Cfg('kubernetes_calicoctl_image', ct.String(),
234 default='{}/mirantis/projectcalico/calico/ctl:latest'.format(
235 settings.DOCKER_REGISTRY)),
236 ct.Cfg('kubernetes_calico_cni_image', ct.String(),
237 default='{}/mirantis/projectcalico/calico/cni:latest'.format(
238 settings.DOCKER_REGISTRY)),
Artem Panchenko0594cd72017-06-12 13:25:26 +0300239 ct.Cfg('kubernetes_netchecker_enabled', ct.Boolean(),
240 help="", default=True),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300241 ct.Cfg('kubernetes_netchecker_agent_image', ct.String(),
Tatyana Leontovichf00b2342017-07-04 18:26:25 +0300242 default='mirantis/k8s-netchecker-agent:stable'),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300243 ct.Cfg('kubernetes_netchecker_server_image', ct.String(),
Tatyana Leontovichf00b2342017-07-04 18:26:25 +0300244 default='mirantis/k8s-netchecker-server:stable'),
Artem Panchenko501e67e2017-06-14 14:59:18 +0300245 ct.Cfg('kubernetes_calico_policy_enabled', ct.Boolean(),
246 help="", default=False),
247 ct.Cfg('kubernetes_calico_policy_image', ct.String(),
248 default='calico/kube-policy-controller:v0.5.4'),
249 ct.Cfg('kubernetes_helm_enabled', ct.Boolean(),
250 help="", default=True),
Victor Ryzhenkin0bf0bb02017-07-06 18:57:05 +0400251 ct.Cfg('kubernetes_virtlet_enabled', ct.Boolean(),
252 help="", default=False),
253 ct.Cfg('kubernetes_virtlet_image', ct.String(),
254 help="", default='mirantis/virtlet:latest')
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300255]
256
257k8s_opts = [
Artem Panchenko0594cd72017-06-12 13:25:26 +0300258 ct.Cfg('k8s_installed', ct.Boolean(),
259 help="", default=False),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300260 ct.Cfg('kube_host', ct.IPAddress(),
261 help="", default='0.0.0.0'),
262 ct.Cfg('kube_apiserver_port', ct.Integer(),
263 help="", default=443),
vrovacheva9d08332017-06-22 20:01:59 +0400264 ct.Cfg("k8s_conformance_run", ct.Boolean(),
265 default=False),
266 ct.Cfg('k8s_conformance_image', ct.String(),
267 default='docker-dev-virtual.docker.mirantis.net/mirantis/'
268 'kubernetes/k8s-conformance:v1.6.4-3_1495550936267')
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300269]
270
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300271_group_opts = [
272 ('hardware', hardware_opts),
273 ('underlay', underlay_opts),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200274 ('salt_deploy', salt_deploy_opts),
275 ('salt', salt_opts),
276 ('common_services_deploy', common_services_deploy_opts),
277 ('common_services', common_services_opts),
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300278 ('oss_deploy', oss_deploy_opts),
279 ('oss', oss_opts),
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200280 ('openstack_deploy', openstack_deploy_opts),
281 ('openstack', openstack_opts),
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200282 ('opencontrail', opencontrail_opts),
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300283 ('stack_light', sl_opts),
284 ('sl_deploy', sl_deploy_opts),
vrovachevbc2f5ce2017-05-22 19:37:24 +0400285 ('virtlet_deploy', virtlet_deploy_opts),
286 ('virtlet', virtlet_opts),
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300287 ('k8s_deploy', k8s_deploy_opts),
288 ('k8s', k8s_opts),
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300289]
290
291
292def register_opts(config):
293 config.register_group(cfg.OptGroup(name='hardware',
294 title="Hardware settings", help=""))
295 config.register_opts(group='hardware', opts=hardware_opts)
296
297 config.register_group(cfg.OptGroup(name='underlay',
298 title="Underlay configuration", help=""))
299 config.register_opts(group='underlay', opts=underlay_opts)
300
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200301 config.register_group(cfg.OptGroup(name='salt_deploy',
302 title="salt deploy configuration", help=""))
303 config.register_opts(group='salt_deploy', opts=salt_deploy_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300304
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200305 config.register_group(cfg.OptGroup(name='salt',
306 title="salt config and credentials", help=""))
307 config.register_opts(group='salt', opts=salt_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300308
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200309 config.register_group(cfg.OptGroup(name='common_services',
310 title="Common services for Openstack", help=""))
311 config.register_opts(group='common_services', opts=common_services_opts)
312
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300313 config.register_group(
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200314 cfg.OptGroup(name='common_services_deploy',
315 title="Common services for Openstack deploy config",
316 help=""))
317 config.register_opts(group='common_services_deploy',
318 opts=common_services_deploy_opts)
319
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300320 config.register_group(cfg.OptGroup(name='oss',
321 title="Operational Support System Tools", help=""))
322 config.register_opts(group='oss', opts=oss_opts)
323
324 config.register_group(cfg.OptGroup(name='oss_deploy',
325 title="OSS deploy config", help=""))
326 config.register_opts(group='oss_deploy',
327 opts=oss_deploy_opts)
328
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200329 config.register_group(cfg.OptGroup(name='openstack',
330 title="Openstack config and credentials", help=""))
331 config.register_opts(group='openstack', opts=openstack_opts)
332
333 config.register_group(
334 cfg.OptGroup(name='openstack_deploy',
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300335 title="Openstack deploy config and credentials",
336 help=""))
Dennis Dmitriev6860ba62016-11-01 21:43:46 +0200337 config.register_opts(group='openstack_deploy', opts=openstack_deploy_opts)
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +0200338
339 config.register_group(cfg.OptGroup(name='opencontrail',
340 title="Options for Juniper contrail-tests", help=""))
341 config.register_opts(group='opencontrail', opts=opencontrail_opts)
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300342 config.register_group(cfg.OptGroup(name='stack_light',
343 title="StackLight config and credentials", help=""))
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +0300344 config.register_opts(group='stack_light', opts=sl_opts)
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300345 config.register_group(
346 cfg.OptGroup(name='sl_deploy',
347 title="SL deploy config and credentials",
348 help=""))
349 config.register_opts(group='sl_deploy', opts=sl_deploy_opts)
vrovachevbc2f5ce2017-05-22 19:37:24 +0400350 config.register_group(cfg.OptGroup(name='virtlet_deploy',
351 title='Virtlet deploy config', help=""))
352 config.register_opts(group='virtlet_deploy', opts=virtlet_deploy_opts)
353 config.register_group(cfg.OptGroup(name='virtlet',
354 title='Virtlet config', help=""))
355 config.register_opts(group='virtlet', opts=virtlet_opts)
Artem Panchenkoedf70ef2017-06-13 09:14:34 +0300356
357 config.register_group(cfg.OptGroup(name='k8s_deploy',
358 title="K8s deploy configuration"))
359 config.register_opts(group='k8s_deploy', opts=k8s_deploy_opts)
360
361 config.register_group(cfg.OptGroup(name='k8s',
362 title="K8s config and credentials"))
363 config.register_opts(group='k8s', opts=k8s_opts)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +0300364 return config
365
366
367def load_config(config_files):
368 config = cfg.CONF
369 register_opts(config)
370 config(args=[], default_config_files=config_files)
371 return config
372
373
374def reload_snapshot_config(config, test_config_path):
375 """Reset config to the state from test_config file"""
376 config(args=[], default_config_files=[test_config_path])
377 return config
378
379
380def list_opts():
381 """Return a list of oslo.config options available in the tcp_tests.
382 """
383 return [(group, copy.deepcopy(opts)) for group, opts in _group_opts]
384
385
386def list_current_opts(config):
387 """Return a list of oslo.config options available in the tcp_tests.
388 """
389 result_opts = []
390 for group, opts in _group_opts:
391 current_opts = copy.deepcopy(opts)
392 for opt in current_opts:
393 if hasattr(config, group):
394 if hasattr(config[group], opt.name):
395 opt.default = getattr(config[group], opt.name)
396 result_opts.append((group, current_opts))
397 return result_opts
398
399
400def save_config(config, snapshot_name, env_name=None):
401 if env_name is None:
402 env_name = 'config'
403 test_config_path = os.path.join(
404 settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))
405
406 with open(test_config_path, 'w') as output_file:
407 formatter = generator._OptFormatter(output_file=output_file)
408 for group, opts in list_current_opts(config):
409 formatter.format_group(group)
410 for opt in opts:
411 formatter.format(opt, group, minimal=True)
412 formatter.write('\n')
413 formatter.write('\n')