blob: fdf28d525af78ad96ff9088dc1beb491984a0206 [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
Matthew Treinishf0971712014-04-11 20:08:53 +000063import os
Brant Knudson28de8d52016-03-18 13:50:02 -050064import re
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000065import sys
David Patersone45aa842015-11-18 16:12:27 -080066import traceback
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000067
David Patersone45aa842015-11-18 16:12:27 -080068from cliff import command
69from oslo_log import log as logging
Matthew Treinish21905512015-07-13 10:33:35 -040070from oslo_serialization import jsonutils as json
Matthew Treinishc795b9e2014-06-09 17:01:10 -040071from six import moves
Matthew Treinishf077dd22015-04-23 09:37:41 -040072from six.moves.urllib import parse as urlparse
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_v1 !=
209 contains_version('v1.', versions)):
Nikita Gerasimov35fbdc12015-08-07 19:58:24 +0300210 print_and_or_update('api_v1', 'volume-feature-enabled',
Matthew Treinishf0971712014-04-11 20:08:53 +0000211 not CONF.volume_feature_enabled.api_v1, update)
David Kranz0df154d2015-06-02 17:02:27 -0400212 if (CONF.volume_feature_enabled.api_v2 !=
213 contains_version('v2.', versions)):
Nikita Gerasimov35fbdc12015-08-07 19:58:24 +0300214 print_and_or_update('api_v2', 'volume-feature-enabled',
Matthew Treinishf0971712014-04-11 20:08:53 +0000215 not CONF.volume_feature_enabled.api_v2, update)
Nikita Gerasimov3b169cc2016-08-10 17:10:42 +0300216 if (CONF.volume_feature_enabled.api_v3 !=
217 contains_version('v3.', versions)):
218 print_and_or_update('api_v3', 'volume-feature-enabled',
219 not CONF.volume_feature_enabled.api_v3, update)
Matthew Treinish2e439632014-03-05 21:53:33 +0000220
221
Adam Gandelman03af5562014-10-07 12:22:48 -0700222def verify_api_versions(os, service, update):
223 verify = {
224 'cinder': verify_cinder_api_versions,
225 'glance': verify_glance_api_versions,
226 'keystone': verify_keystone_api_versions,
Adam Gandelman03af5562014-10-07 12:22:48 -0700227 }
228 if service not in verify:
229 return
230 verify[service](os, update)
231
232
Matthew Treinish8b006d22014-01-07 15:37:20 +0000233def get_extension_client(os, service):
234 extensions_client = {
Andrea Frittolib33dd462017-07-21 10:14:25 +0100235 'nova': os.compute.ExtensionsClient(),
236 'neutron': os.network.ExtensionsClient(),
Andrea Frittoli986407d2017-10-11 10:23:17 +0000237 'swift': os.object_storage.CapabilitiesClient(),
Ken'ichi Ohmichi8b876dd2017-05-04 14:30:31 -0700238 # NOTE: Cinder v3 API is current and v2 and v1 are deprecated.
239 # V3 extension API is the same as v2, so we reuse the v2 client
240 # for v3 API also.
Andrea Frittolib33dd462017-07-21 10:14:25 +0100241 'cinder': os.volume_v2.ExtensionsClient(),
Matthew Treinish8b006d22014-01-07 15:37:20 +0000242 }
Ivan Kolodyazhnybcfc32e2015-08-06 13:31:36 +0300243
Matthew Treinish8b006d22014-01-07 15:37:20 +0000244 if service not in extensions_client:
245 print('No tempest extensions client for %s' % service)
caoyueab333022016-01-25 16:45:21 +0800246 sys.exit(1)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000247 return extensions_client[service]
248
249
250def get_enabled_extensions(service):
251 extensions_options = {
252 'nova': CONF.compute_feature_enabled.api_extensions,
Matthew Treinish8b006d22014-01-07 15:37:20 +0000253 'cinder': CONF.volume_feature_enabled.api_extensions,
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000254 'neutron': CONF.network_feature_enabled.api_extensions,
Matthew Treinishc0120ba2014-01-31 20:10:19 +0000255 'swift': CONF.object_storage_feature_enabled.discoverable_apis,
Matthew Treinish8b006d22014-01-07 15:37:20 +0000256 }
257 if service not in extensions_options:
258 print('No supported extensions list option for %s' % service)
caoyueab333022016-01-25 16:45:21 +0800259 sys.exit(1)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000260 return extensions_options[service]
261
262
263def verify_extensions(os, service, results):
264 extensions_client = get_extension_client(os, service)
David Kranz5cf4ba42015-02-10 14:00:50 -0500265 if service != 'swift':
David Kranz34e88122014-12-11 15:24:05 -0500266 resp = extensions_client.list_extensions()
267 else:
ghanshyam17d8a482017-07-21 03:10:48 +0000268 resp = extensions_client.list_capabilities()
Matthew Treinish54176ce2014-12-08 21:28:05 +0000269 # For Nova, Cinder and Neutron we use the alias name rather than the
270 # 'name' field because the alias is considered to be the canonical
271 # name.
Matthew Treinish8b006d22014-01-07 15:37:20 +0000272 if isinstance(resp, dict):
Matthew Treinish54176ce2014-12-08 21:28:05 +0000273 if service == 'swift':
Matthew Treinishc0120ba2014-01-31 20:10:19 +0000274 # Remove Swift general information from extensions list
275 resp.pop('swift')
276 extensions = resp.keys()
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000277 else:
Matthew Treinish54176ce2014-12-08 21:28:05 +0000278 extensions = map(lambda x: x['alias'], resp['extensions'])
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000279
Matthew Treinish8b006d22014-01-07 15:37:20 +0000280 else:
Matthew Treinish54176ce2014-12-08 21:28:05 +0000281 extensions = map(lambda x: x['alias'], resp)
Matthew Treinish09487242015-05-10 12:43:58 -0400282 extensions = list(extensions)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000283 if not results.get(service):
284 results[service] = {}
285 extensions_opt = get_enabled_extensions(service)
286 if extensions_opt[0] == 'all':
Matthew Treinishf0971712014-04-11 20:08:53 +0000287 results[service]['extensions'] = extensions
Matthew Treinish8b006d22014-01-07 15:37:20 +0000288 return results
289 # Verify that all configured extensions are actually enabled
290 for extension in extensions_opt:
291 results[service][extension] = extension in extensions
292 # Verify that there aren't additional extensions enabled that aren't
293 # specified in the config list
294 for extension in extensions:
295 if extension not in extensions_opt:
296 results[service][extension] = False
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000297 return results
298
299
Matthew Treinishf0971712014-04-11 20:08:53 +0000300def display_results(results, update, replace):
301 update_dict = {
302 'swift': 'object-storage-feature-enabled',
303 'nova': 'compute-feature-enabled',
Matthew Treinishf0971712014-04-11 20:08:53 +0000304 'cinder': 'volume-feature-enabled',
305 'neutron': 'network-feature-enabled',
306 }
Matthew Treinish8b006d22014-01-07 15:37:20 +0000307 for service in results:
308 # If all extensions are specified as being enabled there is no way to
309 # verify this so we just assume this to be true
310 if results[service].get('extensions'):
Matthew Treinishf0971712014-04-11 20:08:53 +0000311 if replace:
312 output_list = results[service].get('extensions')
313 else:
314 output_list = ['all']
315 else:
316 extension_list = get_enabled_extensions(service)
317 output_list = []
318 for extension in results[service]:
319 if not results[service][extension]:
320 if extension in extension_list:
321 print("%s extension: %s should not be included in the "
322 "list of enabled extensions" % (service,
323 extension))
324 else:
325 print("%s extension: %s should be included in the list"
326 " of enabled extensions" % (service, extension))
327 output_list.append(extension)
Matthew Treinish8b006d22014-01-07 15:37:20 +0000328 else:
Matthew Treinishf0971712014-04-11 20:08:53 +0000329 output_list.append(extension)
330 if update:
331 # Sort List
332 output_list.sort()
333 # Convert list to a string
334 output_string = ', '.join(output_list)
335 if service == 'swift':
336 change_option('discoverable_apis', update_dict[service],
337 output_string)
Matthew Treinishf0971712014-04-11 20:08:53 +0000338 else:
339 change_option('api_extensions', update_dict[service],
340 output_string)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000341
342
Matthew Treinishf0971712014-04-11 20:08:53 +0000343def check_service_availability(os, update):
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000344 services = []
345 avail_services = []
346 codename_match = {
347 'volume': 'cinder',
348 'network': 'neutron',
349 'image': 'glance',
350 'object_storage': 'swift',
351 'compute': 'nova',
352 'orchestration': 'heat',
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000353 'baremetal': 'ironic',
Matthew Treinish42d50f62014-04-11 19:47:13 +0000354 'identity': 'keystone',
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000355 }
356 # Get catalog list for endpoints to use for validation
David Kranz45714082015-04-01 14:47:33 -0400357 _token, auth_data = os.auth_provider.get_auth()
David Kranz799eee12015-04-08 11:18:19 -0400358 if os.auth_version == 'v2':
359 catalog_key = 'serviceCatalog'
360 else:
361 catalog_key = 'catalog'
362 for entry in auth_data[catalog_key]:
David Kranz45714082015-04-01 14:47:33 -0400363 services.append(entry['type'])
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000364 # Pull all catalog types from config file and compare against endpoint list
365 for cfgname in dir(CONF._config):
366 cfg = getattr(CONF, cfgname)
367 catalog_type = getattr(cfg, 'catalog_type', None)
368 if not catalog_type:
369 continue
370 else:
371 if cfgname == 'identity':
372 # Keystone is a required service for tempest
373 continue
374 if catalog_type not in services:
375 if getattr(CONF.service_available, codename_match[cfgname]):
376 print('Endpoint type %s not found either disable service '
377 '%s or fix the catalog_type in the config file' % (
Matthew Treinish96e9e882014-06-09 18:37:19 -0400378 catalog_type, codename_match[cfgname]))
Matthew Treinishf0971712014-04-11 20:08:53 +0000379 if update:
380 change_option(codename_match[cfgname],
381 'service_available', False)
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000382 else:
383 if not getattr(CONF.service_available,
384 codename_match[cfgname]):
385 print('Endpoint type %s is available, service %s should be'
386 ' set as available in the config file.' % (
Matthew Treinish96e9e882014-06-09 18:37:19 -0400387 catalog_type, codename_match[cfgname]))
Matthew Treinishf0971712014-04-11 20:08:53 +0000388 if update:
389 change_option(codename_match[cfgname],
390 'service_available', True)
David Kranzf20ac322014-05-02 16:46:15 -0400391 # If we are going to enable this we should allow
392 # extension checks.
393 avail_services.append(codename_match[cfgname])
Matthew Treinish221bd7f2014-02-07 21:16:09 +0000394 else:
395 avail_services.append(codename_match[cfgname])
396 return avail_services
Matthew Treinishd44fe032014-01-31 20:07:24 +0000397
398
David Patersone45aa842015-11-18 16:12:27 -0800399def _parser_add_args(parser):
Matthew Treinishf0971712014-04-11 20:08:53 +0000400 parser.add_argument('-u', '--update', action='store_true',
401 help='Update the config file with results from api '
402 'queries. This assumes whatever is set in the '
403 'config file is incorrect. In the case of '
404 'endpoint checks where it could either be the '
405 'incorrect catalog type or the service available '
406 'option the service available option is assumed '
407 'to be incorrect and is thus changed')
408 parser.add_argument('-o', '--output',
409 help="Output file to write an updated config file to. "
410 "This has to be a separate file from the "
411 "original config file. If one isn't specified "
Martin Kopecbd9dd8e2017-06-28 20:52:18 +0000412 "with -u the values which should be changed "
413 "will be printed to STDOUT")
Matthew Treinishf0971712014-04-11 20:08:53 +0000414 parser.add_argument('-r', '--replace-ext', action='store_true',
415 help="If specified the all option will be replaced "
416 "with a full list of extensions")
Matthew Treinishf0971712014-04-11 20:08:53 +0000417
418
David Patersone45aa842015-11-18 16:12:27 -0800419def parse_args():
420 parser = argparse.ArgumentParser()
421 _parser_add_args(parser)
422 opts = parser.parse_args()
423 return opts
424
425
426def main(opts=None):
Matthew Treinish8b006d22014-01-07 15:37:20 +0000427 print('Running config verification...')
David Patersone45aa842015-11-18 16:12:27 -0800428 if opts is None:
429 print("Use of: 'verify-tempest-config' is deprecated, "
430 "please use: 'tempest verify-config'")
431 opts = parse_args()
Matthew Treinishf0971712014-04-11 20:08:53 +0000432 update = opts.update
433 replace = opts.replace_ext
David Kranzf20ac322014-05-02 16:46:15 -0400434 global CONF_PARSER
435
Matthew Treinishf0971712014-04-11 20:08:53 +0000436 if update:
David Kranzf20ac322014-05-02 16:46:15 -0400437 conf_file = _get_config_file()
Janonymous8254a3f2016-09-15 10:38:48 +0530438 CONF_PARSER = moves.configparser.ConfigParser()
David Kranzf20ac322014-05-02 16:46:15 -0400439 CONF_PARSER.optionxform = str
440 CONF_PARSER.readfp(conf_file)
Brad Behle43e4fd82016-04-13 17:15:21 -0500441
442 # Indicate not to create network resources as part of getting credentials
443 net_resources = {
444 'network': False,
445 'router': False,
446 'subnet': False,
447 'dhcp': False
448 }
449 icreds = credentials.get_credentials_provider(
450 'verify_tempest_config', network_resources=net_resources)
David Kranz5fcac942015-05-08 17:43:45 -0400451 try:
Andrea Frittoli (andreaf)848c4a12016-06-09 11:09:02 +0100452 os = clients.Manager(icreds.get_primary_creds().credentials)
David Kranz5fcac942015-05-08 17:43:45 -0400453 services = check_service_availability(os, update)
454 results = {}
455 for service in ['nova', 'cinder', 'neutron', 'swift']:
456 if service not in services:
457 continue
458 results = verify_extensions(os, service, results)
Adam Gandelman03af5562014-10-07 12:22:48 -0700459
David Kranz5fcac942015-05-08 17:43:45 -0400460 # Verify API versions of all services in the keystone catalog and
461 # keystone itself.
462 services.append('keystone')
463 for service in services:
464 verify_api_versions(os, service, update)
Adam Gandelman03af5562014-10-07 12:22:48 -0700465
David Kranz5fcac942015-05-08 17:43:45 -0400466 display_results(results, update, replace)
467 if update:
468 conf_file.close()
zhang.leia4b1cef2016-03-01 10:50:01 +0800469 if opts.output:
470 with open(opts.output, 'w+') as outfile:
471 CONF_PARSER.write(outfile)
David Kranz5fcac942015-05-08 17:43:45 -0400472 finally:
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700473 icreds.clear_creds()
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000474
475
David Patersone45aa842015-11-18 16:12:27 -0800476class TempestVerifyConfig(command.Command):
477 """Verify your current tempest configuration"""
478
479 def get_parser(self, prog_name):
480 parser = super(TempestVerifyConfig, self).get_parser(prog_name)
481 _parser_add_args(parser)
482 return parser
483
484 def take_action(self, parsed_args):
485 try:
Masayuki Igawa92629432016-06-09 12:28:09 +0900486 main(parsed_args)
David Patersone45aa842015-11-18 16:12:27 -0800487 except Exception:
488 LOG.exception("Failure verifying configuration.")
489 traceback.print_exc()
490 raise
David Patersone45aa842015-11-18 16:12:27 -0800491
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000492if __name__ == "__main__":
Matthew Treinishf8b816a2014-04-23 20:35:49 +0000493 main()