Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 1 | # 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. |
| 14 | import copy |
| 15 | import os |
| 16 | import pkg_resources |
| 17 | |
| 18 | from oslo_config import cfg |
| 19 | from oslo_config import generator |
| 20 | |
| 21 | from tcp_tests.helpers import ext |
| 22 | from tcp_tests.helpers import oslo_cfg_types as ct |
| 23 | from tcp_tests import settings |
| 24 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 25 | print ("\n" + "-" * 10 + " Initialize oslo.config variables with defaults" |
| 26 | " from environment" + "-" * 10) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 27 | |
| 28 | _default_conf = pkg_resources.resource_filename( |
Dennis Dmitriev | ab83ea4 | 2017-05-12 16:52:45 +0300 | [diff] [blame] | 29 | __name__, 'templates/{0}/underlay.yaml'.format(settings.LAB_CONFIG_NAME)) |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 30 | |
| 31 | _default_salt_steps = pkg_resources.resource_filename( |
Dennis Dmitriev | ab83ea4 | 2017-05-12 16:52:45 +0300 | [diff] [blame] | 32 | __name__, 'templates/{0}/salt.yaml'.format(settings.LAB_CONFIG_NAME)) |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 33 | _default_common_services_steps = pkg_resources.resource_filename( |
| 34 | __name__, |
Dennis Dmitriev | ab83ea4 | 2017-05-12 16:52:45 +0300 | [diff] [blame] | 35 | 'templates/{0}/common-services.yaml'.format( |
Dennis Dmitriev | 2a13a13 | 2016-11-04 00:56:23 +0200 | [diff] [blame] | 36 | settings.LAB_CONFIG_NAME)) |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 37 | _default_openstack_steps = pkg_resources.resource_filename( |
Dennis Dmitriev | ab83ea4 | 2017-05-12 16:52:45 +0300 | [diff] [blame] | 38 | __name__, 'templates/{0}/openstack.yaml'.format( |
Dennis Dmitriev | 2a13a13 | 2016-11-04 00:56:23 +0200 | [diff] [blame] | 39 | settings.LAB_CONFIG_NAME)) |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 40 | _default_opencontrail_prepare_tests_steps_path = pkg_resources.resource_filename( |
Dennis Dmitriev | ab83ea4 | 2017-05-12 16:52:45 +0300 | [diff] [blame] | 41 | __name__, 'templates/{0}/opencontrail.yaml'.format( |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 42 | settings.LAB_CONFIG_NAME)) |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 43 | _default_sl_prepare_tests_steps_path = pkg_resources.resource_filename( |
| 44 | __name__, 'templates/{0}/sl.yaml'.format( |
| 45 | settings.LAB_CONFIG_NAME)) |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 46 | _default_virtlet_prepare_tests_steps_path = pkg_resources.resource_filename( |
| 47 | __name__, 'templates/{0}/virtlet.yaml'.format( |
| 48 | settings.LAB_CONFIG_NAME)) |
Victor Ryzhenkin | 655587f | 2017-05-24 20:00:07 +0400 | [diff] [blame] | 49 | _default_virtlet_ceph_prepare_tests_steps_path = pkg_resources.resource_filename( |
| 50 | __name__, 'templates/{0}/virtlet_ceph.yaml'.format( |
| 51 | settings.LAB_CONFIG_NAME)) |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 52 | _default_k8s_steps = pkg_resources.resource_filename( |
| 53 | __name__, 'templates/{0}/k8s.yaml'.format( |
| 54 | settings.LAB_CONFIG_NAME)) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 55 | |
| 56 | hardware_opts = [ |
| 57 | ct.Cfg('manager', ct.String(), |
| 58 | help="Hardware manager name", default="devops"), |
| 59 | ct.Cfg('conf_path', ct.String(), |
| 60 | help="Hardware config file", default=_default_conf), |
| 61 | ct.Cfg('current_snapshot', ct.String(), |
| 62 | help="Latest environment status name", |
| 63 | default=ext.SNAPSHOT.hardware), |
| 64 | ] |
| 65 | |
| 66 | |
| 67 | underlay_opts = [ |
| 68 | ct.Cfg('ssh', ct.JSONList(), |
| 69 | help="""SSH Settings for Underlay: [{ |
| 70 | 'node_name': node1, |
Dennis Dmitriev | 23e5d19 | 2016-10-31 11:27:10 +0200 | [diff] [blame] | 71 | 'roles': ['salt-master', 'salt-minion', ], |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 72 | 'host': hostname, |
| 73 | 'login': login, |
| 74 | 'password': password, |
| 75 | 'address_pool': (optional), |
| 76 | 'port': (optional), |
| 77 | 'keys': [(optional)], |
| 78 | }, ...]""", default=[]), |
| 79 | ct.Cfg('roles', ct.JSONList(), |
| 80 | help="Node roles managed by underlay in the environment", |
Dennis Dmitriev | 53d3b77 | 2016-10-18 14:31:58 +0300 | [diff] [blame] | 81 | default=[ext.UNDERLAY_NODE_ROLES.salt_master, |
vrovachev | 99228d3 | 2017-06-08 19:46:10 +0400 | [diff] [blame] | 82 | ext.UNDERLAY_NODE_ROLES.salt_minion, |
| 83 | ext.UNDERLAY_NODE_ROLES.k8s_virtlet, ]), |
Dennis Dmitriev | 7b9538f | 2017-05-15 17:01:34 +0300 | [diff] [blame] | 84 | ct.Cfg('bootstrap_timeout', ct.Integer(), |
| 85 | help="Timeout of waiting SSH for nodes with specified roles", |
| 86 | default=480), |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 87 | ct.Cfg('nameservers', ct.JSONList(), |
| 88 | help="IP addresses of DNS servers", |
| 89 | default=[]), |
| 90 | ct.Cfg('upstream_dns_servers', ct.JSONList(), |
| 91 | help="IP addresses of upstream DNS servers (dnsmasq)", |
| 92 | default=[]), |
| 93 | ct.Cfg('lvm', ct.JSONDict(), |
| 94 | help="LVM settings for Underlay", default={}), |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 95 | ct.Cfg('address_pools', ct.JSONDict(), |
| 96 | help="""Address pools (dynamically) allocated for the environment. |
| 97 | May be used to determine CIDR for a specific network from |
| 98 | tests or during the deployment process. |
| 99 | {'pool_name1': '<cidr>', 'pool_name2': '<cidr>', ...}""", |
| 100 | default={}), |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 101 | ] |
| 102 | |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 103 | |
| 104 | salt_deploy_opts = [ |
| 105 | ct.Cfg('salt_steps_path', ct.String(), |
| 106 | help="Path to YAML with steps to deploy salt", |
| 107 | default=_default_salt_steps), |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 108 | ] |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 109 | salt_opts = [ |
| 110 | ct.Cfg('salt_master_host', ct.IPAddress(), |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 111 | help="", default='0.0.0.0'), |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 112 | ct.Cfg('salt_master_port', ct.String(), |
| 113 | help="", default='6969'), |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 114 | ] |
| 115 | |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 116 | common_services_deploy_opts = [ |
| 117 | ct.Cfg('common_services_steps_path', ct.String(), |
| 118 | help="Path to YAML with steps to deploy common services", |
| 119 | default=_default_common_services_steps), |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 120 | ] |
| 121 | |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 122 | common_services_opts = [ |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 123 | ct.Cfg('common_services_installed', ct.Boolean(), |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 124 | help="", default=False), |
| 125 | ] |
| 126 | |
| 127 | openstack_deploy_opts = [ |
| 128 | ct.Cfg('openstack_steps_path', ct.String(), |
| 129 | help="Path to YAML with steps to deploy openstack", |
| 130 | default=_default_openstack_steps), |
| 131 | ] |
| 132 | openstack_opts = [ |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 133 | ct.Cfg('openstack_installed', ct.Boolean(), |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 134 | help="", default=False), |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 135 | ct.Cfg('openstack_keystone_endpoint', ct.String(), |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 136 | help="", default=''), |
| 137 | ] |
| 138 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 139 | opencontrail_opts = [ |
| 140 | ct.Cfg('opencontrail_tags', ct.String(), |
| 141 | help="", default=''), |
| 142 | ct.Cfg('opencontrail_features', ct.String(), |
| 143 | help="", default=''), |
| 144 | ct.Cfg('opencontrail_prepare_tests_steps_path', ct.String(), |
| 145 | help="Path to YAML with steps to prepare contrail-tests", |
| 146 | default=_default_opencontrail_prepare_tests_steps_path), |
| 147 | ] |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 148 | |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 149 | sl_deploy_opts = [ |
| 150 | ct.Cfg('sl_steps_path', ct.String(), |
| 151 | help="Path to YAML with steps to deploy sl", |
| 152 | default=_default_sl_prepare_tests_steps_path), |
| 153 | ] |
| 154 | sl_opts = [ |
| 155 | ct.Cfg('sl_installed', ct.Boolean(), |
| 156 | help="", default=False), |
| 157 | ] |
| 158 | |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 159 | virtlet_deploy_opts = [ |
| 160 | ct.Cfg('virtlet_steps_path', ct.String(), |
| 161 | help="Path to YAML with steps to deploy virtlet", |
Victor Ryzhenkin | 655587f | 2017-05-24 20:00:07 +0400 | [diff] [blame] | 162 | default=_default_virtlet_prepare_tests_steps_path), |
| 163 | ct.Cfg('virtlet_ceph_steps_path', ct.String(), |
| 164 | help="Path to YAML with steps to deploy one-node ceph cluster for " |
| 165 | "Virtlet Flexvolumes testing", |
| 166 | default=_default_virtlet_ceph_prepare_tests_steps_path) |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 167 | ] |
| 168 | |
| 169 | virtlet_opts = [ |
| 170 | ct.Cfg('virtlet_installed', ct.Boolean(), |
| 171 | help="", default=False), |
Victor Ryzhenkin | 655587f | 2017-05-24 20:00:07 +0400 | [diff] [blame] | 172 | ct.Cfg('ceph_installed', ct.Boolean(), |
| 173 | help="Determine, installed one-node ceph cluster or not", |
| 174 | default=False) |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 175 | ] |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 176 | |
Artem Panchenko | edf70ef | 2017-06-13 09:14:34 +0300 | [diff] [blame] | 177 | k8s_deploy_opts = [ |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 178 | ct.Cfg('k8s_steps_path', ct.String(), |
| 179 | help="Path to YAML with steps to deploy Kubernetes", |
| 180 | default=_default_k8s_steps), |
| 181 | ct.Cfg('kubernetes_admin_user', ct.String(), default='admin'), |
| 182 | ct.Cfg('kubernetes_admin_password', ct.String(), |
| 183 | default='sbPfel23ZigJF3Bm'), |
Artem Panchenko | edf70ef | 2017-06-13 09:14:34 +0300 | [diff] [blame] | 184 | ct.Cfg('kubernetes_docker_package', ct.String(), default=''), |
| 185 | ct.Cfg('kubernetes_hyperkube_image', ct.String(), |
| 186 | default='{}/mirantis/kubernetes/hyperkube-amd64:v1.6.2-2'.format( |
| 187 | settings.DOCKER_REGISTRY)), |
| 188 | ct.Cfg('kubernetes_calico_image', ct.String(), |
| 189 | default='{}/mirantis/projectcalico/calico/node:latest'.format( |
| 190 | settings.DOCKER_REGISTRY)), |
| 191 | ct.Cfg('kubernetes_calicoctl_image', ct.String(), |
| 192 | default='{}/mirantis/projectcalico/calico/ctl:latest'.format( |
| 193 | settings.DOCKER_REGISTRY)), |
| 194 | ct.Cfg('kubernetes_calico_cni_image', ct.String(), |
| 195 | default='{}/mirantis/projectcalico/calico/cni:latest'.format( |
| 196 | settings.DOCKER_REGISTRY)), |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 197 | ct.Cfg('kubernetes_netchecker_enabled', ct.Boolean(), |
| 198 | help="", default=True), |
Artem Panchenko | edf70ef | 2017-06-13 09:14:34 +0300 | [diff] [blame] | 199 | ct.Cfg('kubernetes_netchecker_agent_image', ct.String(), |
| 200 | default='mirantis/k8s-netchecker-agent:latest'), |
| 201 | ct.Cfg('kubernetes_netchecker_server_image', ct.String(), |
| 202 | default='mirantis/k8s-netchecker-server:latest'), |
| 203 | ] |
| 204 | |
| 205 | k8s_opts = [ |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 206 | ct.Cfg('k8s_installed', ct.Boolean(), |
| 207 | help="", default=False), |
Artem Panchenko | edf70ef | 2017-06-13 09:14:34 +0300 | [diff] [blame] | 208 | ct.Cfg('kube_host', ct.IPAddress(), |
| 209 | help="", default='0.0.0.0'), |
| 210 | ct.Cfg('kube_apiserver_port', ct.Integer(), |
| 211 | help="", default=443), |
| 212 | ] |
| 213 | |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 214 | _group_opts = [ |
| 215 | ('hardware', hardware_opts), |
| 216 | ('underlay', underlay_opts), |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 217 | ('salt_deploy', salt_deploy_opts), |
| 218 | ('salt', salt_opts), |
| 219 | ('common_services_deploy', common_services_deploy_opts), |
| 220 | ('common_services', common_services_opts), |
| 221 | ('openstack_deploy', openstack_deploy_opts), |
| 222 | ('openstack', openstack_opts), |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 223 | ('opencontrail', opencontrail_opts), |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 224 | ('stack_light', sl_opts), |
| 225 | ('sl_deploy', sl_deploy_opts), |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 226 | ('virtlet_deploy', virtlet_deploy_opts), |
| 227 | ('virtlet', virtlet_opts), |
Artem Panchenko | edf70ef | 2017-06-13 09:14:34 +0300 | [diff] [blame] | 228 | ('k8s_deploy', k8s_deploy_opts), |
| 229 | ('k8s', k8s_opts), |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 230 | ] |
| 231 | |
| 232 | |
| 233 | def register_opts(config): |
| 234 | config.register_group(cfg.OptGroup(name='hardware', |
| 235 | title="Hardware settings", help="")) |
| 236 | config.register_opts(group='hardware', opts=hardware_opts) |
| 237 | |
| 238 | config.register_group(cfg.OptGroup(name='underlay', |
| 239 | title="Underlay configuration", help="")) |
| 240 | config.register_opts(group='underlay', opts=underlay_opts) |
| 241 | |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 242 | config.register_group(cfg.OptGroup(name='salt_deploy', |
| 243 | title="salt deploy configuration", help="")) |
| 244 | config.register_opts(group='salt_deploy', opts=salt_deploy_opts) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 245 | |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 246 | config.register_group(cfg.OptGroup(name='salt', |
| 247 | title="salt config and credentials", help="")) |
| 248 | config.register_opts(group='salt', opts=salt_opts) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 249 | |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 250 | config.register_group(cfg.OptGroup(name='common_services', |
| 251 | title="Common services for Openstack", help="")) |
| 252 | config.register_opts(group='common_services', opts=common_services_opts) |
| 253 | |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 254 | config.register_group( |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 255 | cfg.OptGroup(name='common_services_deploy', |
| 256 | title="Common services for Openstack deploy config", |
| 257 | help="")) |
| 258 | config.register_opts(group='common_services_deploy', |
| 259 | opts=common_services_deploy_opts) |
| 260 | |
| 261 | config.register_group(cfg.OptGroup(name='openstack', |
| 262 | title="Openstack config and credentials", help="")) |
| 263 | config.register_opts(group='openstack', opts=openstack_opts) |
| 264 | |
| 265 | config.register_group( |
| 266 | cfg.OptGroup(name='openstack_deploy', |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 267 | title="Openstack deploy config and credentials", |
| 268 | help="")) |
Dennis Dmitriev | 6860ba6 | 2016-11-01 21:43:46 +0200 | [diff] [blame] | 269 | config.register_opts(group='openstack_deploy', opts=openstack_deploy_opts) |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 270 | |
| 271 | config.register_group(cfg.OptGroup(name='opencontrail', |
| 272 | title="Options for Juniper contrail-tests", help="")) |
| 273 | config.register_opts(group='opencontrail', opts=opencontrail_opts) |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 274 | config.register_group(cfg.OptGroup(name='stack_light', |
| 275 | title="StackLight config and credentials", help="")) |
Tatyana Leontovich | 5acc82a | 2017-05-23 15:41:35 +0300 | [diff] [blame] | 276 | config.register_opts(group='stack_light', opts=sl_opts) |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 277 | config.register_group( |
| 278 | cfg.OptGroup(name='sl_deploy', |
| 279 | title="SL deploy config and credentials", |
| 280 | help="")) |
| 281 | config.register_opts(group='sl_deploy', opts=sl_deploy_opts) |
vrovachev | bc2f5ce | 2017-05-22 19:37:24 +0400 | [diff] [blame] | 282 | config.register_group(cfg.OptGroup(name='virtlet_deploy', |
| 283 | title='Virtlet deploy config', help="")) |
| 284 | config.register_opts(group='virtlet_deploy', opts=virtlet_deploy_opts) |
| 285 | config.register_group(cfg.OptGroup(name='virtlet', |
| 286 | title='Virtlet config', help="")) |
| 287 | config.register_opts(group='virtlet', opts=virtlet_opts) |
Artem Panchenko | edf70ef | 2017-06-13 09:14:34 +0300 | [diff] [blame] | 288 | |
| 289 | config.register_group(cfg.OptGroup(name='k8s_deploy', |
| 290 | title="K8s deploy configuration")) |
| 291 | config.register_opts(group='k8s_deploy', opts=k8s_deploy_opts) |
| 292 | |
| 293 | config.register_group(cfg.OptGroup(name='k8s', |
| 294 | title="K8s config and credentials")) |
| 295 | config.register_opts(group='k8s', opts=k8s_opts) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 296 | return config |
| 297 | |
| 298 | |
| 299 | def load_config(config_files): |
| 300 | config = cfg.CONF |
| 301 | register_opts(config) |
| 302 | config(args=[], default_config_files=config_files) |
| 303 | return config |
| 304 | |
| 305 | |
| 306 | def reload_snapshot_config(config, test_config_path): |
| 307 | """Reset config to the state from test_config file""" |
| 308 | config(args=[], default_config_files=[test_config_path]) |
| 309 | return config |
| 310 | |
| 311 | |
| 312 | def list_opts(): |
| 313 | """Return a list of oslo.config options available in the tcp_tests. |
| 314 | """ |
| 315 | return [(group, copy.deepcopy(opts)) for group, opts in _group_opts] |
| 316 | |
| 317 | |
| 318 | def list_current_opts(config): |
| 319 | """Return a list of oslo.config options available in the tcp_tests. |
| 320 | """ |
| 321 | result_opts = [] |
| 322 | for group, opts in _group_opts: |
| 323 | current_opts = copy.deepcopy(opts) |
| 324 | for opt in current_opts: |
| 325 | if hasattr(config, group): |
| 326 | if hasattr(config[group], opt.name): |
| 327 | opt.default = getattr(config[group], opt.name) |
| 328 | result_opts.append((group, current_opts)) |
| 329 | return result_opts |
| 330 | |
| 331 | |
| 332 | def save_config(config, snapshot_name, env_name=None): |
| 333 | if env_name is None: |
| 334 | env_name = 'config' |
| 335 | test_config_path = os.path.join( |
| 336 | settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name)) |
| 337 | |
| 338 | with open(test_config_path, 'w') as output_file: |
| 339 | formatter = generator._OptFormatter(output_file=output_file) |
| 340 | for group, opts in list_current_opts(config): |
| 341 | formatter.format_group(group) |
| 342 | for opt in opts: |
| 343 | formatter.format(opt, group, minimal=True) |
| 344 | formatter.write('\n') |
| 345 | formatter.write('\n') |