blob: 235d8e3e66b44b953f70b37474c09b13cae6ddd0 [file] [log] [blame]
Matthew Treinish1f7b33d2013-10-21 18:07:02 +00001#!/usr/bin/env python
Matthew Treinish1f7b33d2013-10-21 18:07:02 +00002
3# Copyright 2013 IBM Corp.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
Martin Kopecbd9dd8e2017-06-28 20:52:18 +000017"""
18Verifies user's current tempest configuration.
19
20This command is used for updating or user's tempest configuration file based on
21api queries or replacing all option in a tempest configuration file for a full
22list of extensions.
23
24General Options
25===============
26
27-u, --update
28------------
29Update the config file with results from api queries. This assumes whatever is
30set in the config file is incorrect.
31
32-o FILE, --output=FILE
33----------------------
34Output file to write an updated config file to. This has to be a separate file
35from the original one. If one isn't specified with -u the values which should
36be changed will be printed to STDOUT.
37
38-r, --replace-ext
39-----------------
40If specified the all option will be replaced with a full list of extensions.
41
42Environment Variables
43=====================
44
45The command is workspace aware - it uses tempest config file tempest.conf
46located in ./etc/ directory.
47The path to the config file and it's name can be changed through environment
48variables.
49
50TEMPEST_CONFIG_DIR
51------------------
52Path to a directory where tempest configuration file is stored. If the variable
53is set, the default path (./etc/) is overridden.
54
55TEMPEST_CONFIG
56--------------
57Name of a tempest configuration file. If the variable is specified, the default
58name (tempest.conf) is overridden.
59
60"""
61
Matthew Treinishf0971712014-04-11 20:08:53 +000062import argparse
Andreas Jaeger2f273242020-05-05 13:27:32 +020063import configparser
Matthew Treinishf0971712014-04-11 20:08:53 +000064import os
Brant Knudson28de8d52016-03-18 13:50:02 -050065import re
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000066import sys
David Patersone45aa842015-11-18 16:12:27 -080067import traceback
Andreas Jaeger2f273242020-05-05 13:27:32 +020068from urllib import parse as urlparse
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000069
David Patersone45aa842015-11-18 16:12:27 -080070from cliff import command
71from oslo_log import log as logging
Matthew Treinish21905512015-07-13 10:33:35 -040072from oslo_serialization import jsonutils as json
Matthew Treinish4f30eb82014-01-07 21:04:49 +000073
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000074from tempest import clients
Andrea Frittoli (andreaf)290b3e12015-10-08 10:25:02 +010075from tempest.common import credentials_factory as credentials
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000076from tempest import config
Jordan Pittier00f25962016-03-18 17:10:07 +010077import tempest.lib.common.http
Andrea Frittolib33dd462017-07-21 10:14:25 +010078from tempest.lib import exceptions as lib_exc
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000079
80
Sean Dague86bd8422013-12-20 09:56:44 -050081CONF = config.CONF
David Kranzf20ac322014-05-02 16:46:15 -040082CONF_PARSER = None
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000083
David Patersone45aa842015-11-18 16:12:27 -080084LOG = logging.getLogger(__name__)
85
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000086
Matthew Treinishf0971712014-04-11 20:08:53 +000087def _get_config_file():
Martin Kopecbd9dd8e2017-06-28 20:52:18 +000088 config_dir = os.getcwd()
89 default_config_dir = os.path.join(config_dir, "etc")
Matthew Treinishf0971712014-04-11 20:08:53 +000090 default_config_file = "tempest.conf"
91
92 conf_dir = os.environ.get('TEMPEST_CONFIG_DIR', default_config_dir)
93 conf_file = os.environ.get('TEMPEST_CONFIG', default_config_file)
94 path = os.path.join(conf_dir, conf_file)
Sirushti Murugesan12dc9732016-07-13 22:49:17 +053095 fd = open(path, 'r+')
Matthew Treinishf0971712014-04-11 20:08:53 +000096 return fd
97
98
99def change_option(option, group, value):
David Kranzf20ac322014-05-02 16:46:15 -0400100 if not CONF_PARSER.has_section(group):
101 CONF_PARSER.add_section(group)
102 CONF_PARSER.set(group, option, str(value))
Matthew Treinishf0971712014-04-11 20:08:53 +0000103
104
105def print_and_or_update(option, group, value, update):
106 print('Config option %s in group %s should be changed to: %s'
107 % (option, group, value))
108 if update:
109 change_option(option, group, value)
110
111
David Kranz0df154d2015-06-02 17:02:27 -0400112def contains_version(prefix, versions):
113 return any([x for x in versions if x.startswith(prefix)])
114
115
Matthew Treinishf0971712014-04-11 20:08:53 +0000116def verify_glance_api_versions(os, update):
Matthew Treinish99afd072013-10-22 18:03:06 +0000117 # Check glance api versions
Andrea Frittolib33dd462017-07-21 10:14:25 +0100118 # Since we want to verify that the configuration is correct, we cannot
119 # rely on a specific version of the API being available.
120 try:
121 _, versions = os.image_v1.ImagesClient().get_versions()
122 except lib_exc.NotFound:
123 # If not found, we use v2. The assumption is that either v1 or v2
124 # are available, since glance is marked as available in the catalog.
125 # If not, glance should be disabled in Tempest conf.
126 try:
127 versions = os.image_v2.VersionsClient().list_versions()['versions']
128 versions = [x['id'] for x in versions]
129 except lib_exc.NotFound:
130 msg = ('Glance is available in the catalog, but no known version, '
131 '(v1.x or v2.x) of Glance could be found, so Glance should '
132 'be configured as not available')
133 LOG.warn(msg)
134 print_and_or_update('glance', 'service-available', False, update)
135 return
136
David Kranz0df154d2015-06-02 17:02:27 -0400137 if CONF.image_feature_enabled.api_v1 != contains_version('v1.', versions):
Nikita Gerasimov35fbdc12015-08-07 19:58:24 +0300138 print_and_or_update('api_v1', 'image-feature-enabled',
Matthew Treinishf0971712014-04-11 20:08:53 +0000139 not CONF.image_feature_enabled.api_v1, update)
David Kranz0df154d2015-06-02 17:02:27 -0400140 if CONF.image_feature_enabled.api_v2 != contains_version('v2.', versions):
Nikita Gerasimov35fbdc12015-08-07 19:58:24 +0300141 print_and_or_update('api_v2', 'image-feature-enabled',
Matthew Treinishf0971712014-04-11 20:08:53 +0000142 not CONF.image_feature_enabled.api_v2, update)
Matthew Treinish99afd072013-10-22 18:03:06 +0000143
144
Brant Knudson28de8d52016-03-18 13:50:02 -0500145def _remove_version_project(url_path):
146 # The regex matches strings like /v2.0, /v3/, /v2.1/project-id/
147 return re.sub(r'/v\d+(\.\d+)?(/[^/]+)?', '', url_path)
148
149
Matthew Treinish9b896242014-04-23 21:25:27 +0000150def _get_unversioned_endpoint(base_url):
151 endpoint_parts = urlparse.urlparse(base_url)
Brant Knudson28de8d52016-03-18 13:50:02 -0500152 new_path = _remove_version_project(endpoint_parts.path)
153 endpoint_parts = endpoint_parts._replace(path=new_path)
154 endpoint = urlparse.urlunparse(endpoint_parts)
Matthew Treinish9b896242014-04-23 21:25:27 +0000155 return endpoint
156
157
Matthew Treinish864fe072014-03-02 03:47:26 +0000158def _get_api_versions(os, service):
Andrea Frittolib33dd462017-07-21 10:14:25 +0100159 # Clients are used to obtain the base_url. Each client applies the
160 # appropriate filters to the catalog to extract a base_url which
161 # matches the configured region and endpoint_type.
162 # The base URL is used to obtain the list of versions available.
Matthew Treinish864fe072014-03-02 03:47:26 +0000163 client_dict = {
Andrea Frittolib33dd462017-07-21 10:14:25 +0100164 'nova': os.compute.ServersClient(),
165 'keystone': os.identity_v3.IdentityClient(
166 endpoint_type=CONF.identity.v3_endpoint_type),
167 'cinder': os.volume_v3.VolumesClient(),
Matthew Treinish864fe072014-03-02 03:47:26 +0000168 }
Ivan Kolodyazhnyb24f9042017-06-12 18:54:18 +0300169 if service != 'keystone' and service != 'cinder':
170 # Since keystone and cinder may be listening on a path,
171 # do not remove the path.
Brant Knudson28de8d52016-03-18 13:50:02 -0500172 client_dict[service].skip_path()
Matthew Treinish9b896242014-04-23 21:25:27 +0000173 endpoint = _get_unversioned_endpoint(client_dict[service].base_url)
Jordan Pittier00f25962016-03-18 17:10:07 +0100174
175 http = tempest.lib.common.http.ClosingHttp(
Daniel Melladocad3f3d2016-08-19 14:17:16 +0000176 CONF.identity.disable_ssl_certificate_validation,
177 CONF.identity.ca_certificates_file)
Jordan Pittier00f25962016-03-18 17:10:07 +0100178
179 __, body = http.request(endpoint, 'GET')
Matthew Treinish864fe072014-03-02 03:47:26 +0000180 client_dict[service].reset_path()
Brant Knudson5a59f872016-03-18 13:07:00 -0500181 try:
182 body = json.loads(body)
183 except ValueError:
184 LOG.error(
185 'Failed to get a JSON response from unversioned endpoint %s '
186 '(versioned endpoint was %s). Response is:\n%s',
187 endpoint, client_dict[service].base_url, body[:100])
188 raise
Matthew Treinish864fe072014-03-02 03:47:26 +0000189 if service == 'keystone':
190 versions = map(lambda x: x['id'], body['versions']['values'])
191 else:
192 versions = map(lambda x: x['id'], body['versions'])
Matthew Treinish09487242015-05-10 12:43:58 -0400193 return list(versions)
Matthew Treinish864fe072014-03-02 03:47:26 +0000194
195
Matthew Treinishf0971712014-04-11 20:08:53 +0000196def verify_keystone_api_versions(os, update):
Matthew Treinish864fe072014-03-02 03:47:26 +0000197 # Check keystone api versions
198 versions = _get_api_versions(os, 'keystone')
David Kranz0df154d2015-06-02 17:02:27 -0400199 if (CONF.identity_feature_enabled.api_v3 !=
200 contains_version('v3.', versions)):
Nikita Gerasimov35fbdc12015-08-07 19:58:24 +0300201 print_and_or_update('api_v3', 'identity-feature-enabled',
Matthew Treinishf0971712014-04-11 20:08:53 +0000202 not CONF.identity_feature_enabled.api_v3, update)
Matthew Treinish864fe072014-03-02 03:47:26 +0000203
204
Matthew Treinishf0971712014-04-11 20:08:53 +0000205def verify_cinder_api_versions(os, update):
Matthew Treinish2e439632014-03-05 21:53:33 +0000206 # Check cinder api versions
207 versions = _get_api_versions(os, 'cinder')
David Kranz0df154d2015-06-02 17:02:27 -0400208 if (CONF.volume_feature_enabled.api_v2 !=
209 contains_version('v2.', versions)):
Nikita Gerasimov35fbdc12015-08-07 19:58:24 +0300210 print_and_or_update('api_v2', 'volume-feature-enabled',
Matthew Treinishf0971712014-04-11 20:08:53 +0000211 not CONF.volume_feature_enabled.api_v2, update)
Nikita Gerasimov3b169cc2016-08-10 17:10:42 +0300212 if (CONF.volume_feature_enabled.api_v3 !=
213 contains_version('v3.', versions)):
214 print_and_or_update('api_v3', 'volume-feature-enabled',
215 not CONF.volume_feature_enabled.api_v3, update)
Matthew Treinish2e439632014-03-05 21:53:33 +0000216
217
Adam Gandelman03af5562014-10-07 12:22:48 -0700218def verify_api_versions(os, service, update):
219 verify = {
220 'cinder': verify_cinder_api_versions,
221 'glance': verify_glance_api_versions,
222 'keystone': verify_keystone_api_versions,
Adam Gandelman03af5562014-10-07 12:22:48 -0700223 }
224 if service not in verify:
225 return
226 verify[service](os, update)
227
228
Matthew Treinish8b006d22014-01-07 15:37:20 +0000229def get_extension_client(os, service):
230 extensions_client = {
Andrea Frittolib33dd462017-07-21 10:14:25 +0100231 'nova': os.compute.ExtensionsClient(),
232 'neutron': os.network.ExtensionsClient(),
Andrea Frittoli986407d2017-10-11 10:23:17 +0000233 'swift': os.object_storage.CapabilitiesClient(),
Ken'ichi Ohmichi8b876dd2017-05-04 14:30:31 -0700234 # NOTE: Cinder v3 API is current and v2 and v1 are deprecated.
235 # V3 extension API is the same as v2, so we reuse the v2 client
236 # for v3 API also.
Andrea Frittolib33dd462017-07-21 10:14:25 +0100237 'cinder': os.volume_v2.ExtensionsClient(),
Matthew Treinish8b006d22014-01-07 15:37:20 +0000238 }
Ivan Kolodyazhnybcfc32e2015-08-06 13:31:36 +0300239
Matthew Treinish8b006d22014-01-07 15:37:20 +0000240 if service not in extensions_client:
241 print('No tempest extensions client for %s' % service)
caoyueab333022016-01-25 16:45:21 +0800242 sys.exit(1)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000243 return extensions_client[service]
244
245
246def get_enabled_extensions(service):
247 extensions_options = {
248 'nova': CONF.compute_feature_enabled.api_extensions,
Matthew Treinish8b006d22014-01-07 15:37:20 +0000249 'cinder': CONF.volume_feature_enabled.api_extensions,
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000250 'neutron': CONF.network_feature_enabled.api_extensions,
Matthew Treinishc0120ba2014-01-31 20:10:19 +0000251 'swift': CONF.object_storage_feature_enabled.discoverable_apis,
Matthew Treinish8b006d22014-01-07 15:37:20 +0000252 }
253 if service not in extensions_options:
254 print('No supported extensions list option for %s' % service)
caoyueab333022016-01-25 16:45:21 +0800255 sys.exit(1)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000256 return extensions_options[service]
257
258
259def verify_extensions(os, service, results):
260 extensions_client = get_extension_client(os, service)
David Kranz5cf4ba42015-02-10 14:00:50 -0500261 if service != 'swift':
David Kranz34e88122014-12-11 15:24:05 -0500262 resp = extensions_client.list_extensions()
263 else:
ghanshyam17d8a482017-07-21 03:10:48 +0000264 resp = extensions_client.list_capabilities()
Matthew Treinish54176ce2014-12-08 21:28:05 +0000265 # For Nova, Cinder and Neutron we use the alias name rather than the
266 # 'name' field because the alias is considered to be the canonical
267 # name.
Matthew Treinish8b006d22014-01-07 15:37:20 +0000268 if isinstance(resp, dict):
Matthew Treinish54176ce2014-12-08 21:28:05 +0000269 if service == 'swift':
Matthew Treinishc0120ba2014-01-31 20:10:19 +0000270 # Remove Swift general information from extensions list
271 resp.pop('swift')
272 extensions = resp.keys()
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000273 else:
Matthew Treinish54176ce2014-12-08 21:28:05 +0000274 extensions = map(lambda x: x['alias'], resp['extensions'])
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000275
Matthew Treinish8b006d22014-01-07 15:37:20 +0000276 else:
Matthew Treinish54176ce2014-12-08 21:28:05 +0000277 extensions = map(lambda x: x['alias'], resp)
Matthew Treinish09487242015-05-10 12:43:58 -0400278 extensions = list(extensions)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000279 if not results.get(service):
280 results[service] = {}
281 extensions_opt = get_enabled_extensions(service)
Martin Kopecd7e05dd2018-08-14 09:20:48 +0000282 if not extensions_opt:
283 LOG.info("'%s' has no api_extensions set.", service)
284 return results
Matthew Treinish8b006d22014-01-07 15:37:20 +0000285 if extensions_opt[0] == 'all':
Matthew Treinishf0971712014-04-11 20:08:53 +0000286 results[service]['extensions'] = extensions
Matthew Treinish8b006d22014-01-07 15:37:20 +0000287 return results
288 # Verify that all configured extensions are actually enabled
289 for extension in extensions_opt:
290 results[service][extension] = extension in extensions
291 # Verify that there aren't additional extensions enabled that aren't
292 # specified in the config list
293 for extension in extensions:
294 if extension not in extensions_opt:
295 results[service][extension] = False
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000296 return results
297
298
Matthew Treinishf0971712014-04-11 20:08:53 +0000299def display_results(results, update, replace):
300 update_dict = {
301 'swift': 'object-storage-feature-enabled',
302 'nova': 'compute-feature-enabled',
Matthew Treinishf0971712014-04-11 20:08:53 +0000303 'cinder': 'volume-feature-enabled',
304 'neutron': 'network-feature-enabled',
305 }
Matthew Treinish8b006d22014-01-07 15:37:20 +0000306 for service in results:
307 # If all extensions are specified as being enabled there is no way to
308 # verify this so we just assume this to be true
309 if results[service].get('extensions'):
Matthew Treinishf0971712014-04-11 20:08:53 +0000310 if replace:
311 output_list = results[service].get('extensions')
312 else:
313 output_list = ['all']
314 else:
315 extension_list = get_enabled_extensions(service)
316 output_list = []
317 for extension in results[service]:
318 if not results[service][extension]:
319 if extension in extension_list:
320 print("%s extension: %s should not be included in the "
321 "list of enabled extensions" % (service,
322 extension))
323 else:
324 print("%s extension: %s should be included in the list"
325 " of enabled extensions" % (service, extension))
326 output_list.append(extension)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000327 else:
Matthew Treinishf0971712014-04-11 20:08:53 +0000328 output_list.append(extension)
329 if update:
330 # Sort List
331 output_list.sort()
332 # Convert list to a string
333 output_string = ', '.join(output_list)
334 if service == 'swift':
335 change_option('discoverable_apis', update_dict[service],
336 output_string)
Matthew Treinishf0971712014-04-11 20:08:53 +0000337 else:
338 change_option('api_extensions', update_dict[service],
339 output_string)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000340
341
Matthew Treinishf0971712014-04-11 20:08:53 +0000342def check_service_availability(os, update):
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000343 services = []
344 avail_services = []
345 codename_match = {
346 'volume': 'cinder',
347 'network': 'neutron',
348 'image': 'glance',
349 'object_storage': 'swift',
350 'compute': 'nova',
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000351 'baremetal': 'ironic',
Matthew Treinish42d50f62014-04-11 19:47:13 +0000352 'identity': 'keystone',
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000353 }
354 # Get catalog list for endpoints to use for validation
David Kranz45714082015-04-01 14:47:33 -0400355 _token, auth_data = os.auth_provider.get_auth()
David Kranz799eee12015-04-08 11:18:19 -0400356 if os.auth_version == 'v2':
357 catalog_key = 'serviceCatalog'
358 else:
359 catalog_key = 'catalog'
360 for entry in auth_data[catalog_key]:
David Kranz45714082015-04-01 14:47:33 -0400361 services.append(entry['type'])
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000362 # Pull all catalog types from config file and compare against endpoint list
363 for cfgname in dir(CONF._config):
364 cfg = getattr(CONF, cfgname)
365 catalog_type = getattr(cfg, 'catalog_type', None)
366 if not catalog_type:
367 continue
Martin Kopec07a572c2019-01-18 14:23:06 +0000368 if cfgname == 'identity':
369 # Keystone is a required service for tempest
370 continue
371 if catalog_type not in services:
372 try:
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000373 if getattr(CONF.service_available, codename_match[cfgname]):
374 print('Endpoint type %s not found either disable service '
375 '%s or fix the catalog_type in the config file' % (
Matthew Treinish96e9e882014-06-09 18:37:19 -0400376 catalog_type, codename_match[cfgname]))
Matthew Treinishf0971712014-04-11 20:08:53 +0000377 if update:
378 change_option(codename_match[cfgname],
379 'service_available', False)
Martin Kopec07a572c2019-01-18 14:23:06 +0000380 except KeyError:
381 print('%s is a third party plugin, cannot be verified '
382 'automatically, but it is suggested that it is set to '
383 'False because %s service is not available ' % (
384 cfgname, catalog_type))
385 else:
386 try:
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000387 if not getattr(CONF.service_available,
388 codename_match[cfgname]):
389 print('Endpoint type %s is available, service %s should be'
390 ' set as available in the config file.' % (
Matthew Treinish96e9e882014-06-09 18:37:19 -0400391 catalog_type, codename_match[cfgname]))
Matthew Treinishf0971712014-04-11 20:08:53 +0000392 if update:
393 change_option(codename_match[cfgname],
394 'service_available', True)
David Kranzf20ac322014-05-02 16:46:15 -0400395 # If we are going to enable this we should allow
396 # extension checks.
397 avail_services.append(codename_match[cfgname])
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000398 else:
399 avail_services.append(codename_match[cfgname])
Martin Kopec07a572c2019-01-18 14:23:06 +0000400 except KeyError:
401 print('%s is a third party plugin, cannot be verified '
402 'automatically, but it is suggested that it is set to '
403 'True because %s service is available ' % (
404 cfgname, catalog_type))
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000405 return avail_services
Matthew Treinishd44fe032014-01-31 20:07:24 +0000406
407
David Patersone45aa842015-11-18 16:12:27 -0800408def _parser_add_args(parser):
Matthew Treinishf0971712014-04-11 20:08:53 +0000409 parser.add_argument('-u', '--update', action='store_true',
410 help='Update the config file with results from api '
411 'queries. This assumes whatever is set in the '
412 'config file is incorrect. In the case of '
413 'endpoint checks where it could either be the '
414 'incorrect catalog type or the service available '
415 'option the service available option is assumed '
416 'to be incorrect and is thus changed')
417 parser.add_argument('-o', '--output',
418 help="Output file to write an updated config file to. "
419 "This has to be a separate file from the "
420 "original config file. If one isn't specified "
Martin Kopecbd9dd8e2017-06-28 20:52:18 +0000421 "with -u the values which should be changed "
422 "will be printed to STDOUT")
Matthew Treinishf0971712014-04-11 20:08:53 +0000423 parser.add_argument('-r', '--replace-ext', action='store_true',
424 help="If specified the all option will be replaced "
425 "with a full list of extensions")
Matthew Treinishf0971712014-04-11 20:08:53 +0000426
427
David Patersone45aa842015-11-18 16:12:27 -0800428def parse_args():
429 parser = argparse.ArgumentParser()
430 _parser_add_args(parser)
431 opts = parser.parse_args()
432 return opts
433
434
435def main(opts=None):
Matthew Treinishf0971712014-04-11 20:08:53 +0000436 update = opts.update
437 replace = opts.replace_ext
David Kranzf20ac322014-05-02 16:46:15 -0400438 global CONF_PARSER
439
Matthew Treinishf0971712014-04-11 20:08:53 +0000440 if update:
David Kranzf20ac322014-05-02 16:46:15 -0400441 conf_file = _get_config_file()
Andreas Jaeger2f273242020-05-05 13:27:32 +0200442 CONF_PARSER = configparser.ConfigParser()
David Kranzf20ac322014-05-02 16:46:15 -0400443 CONF_PARSER.optionxform = str
Andreas Jaeger2f273242020-05-05 13:27:32 +0200444 CONF_PARSER.read_file(conf_file)
Brad Behle43e4fd82016-04-13 17:15:21 -0500445
446 # Indicate not to create network resources as part of getting credentials
447 net_resources = {
448 'network': False,
449 'router': False,
450 'subnet': False,
451 'dhcp': False
452 }
453 icreds = credentials.get_credentials_provider(
454 'verify_tempest_config', network_resources=net_resources)
David Kranz5fcac942015-05-08 17:43:45 -0400455 try:
Andrea Frittoli (andreaf)848c4a12016-06-09 11:09:02 +0100456 os = clients.Manager(icreds.get_primary_creds().credentials)
David Kranz5fcac942015-05-08 17:43:45 -0400457 services = check_service_availability(os, update)
458 results = {}
459 for service in ['nova', 'cinder', 'neutron', 'swift']:
460 if service not in services:
461 continue
462 results = verify_extensions(os, service, results)
Adam Gandelman03af5562014-10-07 12:22:48 -0700463
David Kranz5fcac942015-05-08 17:43:45 -0400464 # Verify API versions of all services in the keystone catalog and
465 # keystone itself.
466 services.append('keystone')
467 for service in services:
468 verify_api_versions(os, service, update)
Adam Gandelman03af5562014-10-07 12:22:48 -0700469
David Kranz5fcac942015-05-08 17:43:45 -0400470 display_results(results, update, replace)
471 if update:
472 conf_file.close()
zhang.leia4b1cef2016-03-01 10:50:01 +0800473 if opts.output:
474 with open(opts.output, 'w+') as outfile:
475 CONF_PARSER.write(outfile)
David Kranz5fcac942015-05-08 17:43:45 -0400476 finally:
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700477 icreds.clear_creds()
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000478
479
David Patersone45aa842015-11-18 16:12:27 -0800480class TempestVerifyConfig(command.Command):
481 """Verify your current tempest configuration"""
482
483 def get_parser(self, prog_name):
484 parser = super(TempestVerifyConfig, self).get_parser(prog_name)
485 _parser_add_args(parser)
486 return parser
487
488 def take_action(self, parsed_args):
489 try:
Masayuki Igawa92629432016-06-09 12:28:09 +0900490 main(parsed_args)
David Patersone45aa842015-11-18 16:12:27 -0800491 except Exception:
492 LOG.exception("Failure verifying configuration.")
493 traceback.print_exc()
494 raise