blob: 0db1ab15772f316dbba8db50e0e577a9b87e9c74 [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
Adam Gandelman03af5562014-10-07 12:22:48 -0700205def verify_api_versions(os, service, update):
206 verify = {
Adam Gandelman03af5562014-10-07 12:22:48 -0700207 'glance': verify_glance_api_versions,
208 'keystone': verify_keystone_api_versions,
Adam Gandelman03af5562014-10-07 12:22:48 -0700209 }
210 if service not in verify:
211 return
212 verify[service](os, update)
213
214
Matthew Treinish8b006d22014-01-07 15:37:20 +0000215def get_extension_client(os, service):
216 extensions_client = {
Andrea Frittolib33dd462017-07-21 10:14:25 +0100217 'nova': os.compute.ExtensionsClient(),
218 'neutron': os.network.ExtensionsClient(),
Andrea Frittoli986407d2017-10-11 10:23:17 +0000219 'swift': os.object_storage.CapabilitiesClient(),
Ken'ichi Ohmichi8b876dd2017-05-04 14:30:31 -0700220 # NOTE: Cinder v3 API is current and v2 and v1 are deprecated.
221 # V3 extension API is the same as v2, so we reuse the v2 client
222 # for v3 API also.
Andrea Frittolib33dd462017-07-21 10:14:25 +0100223 'cinder': os.volume_v2.ExtensionsClient(),
Matthew Treinish8b006d22014-01-07 15:37:20 +0000224 }
Ivan Kolodyazhnybcfc32e2015-08-06 13:31:36 +0300225
Matthew Treinish8b006d22014-01-07 15:37:20 +0000226 if service not in extensions_client:
227 print('No tempest extensions client for %s' % service)
caoyueab333022016-01-25 16:45:21 +0800228 sys.exit(1)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000229 return extensions_client[service]
230
231
232def get_enabled_extensions(service):
233 extensions_options = {
234 'nova': CONF.compute_feature_enabled.api_extensions,
Matthew Treinish8b006d22014-01-07 15:37:20 +0000235 'cinder': CONF.volume_feature_enabled.api_extensions,
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000236 'neutron': CONF.network_feature_enabled.api_extensions,
Matthew Treinishc0120ba2014-01-31 20:10:19 +0000237 'swift': CONF.object_storage_feature_enabled.discoverable_apis,
Matthew Treinish8b006d22014-01-07 15:37:20 +0000238 }
239 if service not in extensions_options:
240 print('No supported extensions list option for %s' % service)
caoyueab333022016-01-25 16:45:21 +0800241 sys.exit(1)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000242 return extensions_options[service]
243
244
245def verify_extensions(os, service, results):
246 extensions_client = get_extension_client(os, service)
David Kranz5cf4ba42015-02-10 14:00:50 -0500247 if service != 'swift':
David Kranz34e88122014-12-11 15:24:05 -0500248 resp = extensions_client.list_extensions()
249 else:
ghanshyam17d8a482017-07-21 03:10:48 +0000250 resp = extensions_client.list_capabilities()
Matthew Treinish54176ce2014-12-08 21:28:05 +0000251 # For Nova, Cinder and Neutron we use the alias name rather than the
252 # 'name' field because the alias is considered to be the canonical
253 # name.
Matthew Treinish8b006d22014-01-07 15:37:20 +0000254 if isinstance(resp, dict):
Matthew Treinish54176ce2014-12-08 21:28:05 +0000255 if service == 'swift':
Matthew Treinishc0120ba2014-01-31 20:10:19 +0000256 # Remove Swift general information from extensions list
257 resp.pop('swift')
258 extensions = resp.keys()
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000259 else:
Matthew Treinish54176ce2014-12-08 21:28:05 +0000260 extensions = map(lambda x: x['alias'], resp['extensions'])
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000261
Matthew Treinish8b006d22014-01-07 15:37:20 +0000262 else:
Matthew Treinish54176ce2014-12-08 21:28:05 +0000263 extensions = map(lambda x: x['alias'], resp)
Matthew Treinish09487242015-05-10 12:43:58 -0400264 extensions = list(extensions)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000265 if not results.get(service):
266 results[service] = {}
267 extensions_opt = get_enabled_extensions(service)
Martin Kopecd7e05dd2018-08-14 09:20:48 +0000268 if not extensions_opt:
269 LOG.info("'%s' has no api_extensions set.", service)
270 return results
Matthew Treinish8b006d22014-01-07 15:37:20 +0000271 if extensions_opt[0] == 'all':
Matthew Treinishf0971712014-04-11 20:08:53 +0000272 results[service]['extensions'] = extensions
Matthew Treinish8b006d22014-01-07 15:37:20 +0000273 return results
274 # Verify that all configured extensions are actually enabled
275 for extension in extensions_opt:
276 results[service][extension] = extension in extensions
277 # Verify that there aren't additional extensions enabled that aren't
278 # specified in the config list
279 for extension in extensions:
280 if extension not in extensions_opt:
281 results[service][extension] = False
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000282 return results
283
284
Matthew Treinishf0971712014-04-11 20:08:53 +0000285def display_results(results, update, replace):
286 update_dict = {
287 'swift': 'object-storage-feature-enabled',
288 'nova': 'compute-feature-enabled',
Matthew Treinishf0971712014-04-11 20:08:53 +0000289 'cinder': 'volume-feature-enabled',
290 'neutron': 'network-feature-enabled',
291 }
Matthew Treinish8b006d22014-01-07 15:37:20 +0000292 for service in results:
293 # If all extensions are specified as being enabled there is no way to
294 # verify this so we just assume this to be true
295 if results[service].get('extensions'):
Matthew Treinishf0971712014-04-11 20:08:53 +0000296 if replace:
297 output_list = results[service].get('extensions')
298 else:
299 output_list = ['all']
300 else:
301 extension_list = get_enabled_extensions(service)
302 output_list = []
303 for extension in results[service]:
304 if not results[service][extension]:
305 if extension in extension_list:
306 print("%s extension: %s should not be included in the "
307 "list of enabled extensions" % (service,
308 extension))
309 else:
310 print("%s extension: %s should be included in the list"
311 " of enabled extensions" % (service, extension))
312 output_list.append(extension)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000313 else:
Matthew Treinishf0971712014-04-11 20:08:53 +0000314 output_list.append(extension)
315 if update:
316 # Sort List
317 output_list.sort()
318 # Convert list to a string
319 output_string = ', '.join(output_list)
320 if service == 'swift':
321 change_option('discoverable_apis', update_dict[service],
322 output_string)
Matthew Treinishf0971712014-04-11 20:08:53 +0000323 else:
324 change_option('api_extensions', update_dict[service],
325 output_string)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000326
327
Matthew Treinishf0971712014-04-11 20:08:53 +0000328def check_service_availability(os, update):
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000329 services = []
330 avail_services = []
331 codename_match = {
332 'volume': 'cinder',
333 'network': 'neutron',
334 'image': 'glance',
335 'object_storage': 'swift',
336 'compute': 'nova',
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000337 'baremetal': 'ironic',
Matthew Treinish42d50f62014-04-11 19:47:13 +0000338 'identity': 'keystone',
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000339 }
340 # Get catalog list for endpoints to use for validation
David Kranz45714082015-04-01 14:47:33 -0400341 _token, auth_data = os.auth_provider.get_auth()
David Kranz799eee12015-04-08 11:18:19 -0400342 if os.auth_version == 'v2':
343 catalog_key = 'serviceCatalog'
344 else:
345 catalog_key = 'catalog'
346 for entry in auth_data[catalog_key]:
David Kranz45714082015-04-01 14:47:33 -0400347 services.append(entry['type'])
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000348 # Pull all catalog types from config file and compare against endpoint list
349 for cfgname in dir(CONF._config):
350 cfg = getattr(CONF, cfgname)
351 catalog_type = getattr(cfg, 'catalog_type', None)
352 if not catalog_type:
353 continue
Martin Kopec07a572c2019-01-18 14:23:06 +0000354 if cfgname == 'identity':
355 # Keystone is a required service for tempest
356 continue
357 if catalog_type not in services:
358 try:
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000359 if getattr(CONF.service_available, codename_match[cfgname]):
360 print('Endpoint type %s not found either disable service '
361 '%s or fix the catalog_type in the config file' % (
Matthew Treinish96e9e882014-06-09 18:37:19 -0400362 catalog_type, codename_match[cfgname]))
Matthew Treinishf0971712014-04-11 20:08:53 +0000363 if update:
364 change_option(codename_match[cfgname],
365 'service_available', False)
Martin Kopec07a572c2019-01-18 14:23:06 +0000366 except KeyError:
367 print('%s is a third party plugin, cannot be verified '
368 'automatically, but it is suggested that it is set to '
369 'False because %s service is not available ' % (
370 cfgname, catalog_type))
371 else:
372 try:
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000373 if not getattr(CONF.service_available,
374 codename_match[cfgname]):
375 print('Endpoint type %s is available, service %s should be'
376 ' set as available in the config file.' % (
Matthew Treinish96e9e882014-06-09 18:37:19 -0400377 catalog_type, codename_match[cfgname]))
Matthew Treinishf0971712014-04-11 20:08:53 +0000378 if update:
379 change_option(codename_match[cfgname],
380 'service_available', True)
David Kranzf20ac322014-05-02 16:46:15 -0400381 # If we are going to enable this we should allow
382 # extension checks.
383 avail_services.append(codename_match[cfgname])
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000384 else:
385 avail_services.append(codename_match[cfgname])
Martin Kopec07a572c2019-01-18 14:23:06 +0000386 except KeyError:
387 print('%s is a third party plugin, cannot be verified '
388 'automatically, but it is suggested that it is set to '
389 'True because %s service is available ' % (
390 cfgname, catalog_type))
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000391 return avail_services
Matthew Treinishd44fe032014-01-31 20:07:24 +0000392
393
David Patersone45aa842015-11-18 16:12:27 -0800394def _parser_add_args(parser):
Matthew Treinishf0971712014-04-11 20:08:53 +0000395 parser.add_argument('-u', '--update', action='store_true',
396 help='Update the config file with results from api '
397 'queries. This assumes whatever is set in the '
398 'config file is incorrect. In the case of '
399 'endpoint checks where it could either be the '
400 'incorrect catalog type or the service available '
401 'option the service available option is assumed '
402 'to be incorrect and is thus changed')
403 parser.add_argument('-o', '--output',
404 help="Output file to write an updated config file to. "
405 "This has to be a separate file from the "
406 "original config file. If one isn't specified "
Martin Kopecbd9dd8e2017-06-28 20:52:18 +0000407 "with -u the values which should be changed "
408 "will be printed to STDOUT")
Matthew Treinishf0971712014-04-11 20:08:53 +0000409 parser.add_argument('-r', '--replace-ext', action='store_true',
410 help="If specified the all option will be replaced "
411 "with a full list of extensions")
Matthew Treinishf0971712014-04-11 20:08:53 +0000412
413
David Patersone45aa842015-11-18 16:12:27 -0800414def parse_args():
415 parser = argparse.ArgumentParser()
416 _parser_add_args(parser)
417 opts = parser.parse_args()
418 return opts
419
420
421def main(opts=None):
Matthew Treinishf0971712014-04-11 20:08:53 +0000422 update = opts.update
423 replace = opts.replace_ext
David Kranzf20ac322014-05-02 16:46:15 -0400424 global CONF_PARSER
425
Matthew Treinishf0971712014-04-11 20:08:53 +0000426 if update:
David Kranzf20ac322014-05-02 16:46:15 -0400427 conf_file = _get_config_file()
Andreas Jaeger2f273242020-05-05 13:27:32 +0200428 CONF_PARSER = configparser.ConfigParser()
David Kranzf20ac322014-05-02 16:46:15 -0400429 CONF_PARSER.optionxform = str
Andreas Jaeger2f273242020-05-05 13:27:32 +0200430 CONF_PARSER.read_file(conf_file)
Brad Behle43e4fd82016-04-13 17:15:21 -0500431
432 # Indicate not to create network resources as part of getting credentials
433 net_resources = {
434 'network': False,
435 'router': False,
436 'subnet': False,
437 'dhcp': False
438 }
439 icreds = credentials.get_credentials_provider(
440 'verify_tempest_config', network_resources=net_resources)
David Kranz5fcac942015-05-08 17:43:45 -0400441 try:
Andrea Frittoli (andreaf)848c4a12016-06-09 11:09:02 +0100442 os = clients.Manager(icreds.get_primary_creds().credentials)
David Kranz5fcac942015-05-08 17:43:45 -0400443 services = check_service_availability(os, update)
444 results = {}
445 for service in ['nova', 'cinder', 'neutron', 'swift']:
446 if service not in services:
447 continue
448 results = verify_extensions(os, service, results)
Adam Gandelman03af5562014-10-07 12:22:48 -0700449
David Kranz5fcac942015-05-08 17:43:45 -0400450 # Verify API versions of all services in the keystone catalog and
451 # keystone itself.
452 services.append('keystone')
453 for service in services:
454 verify_api_versions(os, service, update)
Adam Gandelman03af5562014-10-07 12:22:48 -0700455
David Kranz5fcac942015-05-08 17:43:45 -0400456 display_results(results, update, replace)
457 if update:
458 conf_file.close()
zhang.leia4b1cef2016-03-01 10:50:01 +0800459 if opts.output:
460 with open(opts.output, 'w+') as outfile:
461 CONF_PARSER.write(outfile)
David Kranz5fcac942015-05-08 17:43:45 -0400462 finally:
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700463 icreds.clear_creds()
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000464
465
David Patersone45aa842015-11-18 16:12:27 -0800466class TempestVerifyConfig(command.Command):
467 """Verify your current tempest configuration"""
468
469 def get_parser(self, prog_name):
470 parser = super(TempestVerifyConfig, self).get_parser(prog_name)
471 _parser_add_args(parser)
472 return parser
473
474 def take_action(self, parsed_args):
475 try:
Masayuki Igawa92629432016-06-09 12:28:09 +0900476 main(parsed_args)
David Patersone45aa842015-11-18 16:12:27 -0800477 except Exception:
478 LOG.exception("Failure verifying configuration.")
479 traceback.print_exc()
480 raise