Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 2 | |
| 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 Kopec | bd9dd8e | 2017-06-28 20:52:18 +0000 | [diff] [blame] | 17 | """ |
| 18 | Verifies user's current tempest configuration. |
| 19 | |
| 20 | This command is used for updating or user's tempest configuration file based on |
| 21 | api queries or replacing all option in a tempest configuration file for a full |
| 22 | list of extensions. |
| 23 | |
| 24 | General Options |
| 25 | =============== |
| 26 | |
| 27 | -u, --update |
| 28 | ------------ |
| 29 | Update the config file with results from api queries. This assumes whatever is |
| 30 | set in the config file is incorrect. |
| 31 | |
| 32 | -o FILE, --output=FILE |
| 33 | ---------------------- |
| 34 | Output file to write an updated config file to. This has to be a separate file |
| 35 | from the original one. If one isn't specified with -u the values which should |
| 36 | be changed will be printed to STDOUT. |
| 37 | |
| 38 | -r, --replace-ext |
| 39 | ----------------- |
| 40 | If specified the all option will be replaced with a full list of extensions. |
| 41 | |
| 42 | Environment Variables |
| 43 | ===================== |
| 44 | |
| 45 | The command is workspace aware - it uses tempest config file tempest.conf |
| 46 | located in ./etc/ directory. |
| 47 | The path to the config file and it's name can be changed through environment |
| 48 | variables. |
| 49 | |
| 50 | TEMPEST_CONFIG_DIR |
| 51 | ------------------ |
| 52 | Path to a directory where tempest configuration file is stored. If the variable |
| 53 | is set, the default path (./etc/) is overridden. |
| 54 | |
| 55 | TEMPEST_CONFIG |
| 56 | -------------- |
| 57 | Name of a tempest configuration file. If the variable is specified, the default |
| 58 | name (tempest.conf) is overridden. |
| 59 | |
| 60 | """ |
| 61 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 62 | import argparse |
Andreas Jaeger | 2f27324 | 2020-05-05 13:27:32 +0200 | [diff] [blame] | 63 | import configparser |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 64 | import os |
Brant Knudson | 28de8d5 | 2016-03-18 13:50:02 -0500 | [diff] [blame] | 65 | import re |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 66 | import sys |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 67 | import traceback |
Andreas Jaeger | 2f27324 | 2020-05-05 13:27:32 +0200 | [diff] [blame] | 68 | from urllib import parse as urlparse |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 69 | |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 70 | from cliff import command |
| 71 | from oslo_log import log as logging |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 72 | from oslo_serialization import jsonutils as json |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 73 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 74 | from tempest import clients |
Andrea Frittoli (andreaf) | 290b3e1 | 2015-10-08 10:25:02 +0100 | [diff] [blame] | 75 | from tempest.common import credentials_factory as credentials |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 76 | from tempest import config |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 77 | import tempest.lib.common.http |
Andrea Frittoli | b33dd46 | 2017-07-21 10:14:25 +0100 | [diff] [blame] | 78 | from tempest.lib import exceptions as lib_exc |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 79 | |
| 80 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 81 | CONF = config.CONF |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 82 | CONF_PARSER = None |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 83 | |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 84 | LOG = logging.getLogger(__name__) |
| 85 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 86 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 87 | def _get_config_file(): |
Martin Kopec | bd9dd8e | 2017-06-28 20:52:18 +0000 | [diff] [blame] | 88 | config_dir = os.getcwd() |
| 89 | default_config_dir = os.path.join(config_dir, "etc") |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 90 | 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 Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 95 | fd = open(path, 'r+') |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 96 | return fd |
| 97 | |
| 98 | |
| 99 | def change_option(option, group, value): |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 100 | if not CONF_PARSER.has_section(group): |
| 101 | CONF_PARSER.add_section(group) |
| 102 | CONF_PARSER.set(group, option, str(value)) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 103 | |
| 104 | |
| 105 | def 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 Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 112 | def contains_version(prefix, versions): |
| 113 | return any([x for x in versions if x.startswith(prefix)]) |
| 114 | |
| 115 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 116 | def verify_glance_api_versions(os, update): |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 117 | # Check glance api versions |
Andrea Frittoli | b33dd46 | 2017-07-21 10:14:25 +0100 | [diff] [blame] | 118 | # 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 Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 137 | if CONF.image_feature_enabled.api_v1 != contains_version('v1.', versions): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 138 | print_and_or_update('api_v1', 'image-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 139 | not CONF.image_feature_enabled.api_v1, update) |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 140 | if CONF.image_feature_enabled.api_v2 != contains_version('v2.', versions): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 141 | print_and_or_update('api_v2', 'image-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 142 | not CONF.image_feature_enabled.api_v2, update) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 143 | |
| 144 | |
Brant Knudson | 28de8d5 | 2016-03-18 13:50:02 -0500 | [diff] [blame] | 145 | def _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 Treinish | 9b89624 | 2014-04-23 21:25:27 +0000 | [diff] [blame] | 150 | def _get_unversioned_endpoint(base_url): |
| 151 | endpoint_parts = urlparse.urlparse(base_url) |
Brant Knudson | 28de8d5 | 2016-03-18 13:50:02 -0500 | [diff] [blame] | 152 | new_path = _remove_version_project(endpoint_parts.path) |
| 153 | endpoint_parts = endpoint_parts._replace(path=new_path) |
| 154 | endpoint = urlparse.urlunparse(endpoint_parts) |
Matthew Treinish | 9b89624 | 2014-04-23 21:25:27 +0000 | [diff] [blame] | 155 | return endpoint |
| 156 | |
| 157 | |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 158 | def _get_api_versions(os, service): |
Andrea Frittoli | b33dd46 | 2017-07-21 10:14:25 +0100 | [diff] [blame] | 159 | # 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 Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 163 | client_dict = { |
Andrea Frittoli | b33dd46 | 2017-07-21 10:14:25 +0100 | [diff] [blame] | 164 | '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 Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 168 | } |
Ivan Kolodyazhny | b24f904 | 2017-06-12 18:54:18 +0300 | [diff] [blame] | 169 | if service != 'keystone' and service != 'cinder': |
| 170 | # Since keystone and cinder may be listening on a path, |
| 171 | # do not remove the path. |
Brant Knudson | 28de8d5 | 2016-03-18 13:50:02 -0500 | [diff] [blame] | 172 | client_dict[service].skip_path() |
Matthew Treinish | 9b89624 | 2014-04-23 21:25:27 +0000 | [diff] [blame] | 173 | endpoint = _get_unversioned_endpoint(client_dict[service].base_url) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 174 | |
| 175 | http = tempest.lib.common.http.ClosingHttp( |
Daniel Mellado | cad3f3d | 2016-08-19 14:17:16 +0000 | [diff] [blame] | 176 | CONF.identity.disable_ssl_certificate_validation, |
| 177 | CONF.identity.ca_certificates_file) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 178 | |
| 179 | __, body = http.request(endpoint, 'GET') |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 180 | client_dict[service].reset_path() |
Brant Knudson | 5a59f87 | 2016-03-18 13:07:00 -0500 | [diff] [blame] | 181 | 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 Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 189 | 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 Treinish | 0948724 | 2015-05-10 12:43:58 -0400 | [diff] [blame] | 193 | return list(versions) |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 194 | |
| 195 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 196 | def verify_keystone_api_versions(os, update): |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 197 | # Check keystone api versions |
| 198 | versions = _get_api_versions(os, 'keystone') |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 199 | if (CONF.identity_feature_enabled.api_v3 != |
| 200 | contains_version('v3.', versions)): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 201 | print_and_or_update('api_v3', 'identity-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 202 | not CONF.identity_feature_enabled.api_v3, update) |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 203 | |
| 204 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 205 | def verify_cinder_api_versions(os, update): |
Matthew Treinish | 2e43963 | 2014-03-05 21:53:33 +0000 | [diff] [blame] | 206 | # Check cinder api versions |
| 207 | versions = _get_api_versions(os, 'cinder') |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 208 | if (CONF.volume_feature_enabled.api_v2 != |
| 209 | contains_version('v2.', versions)): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 210 | print_and_or_update('api_v2', 'volume-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 211 | not CONF.volume_feature_enabled.api_v2, update) |
Nikita Gerasimov | 3b169cc | 2016-08-10 17:10:42 +0300 | [diff] [blame] | 212 | 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 Treinish | 2e43963 | 2014-03-05 21:53:33 +0000 | [diff] [blame] | 216 | |
| 217 | |
Adam Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 218 | def 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 Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 223 | } |
| 224 | if service not in verify: |
| 225 | return |
| 226 | verify[service](os, update) |
| 227 | |
| 228 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 229 | def get_extension_client(os, service): |
| 230 | extensions_client = { |
Andrea Frittoli | b33dd46 | 2017-07-21 10:14:25 +0100 | [diff] [blame] | 231 | 'nova': os.compute.ExtensionsClient(), |
| 232 | 'neutron': os.network.ExtensionsClient(), |
Andrea Frittoli | 986407d | 2017-10-11 10:23:17 +0000 | [diff] [blame] | 233 | 'swift': os.object_storage.CapabilitiesClient(), |
Ken'ichi Ohmichi | 8b876dd | 2017-05-04 14:30:31 -0700 | [diff] [blame] | 234 | # 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 Frittoli | b33dd46 | 2017-07-21 10:14:25 +0100 | [diff] [blame] | 237 | 'cinder': os.volume_v2.ExtensionsClient(), |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 238 | } |
Ivan Kolodyazhny | bcfc32e | 2015-08-06 13:31:36 +0300 | [diff] [blame] | 239 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 240 | if service not in extensions_client: |
| 241 | print('No tempest extensions client for %s' % service) |
caoyue | ab33302 | 2016-01-25 16:45:21 +0800 | [diff] [blame] | 242 | sys.exit(1) |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 243 | return extensions_client[service] |
| 244 | |
| 245 | |
| 246 | def get_enabled_extensions(service): |
| 247 | extensions_options = { |
| 248 | 'nova': CONF.compute_feature_enabled.api_extensions, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 249 | 'cinder': CONF.volume_feature_enabled.api_extensions, |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 250 | 'neutron': CONF.network_feature_enabled.api_extensions, |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 251 | 'swift': CONF.object_storage_feature_enabled.discoverable_apis, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 252 | } |
| 253 | if service not in extensions_options: |
| 254 | print('No supported extensions list option for %s' % service) |
caoyue | ab33302 | 2016-01-25 16:45:21 +0800 | [diff] [blame] | 255 | sys.exit(1) |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 256 | return extensions_options[service] |
| 257 | |
| 258 | |
| 259 | def verify_extensions(os, service, results): |
| 260 | extensions_client = get_extension_client(os, service) |
David Kranz | 5cf4ba4 | 2015-02-10 14:00:50 -0500 | [diff] [blame] | 261 | if service != 'swift': |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 262 | resp = extensions_client.list_extensions() |
| 263 | else: |
ghanshyam | 17d8a48 | 2017-07-21 03:10:48 +0000 | [diff] [blame] | 264 | resp = extensions_client.list_capabilities() |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 265 | # 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 Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 268 | if isinstance(resp, dict): |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 269 | if service == 'swift': |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 270 | # Remove Swift general information from extensions list |
| 271 | resp.pop('swift') |
| 272 | extensions = resp.keys() |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 273 | else: |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 274 | extensions = map(lambda x: x['alias'], resp['extensions']) |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 275 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 276 | else: |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 277 | extensions = map(lambda x: x['alias'], resp) |
Matthew Treinish | 0948724 | 2015-05-10 12:43:58 -0400 | [diff] [blame] | 278 | extensions = list(extensions) |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 279 | if not results.get(service): |
| 280 | results[service] = {} |
| 281 | extensions_opt = get_enabled_extensions(service) |
Martin Kopec | d7e05dd | 2018-08-14 09:20:48 +0000 | [diff] [blame] | 282 | if not extensions_opt: |
| 283 | LOG.info("'%s' has no api_extensions set.", service) |
| 284 | return results |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 285 | if extensions_opt[0] == 'all': |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 286 | results[service]['extensions'] = extensions |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 287 | 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 Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 296 | return results |
| 297 | |
| 298 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 299 | def display_results(results, update, replace): |
| 300 | update_dict = { |
| 301 | 'swift': 'object-storage-feature-enabled', |
| 302 | 'nova': 'compute-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 303 | 'cinder': 'volume-feature-enabled', |
| 304 | 'neutron': 'network-feature-enabled', |
| 305 | } |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 306 | 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 Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 310 | 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 Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 327 | else: |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 328 | 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 Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 337 | else: |
| 338 | change_option('api_extensions', update_dict[service], |
| 339 | output_string) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 340 | |
| 341 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 342 | def check_service_availability(os, update): |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 343 | services = [] |
| 344 | avail_services = [] |
| 345 | codename_match = { |
| 346 | 'volume': 'cinder', |
| 347 | 'network': 'neutron', |
| 348 | 'image': 'glance', |
| 349 | 'object_storage': 'swift', |
| 350 | 'compute': 'nova', |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 351 | 'baremetal': 'ironic', |
Matthew Treinish | 42d50f6 | 2014-04-11 19:47:13 +0000 | [diff] [blame] | 352 | 'identity': 'keystone', |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 353 | } |
| 354 | # Get catalog list for endpoints to use for validation |
David Kranz | 4571408 | 2015-04-01 14:47:33 -0400 | [diff] [blame] | 355 | _token, auth_data = os.auth_provider.get_auth() |
David Kranz | 799eee1 | 2015-04-08 11:18:19 -0400 | [diff] [blame] | 356 | if os.auth_version == 'v2': |
| 357 | catalog_key = 'serviceCatalog' |
| 358 | else: |
| 359 | catalog_key = 'catalog' |
| 360 | for entry in auth_data[catalog_key]: |
David Kranz | 4571408 | 2015-04-01 14:47:33 -0400 | [diff] [blame] | 361 | services.append(entry['type']) |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 362 | # 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 Kopec | 07a572c | 2019-01-18 14:23:06 +0000 | [diff] [blame] | 368 | if cfgname == 'identity': |
| 369 | # Keystone is a required service for tempest |
| 370 | continue |
| 371 | if catalog_type not in services: |
| 372 | try: |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 373 | 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 Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 376 | catalog_type, codename_match[cfgname])) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 377 | if update: |
| 378 | change_option(codename_match[cfgname], |
| 379 | 'service_available', False) |
Martin Kopec | 07a572c | 2019-01-18 14:23:06 +0000 | [diff] [blame] | 380 | 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 Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 387 | 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 Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 391 | catalog_type, codename_match[cfgname])) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 392 | if update: |
| 393 | change_option(codename_match[cfgname], |
| 394 | 'service_available', True) |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 395 | # If we are going to enable this we should allow |
| 396 | # extension checks. |
| 397 | avail_services.append(codename_match[cfgname]) |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 398 | else: |
| 399 | avail_services.append(codename_match[cfgname]) |
Martin Kopec | 07a572c | 2019-01-18 14:23:06 +0000 | [diff] [blame] | 400 | 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 Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 405 | return avail_services |
Matthew Treinish | d44fe03 | 2014-01-31 20:07:24 +0000 | [diff] [blame] | 406 | |
| 407 | |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 408 | def _parser_add_args(parser): |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 409 | 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 Kopec | bd9dd8e | 2017-06-28 20:52:18 +0000 | [diff] [blame] | 421 | "with -u the values which should be changed " |
| 422 | "will be printed to STDOUT") |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 423 | 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 Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 426 | |
| 427 | |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 428 | def parse_args(): |
| 429 | parser = argparse.ArgumentParser() |
| 430 | _parser_add_args(parser) |
| 431 | opts = parser.parse_args() |
| 432 | return opts |
| 433 | |
| 434 | |
| 435 | def main(opts=None): |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 436 | update = opts.update |
| 437 | replace = opts.replace_ext |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 438 | global CONF_PARSER |
| 439 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 440 | if update: |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 441 | conf_file = _get_config_file() |
Andreas Jaeger | 2f27324 | 2020-05-05 13:27:32 +0200 | [diff] [blame] | 442 | CONF_PARSER = configparser.ConfigParser() |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 443 | CONF_PARSER.optionxform = str |
Andreas Jaeger | 2f27324 | 2020-05-05 13:27:32 +0200 | [diff] [blame] | 444 | CONF_PARSER.read_file(conf_file) |
Brad Behle | 43e4fd8 | 2016-04-13 17:15:21 -0500 | [diff] [blame] | 445 | |
| 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 Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 455 | try: |
Andrea Frittoli (andreaf) | 848c4a1 | 2016-06-09 11:09:02 +0100 | [diff] [blame] | 456 | os = clients.Manager(icreds.get_primary_creds().credentials) |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 457 | 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 Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 463 | |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 464 | # 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 Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 469 | |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 470 | display_results(results, update, replace) |
| 471 | if update: |
| 472 | conf_file.close() |
zhang.lei | a4b1cef | 2016-03-01 10:50:01 +0800 | [diff] [blame] | 473 | if opts.output: |
| 474 | with open(opts.output, 'w+') as outfile: |
| 475 | CONF_PARSER.write(outfile) |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 476 | finally: |
Andrea Frittoli (andreaf) | 17209bb | 2015-05-22 10:16:57 -0700 | [diff] [blame] | 477 | icreds.clear_creds() |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 478 | |
| 479 | |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 480 | class 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 Igawa | 9262943 | 2016-06-09 12:28:09 +0900 | [diff] [blame] | 490 | main(parsed_args) |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 491 | except Exception: |
| 492 | LOG.exception("Failure verifying configuration.") |
| 493 | traceback.print_exc() |
| 494 | raise |