blob: 6c818f2cc8b41ad880c6c79bc9c50d935b9bc538 [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(
27 __name__, 'templates/default.yaml')
28
29
30hardware_opts = [
31 ct.Cfg('manager', ct.String(),
32 help="Hardware manager name", default="devops"),
33 ct.Cfg('conf_path', ct.String(),
34 help="Hardware config file", default=_default_conf),
35 ct.Cfg('current_snapshot', ct.String(),
36 help="Latest environment status name",
37 default=ext.SNAPSHOT.hardware),
38]
39
40
41underlay_opts = [
42 ct.Cfg('ssh', ct.JSONList(),
43 help="""SSH Settings for Underlay: [{
44 'node_name': node1,
45 'host': hostname,
46 'login': login,
47 'password': password,
48 'address_pool': (optional),
49 'port': (optional),
50 'keys': [(optional)],
51 }, ...]""", default=[]),
52 ct.Cfg('roles', ct.JSONList(),
53 help="Node roles managed by underlay in the environment",
54 default=[ext.UNDERLAY_NODE_ROLE.salt-master,
55 ext.UNDERLAY_NODE_ROLE.salt-minion, ]),
56 ct.Cfg('nameservers', ct.JSONList(),
57 help="IP addresses of DNS servers",
58 default=[]),
59 ct.Cfg('upstream_dns_servers', ct.JSONList(),
60 help="IP addresses of upstream DNS servers (dnsmasq)",
61 default=[]),
62 ct.Cfg('lvm', ct.JSONDict(),
63 help="LVM settings for Underlay", default={}),
64]
65
66# Deploy options for a new TCPCloud deployment
67tcp_deploy_opts = [
68 ct.Cfg('reclass_settings', ct.JSONDict(),
69 help="", default={}),
70]
71
72
73# Access credentials to a ready TCP cluster
74tcp_opts = [
75 ct.Cfg('tcp_host', ct.IPAddress(),
76 help="", default='0.0.0.0'),
77]
78
79
80os_deploy_opts = [
81 # ct.Cfg('stacklight_enable', ct.Boolean(),
82 # help="", default=False),
83]
84
85os_opts = [
86 ct.Cfg('keystone_endpoint', ct.String(),
87 help="", default=''),
88]
89
90
91_group_opts = [
92 ('hardware', hardware_opts),
93 ('underlay', underlay_opts),
94 ('tcp_deploy', tcp_deploy_opts),
95 ('tcp', tcp_opts),
96 ('os_deploy', os_deploy_opts),
97 ('os', os_opts),
98]
99
100
101def register_opts(config):
102 config.register_group(cfg.OptGroup(name='hardware',
103 title="Hardware settings", help=""))
104 config.register_opts(group='hardware', opts=hardware_opts)
105
106 config.register_group(cfg.OptGroup(name='underlay',
107 title="Underlay configuration", help=""))
108 config.register_opts(group='underlay', opts=underlay_opts)
109
110 config.register_group(cfg.OptGroup(name='tcp_deploy',
111 title="tcp deploy configuration", help=""))
112 config.register_opts(group='tcp_deploy', opts=tcp_deploy_opts)
113
114 config.register_group(cfg.OptGroup(name='tcp',
115 title="tcp config and credentials", help=""))
116 config.register_opts(group='tcp', opts=tcp_opts)
117
118 config.register_group(cfg.OptGroup(name='os',
119 title="Openstack config and credentials", help=""))
120 config.register_opts(group='os', opts=os_opts)
121 config.register_group(
122 cfg.OptGroup(name='os_deploy',
123 title="Openstack deploy config and credentials",
124 help=""))
125 config.register_opts(group='os_deploy', opts=os_deploy_opts)
126 return config
127
128
129def load_config(config_files):
130 config = cfg.CONF
131 register_opts(config)
132 config(args=[], default_config_files=config_files)
133 return config
134
135
136def reload_snapshot_config(config, test_config_path):
137 """Reset config to the state from test_config file"""
138 config(args=[], default_config_files=[test_config_path])
139 return config
140
141
142def list_opts():
143 """Return a list of oslo.config options available in the tcp_tests.
144 """
145 return [(group, copy.deepcopy(opts)) for group, opts in _group_opts]
146
147
148def list_current_opts(config):
149 """Return a list of oslo.config options available in the tcp_tests.
150 """
151 result_opts = []
152 for group, opts in _group_opts:
153 current_opts = copy.deepcopy(opts)
154 for opt in current_opts:
155 if hasattr(config, group):
156 if hasattr(config[group], opt.name):
157 opt.default = getattr(config[group], opt.name)
158 result_opts.append((group, current_opts))
159 return result_opts
160
161
162def save_config(config, snapshot_name, env_name=None):
163 if env_name is None:
164 env_name = 'config'
165 test_config_path = os.path.join(
166 settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))
167
168 with open(test_config_path, 'w') as output_file:
169 formatter = generator._OptFormatter(output_file=output_file)
170 for group, opts in list_current_opts(config):
171 formatter.format_group(group)
172 for opt in opts:
173 formatter.format(opt, group, minimal=True)
174 formatter.write('\n')
175 formatter.write('\n')