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 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 17 | import argparse |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 18 | import os |
Brant Knudson | 28de8d5 | 2016-03-18 13:50:02 -0500 | [diff] [blame] | 19 | import re |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 20 | import sys |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 21 | import traceback |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 22 | |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 23 | from cliff import command |
| 24 | from oslo_log import log as logging |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 25 | from oslo_serialization import jsonutils as json |
Matthew Treinish | c795b9e | 2014-06-09 17:01:10 -0400 | [diff] [blame] | 26 | from six import moves |
Matthew Treinish | f077dd2 | 2015-04-23 09:37:41 -0400 | [diff] [blame] | 27 | from six.moves.urllib import parse as urlparse |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 28 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 29 | from tempest import clients |
Andrea Frittoli (andreaf) | 290b3e1 | 2015-10-08 10:25:02 +0100 | [diff] [blame] | 30 | from tempest.common import credentials_factory as credentials |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 31 | from tempest import config |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 32 | import tempest.lib.common.http |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 33 | |
| 34 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 35 | CONF = config.CONF |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 36 | CONF_PARSER = None |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 37 | |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 38 | LOG = logging.getLogger(__name__) |
| 39 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 40 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 41 | def _get_config_file(): |
| 42 | default_config_dir = os.path.join(os.path.abspath( |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 43 | os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), "etc") |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 44 | default_config_file = "tempest.conf" |
| 45 | |
| 46 | conf_dir = os.environ.get('TEMPEST_CONFIG_DIR', default_config_dir) |
| 47 | conf_file = os.environ.get('TEMPEST_CONFIG', default_config_file) |
| 48 | path = os.path.join(conf_dir, conf_file) |
Sirushti Murugesan | 12dc973 | 2016-07-13 22:49:17 +0530 | [diff] [blame] | 49 | fd = open(path, 'r+') |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 50 | return fd |
| 51 | |
| 52 | |
| 53 | def change_option(option, group, value): |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 54 | if not CONF_PARSER.has_section(group): |
| 55 | CONF_PARSER.add_section(group) |
| 56 | CONF_PARSER.set(group, option, str(value)) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 57 | |
| 58 | |
| 59 | def print_and_or_update(option, group, value, update): |
| 60 | print('Config option %s in group %s should be changed to: %s' |
| 61 | % (option, group, value)) |
| 62 | if update: |
| 63 | change_option(option, group, value) |
| 64 | |
| 65 | |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 66 | def contains_version(prefix, versions): |
| 67 | return any([x for x in versions if x.startswith(prefix)]) |
| 68 | |
| 69 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 70 | def verify_glance_api_versions(os, update): |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 71 | # Check glance api versions |
Julien Danjou | 9951876 | 2016-09-19 17:58:25 +0200 | [diff] [blame] | 72 | _, versions = os.image_client.get_versions() |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 73 | if CONF.image_feature_enabled.api_v1 != contains_version('v1.', versions): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 74 | print_and_or_update('api_v1', 'image-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 75 | not CONF.image_feature_enabled.api_v1, update) |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 76 | if CONF.image_feature_enabled.api_v2 != contains_version('v2.', versions): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 77 | print_and_or_update('api_v2', 'image-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 78 | not CONF.image_feature_enabled.api_v2, update) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 79 | |
| 80 | |
Brant Knudson | 28de8d5 | 2016-03-18 13:50:02 -0500 | [diff] [blame] | 81 | def _remove_version_project(url_path): |
| 82 | # The regex matches strings like /v2.0, /v3/, /v2.1/project-id/ |
| 83 | return re.sub(r'/v\d+(\.\d+)?(/[^/]+)?', '', url_path) |
| 84 | |
| 85 | |
Matthew Treinish | 9b89624 | 2014-04-23 21:25:27 +0000 | [diff] [blame] | 86 | def _get_unversioned_endpoint(base_url): |
| 87 | endpoint_parts = urlparse.urlparse(base_url) |
Brant Knudson | 28de8d5 | 2016-03-18 13:50:02 -0500 | [diff] [blame] | 88 | new_path = _remove_version_project(endpoint_parts.path) |
| 89 | endpoint_parts = endpoint_parts._replace(path=new_path) |
| 90 | endpoint = urlparse.urlunparse(endpoint_parts) |
Matthew Treinish | 9b89624 | 2014-04-23 21:25:27 +0000 | [diff] [blame] | 91 | return endpoint |
| 92 | |
| 93 | |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 94 | def _get_api_versions(os, service): |
| 95 | client_dict = { |
| 96 | 'nova': os.servers_client, |
| 97 | 'keystone': os.identity_client, |
Sean McGinnis | ff5f0c1 | 2017-07-07 16:39:24 -0500 | [diff] [blame] | 98 | 'cinder': os.volumes_client_latest, |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 99 | } |
Ivan Kolodyazhny | b24f904 | 2017-06-12 18:54:18 +0300 | [diff] [blame] | 100 | if service != 'keystone' and service != 'cinder': |
| 101 | # Since keystone and cinder may be listening on a path, |
| 102 | # do not remove the path. |
Brant Knudson | 28de8d5 | 2016-03-18 13:50:02 -0500 | [diff] [blame] | 103 | client_dict[service].skip_path() |
Matthew Treinish | 9b89624 | 2014-04-23 21:25:27 +0000 | [diff] [blame] | 104 | endpoint = _get_unversioned_endpoint(client_dict[service].base_url) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 105 | |
| 106 | http = tempest.lib.common.http.ClosingHttp( |
Daniel Mellado | cad3f3d | 2016-08-19 14:17:16 +0000 | [diff] [blame] | 107 | CONF.identity.disable_ssl_certificate_validation, |
| 108 | CONF.identity.ca_certificates_file) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 109 | |
| 110 | __, body = http.request(endpoint, 'GET') |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 111 | client_dict[service].reset_path() |
Brant Knudson | 5a59f87 | 2016-03-18 13:07:00 -0500 | [diff] [blame] | 112 | try: |
| 113 | body = json.loads(body) |
| 114 | except ValueError: |
| 115 | LOG.error( |
| 116 | 'Failed to get a JSON response from unversioned endpoint %s ' |
| 117 | '(versioned endpoint was %s). Response is:\n%s', |
| 118 | endpoint, client_dict[service].base_url, body[:100]) |
| 119 | raise |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 120 | if service == 'keystone': |
| 121 | versions = map(lambda x: x['id'], body['versions']['values']) |
| 122 | else: |
| 123 | versions = map(lambda x: x['id'], body['versions']) |
Matthew Treinish | 0948724 | 2015-05-10 12:43:58 -0400 | [diff] [blame] | 124 | return list(versions) |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 125 | |
| 126 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 127 | def verify_keystone_api_versions(os, update): |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 128 | # Check keystone api versions |
| 129 | versions = _get_api_versions(os, 'keystone') |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 130 | if (CONF.identity_feature_enabled.api_v2 != |
| 131 | contains_version('v2.', versions)): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 132 | print_and_or_update('api_v2', 'identity-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 133 | not CONF.identity_feature_enabled.api_v2, update) |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 134 | if (CONF.identity_feature_enabled.api_v3 != |
| 135 | contains_version('v3.', versions)): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 136 | print_and_or_update('api_v3', 'identity-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 137 | not CONF.identity_feature_enabled.api_v3, update) |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 138 | |
| 139 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 140 | def verify_cinder_api_versions(os, update): |
Matthew Treinish | 2e43963 | 2014-03-05 21:53:33 +0000 | [diff] [blame] | 141 | # Check cinder api versions |
| 142 | versions = _get_api_versions(os, 'cinder') |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 143 | if (CONF.volume_feature_enabled.api_v1 != |
| 144 | contains_version('v1.', versions)): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 145 | print_and_or_update('api_v1', 'volume-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 146 | not CONF.volume_feature_enabled.api_v1, update) |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 147 | if (CONF.volume_feature_enabled.api_v2 != |
| 148 | contains_version('v2.', versions)): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 149 | print_and_or_update('api_v2', 'volume-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 150 | not CONF.volume_feature_enabled.api_v2, update) |
Nikita Gerasimov | 3b169cc | 2016-08-10 17:10:42 +0300 | [diff] [blame] | 151 | if (CONF.volume_feature_enabled.api_v3 != |
| 152 | contains_version('v3.', versions)): |
| 153 | print_and_or_update('api_v3', 'volume-feature-enabled', |
| 154 | not CONF.volume_feature_enabled.api_v3, update) |
Matthew Treinish | 2e43963 | 2014-03-05 21:53:33 +0000 | [diff] [blame] | 155 | |
| 156 | |
Adam Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 157 | def verify_api_versions(os, service, update): |
| 158 | verify = { |
| 159 | 'cinder': verify_cinder_api_versions, |
| 160 | 'glance': verify_glance_api_versions, |
| 161 | 'keystone': verify_keystone_api_versions, |
Adam Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 162 | } |
| 163 | if service not in verify: |
| 164 | return |
| 165 | verify[service](os, update) |
| 166 | |
| 167 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 168 | def get_extension_client(os, service): |
| 169 | extensions_client = { |
| 170 | 'nova': os.extensions_client, |
Ken'ichi Ohmichi | 52bb812 | 2016-01-26 01:43:06 +0000 | [diff] [blame] | 171 | 'neutron': os.network_extensions_client, |
ghanshyam | f29831d | 2016-12-12 18:45:23 +0900 | [diff] [blame] | 172 | 'swift': os.capabilities_client, |
Ken'ichi Ohmichi | 8b876dd | 2017-05-04 14:30:31 -0700 | [diff] [blame] | 173 | # NOTE: Cinder v3 API is current and v2 and v1 are deprecated. |
| 174 | # V3 extension API is the same as v2, so we reuse the v2 client |
| 175 | # for v3 API also. |
| 176 | 'cinder': os.volumes_v2_extension_client, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 177 | } |
Ivan Kolodyazhny | bcfc32e | 2015-08-06 13:31:36 +0300 | [diff] [blame] | 178 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 179 | if service not in extensions_client: |
| 180 | print('No tempest extensions client for %s' % service) |
caoyue | ab33302 | 2016-01-25 16:45:21 +0800 | [diff] [blame] | 181 | sys.exit(1) |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 182 | return extensions_client[service] |
| 183 | |
| 184 | |
| 185 | def get_enabled_extensions(service): |
| 186 | extensions_options = { |
| 187 | 'nova': CONF.compute_feature_enabled.api_extensions, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 188 | 'cinder': CONF.volume_feature_enabled.api_extensions, |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 189 | 'neutron': CONF.network_feature_enabled.api_extensions, |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 190 | 'swift': CONF.object_storage_feature_enabled.discoverable_apis, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 191 | } |
| 192 | if service not in extensions_options: |
| 193 | print('No supported extensions list option for %s' % service) |
caoyue | ab33302 | 2016-01-25 16:45:21 +0800 | [diff] [blame] | 194 | sys.exit(1) |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 195 | return extensions_options[service] |
| 196 | |
| 197 | |
| 198 | def verify_extensions(os, service, results): |
| 199 | extensions_client = get_extension_client(os, service) |
David Kranz | 5cf4ba4 | 2015-02-10 14:00:50 -0500 | [diff] [blame] | 200 | if service != 'swift': |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 201 | resp = extensions_client.list_extensions() |
| 202 | else: |
ghanshyam | 17d8a48 | 2017-07-21 03:10:48 +0000 | [diff] [blame] | 203 | resp = extensions_client.list_capabilities() |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 204 | # For Nova, Cinder and Neutron we use the alias name rather than the |
| 205 | # 'name' field because the alias is considered to be the canonical |
| 206 | # name. |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 207 | if isinstance(resp, dict): |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 208 | if service == 'swift': |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 209 | # Remove Swift general information from extensions list |
| 210 | resp.pop('swift') |
| 211 | extensions = resp.keys() |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 212 | else: |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 213 | extensions = map(lambda x: x['alias'], resp['extensions']) |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 214 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 215 | else: |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 216 | extensions = map(lambda x: x['alias'], resp) |
Matthew Treinish | 0948724 | 2015-05-10 12:43:58 -0400 | [diff] [blame] | 217 | extensions = list(extensions) |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 218 | if not results.get(service): |
| 219 | results[service] = {} |
| 220 | extensions_opt = get_enabled_extensions(service) |
| 221 | if extensions_opt[0] == 'all': |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 222 | results[service]['extensions'] = extensions |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 223 | return results |
| 224 | # Verify that all configured extensions are actually enabled |
| 225 | for extension in extensions_opt: |
| 226 | results[service][extension] = extension in extensions |
| 227 | # Verify that there aren't additional extensions enabled that aren't |
| 228 | # specified in the config list |
| 229 | for extension in extensions: |
| 230 | if extension not in extensions_opt: |
| 231 | results[service][extension] = False |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 232 | return results |
| 233 | |
| 234 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 235 | def display_results(results, update, replace): |
| 236 | update_dict = { |
| 237 | 'swift': 'object-storage-feature-enabled', |
| 238 | 'nova': 'compute-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 239 | 'cinder': 'volume-feature-enabled', |
| 240 | 'neutron': 'network-feature-enabled', |
| 241 | } |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 242 | for service in results: |
| 243 | # If all extensions are specified as being enabled there is no way to |
| 244 | # verify this so we just assume this to be true |
| 245 | if results[service].get('extensions'): |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 246 | if replace: |
| 247 | output_list = results[service].get('extensions') |
| 248 | else: |
| 249 | output_list = ['all'] |
| 250 | else: |
| 251 | extension_list = get_enabled_extensions(service) |
| 252 | output_list = [] |
| 253 | for extension in results[service]: |
| 254 | if not results[service][extension]: |
| 255 | if extension in extension_list: |
| 256 | print("%s extension: %s should not be included in the " |
| 257 | "list of enabled extensions" % (service, |
| 258 | extension)) |
| 259 | else: |
| 260 | print("%s extension: %s should be included in the list" |
| 261 | " of enabled extensions" % (service, extension)) |
| 262 | output_list.append(extension) |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 263 | else: |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 264 | output_list.append(extension) |
| 265 | if update: |
| 266 | # Sort List |
| 267 | output_list.sort() |
| 268 | # Convert list to a string |
| 269 | output_string = ', '.join(output_list) |
| 270 | if service == 'swift': |
| 271 | change_option('discoverable_apis', update_dict[service], |
| 272 | output_string) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 273 | else: |
| 274 | change_option('api_extensions', update_dict[service], |
| 275 | output_string) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 276 | |
| 277 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 278 | def check_service_availability(os, update): |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 279 | services = [] |
| 280 | avail_services = [] |
| 281 | codename_match = { |
| 282 | 'volume': 'cinder', |
| 283 | 'network': 'neutron', |
| 284 | 'image': 'glance', |
| 285 | 'object_storage': 'swift', |
| 286 | 'compute': 'nova', |
| 287 | 'orchestration': 'heat', |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 288 | 'baremetal': 'ironic', |
Matthew Treinish | 42d50f6 | 2014-04-11 19:47:13 +0000 | [diff] [blame] | 289 | 'identity': 'keystone', |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 290 | } |
| 291 | # Get catalog list for endpoints to use for validation |
David Kranz | 4571408 | 2015-04-01 14:47:33 -0400 | [diff] [blame] | 292 | _token, auth_data = os.auth_provider.get_auth() |
David Kranz | 799eee1 | 2015-04-08 11:18:19 -0400 | [diff] [blame] | 293 | if os.auth_version == 'v2': |
| 294 | catalog_key = 'serviceCatalog' |
| 295 | else: |
| 296 | catalog_key = 'catalog' |
| 297 | for entry in auth_data[catalog_key]: |
David Kranz | 4571408 | 2015-04-01 14:47:33 -0400 | [diff] [blame] | 298 | services.append(entry['type']) |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 299 | # Pull all catalog types from config file and compare against endpoint list |
| 300 | for cfgname in dir(CONF._config): |
| 301 | cfg = getattr(CONF, cfgname) |
| 302 | catalog_type = getattr(cfg, 'catalog_type', None) |
| 303 | if not catalog_type: |
| 304 | continue |
| 305 | else: |
| 306 | if cfgname == 'identity': |
| 307 | # Keystone is a required service for tempest |
| 308 | continue |
| 309 | if catalog_type not in services: |
| 310 | if getattr(CONF.service_available, codename_match[cfgname]): |
| 311 | print('Endpoint type %s not found either disable service ' |
| 312 | '%s or fix the catalog_type in the config file' % ( |
Matthew Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 313 | catalog_type, codename_match[cfgname])) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 314 | if update: |
| 315 | change_option(codename_match[cfgname], |
| 316 | 'service_available', False) |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 317 | else: |
| 318 | if not getattr(CONF.service_available, |
| 319 | codename_match[cfgname]): |
| 320 | print('Endpoint type %s is available, service %s should be' |
| 321 | ' set as available in the config file.' % ( |
Matthew Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 322 | catalog_type, codename_match[cfgname])) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 323 | if update: |
| 324 | change_option(codename_match[cfgname], |
| 325 | 'service_available', True) |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 326 | # If we are going to enable this we should allow |
| 327 | # extension checks. |
| 328 | avail_services.append(codename_match[cfgname]) |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 329 | else: |
| 330 | avail_services.append(codename_match[cfgname]) |
| 331 | return avail_services |
Matthew Treinish | d44fe03 | 2014-01-31 20:07:24 +0000 | [diff] [blame] | 332 | |
| 333 | |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 334 | def _parser_add_args(parser): |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 335 | parser.add_argument('-u', '--update', action='store_true', |
| 336 | help='Update the config file with results from api ' |
| 337 | 'queries. This assumes whatever is set in the ' |
| 338 | 'config file is incorrect. In the case of ' |
| 339 | 'endpoint checks where it could either be the ' |
| 340 | 'incorrect catalog type or the service available ' |
| 341 | 'option the service available option is assumed ' |
| 342 | 'to be incorrect and is thus changed') |
| 343 | parser.add_argument('-o', '--output', |
| 344 | help="Output file to write an updated config file to. " |
| 345 | "This has to be a separate file from the " |
| 346 | "original config file. If one isn't specified " |
| 347 | "with -u the new config file will be printed to " |
| 348 | "STDOUT") |
| 349 | parser.add_argument('-r', '--replace-ext', action='store_true', |
| 350 | help="If specified the all option will be replaced " |
| 351 | "with a full list of extensions") |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 352 | |
| 353 | |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 354 | def parse_args(): |
| 355 | parser = argparse.ArgumentParser() |
| 356 | _parser_add_args(parser) |
| 357 | opts = parser.parse_args() |
| 358 | return opts |
| 359 | |
| 360 | |
| 361 | def main(opts=None): |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 362 | print('Running config verification...') |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 363 | if opts is None: |
| 364 | print("Use of: 'verify-tempest-config' is deprecated, " |
| 365 | "please use: 'tempest verify-config'") |
| 366 | opts = parse_args() |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 367 | update = opts.update |
| 368 | replace = opts.replace_ext |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 369 | global CONF_PARSER |
| 370 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 371 | if update: |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 372 | conf_file = _get_config_file() |
Janonymous | 8254a3f | 2016-09-15 10:38:48 +0530 | [diff] [blame] | 373 | CONF_PARSER = moves.configparser.ConfigParser() |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 374 | CONF_PARSER.optionxform = str |
| 375 | CONF_PARSER.readfp(conf_file) |
Brad Behle | 43e4fd8 | 2016-04-13 17:15:21 -0500 | [diff] [blame] | 376 | |
| 377 | # Indicate not to create network resources as part of getting credentials |
| 378 | net_resources = { |
| 379 | 'network': False, |
| 380 | 'router': False, |
| 381 | 'subnet': False, |
| 382 | 'dhcp': False |
| 383 | } |
| 384 | icreds = credentials.get_credentials_provider( |
| 385 | 'verify_tempest_config', network_resources=net_resources) |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 386 | try: |
Andrea Frittoli (andreaf) | 848c4a1 | 2016-06-09 11:09:02 +0100 | [diff] [blame] | 387 | os = clients.Manager(icreds.get_primary_creds().credentials) |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 388 | services = check_service_availability(os, update) |
| 389 | results = {} |
| 390 | for service in ['nova', 'cinder', 'neutron', 'swift']: |
| 391 | if service not in services: |
| 392 | continue |
| 393 | results = verify_extensions(os, service, results) |
Adam Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 394 | |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 395 | # Verify API versions of all services in the keystone catalog and |
| 396 | # keystone itself. |
| 397 | services.append('keystone') |
| 398 | for service in services: |
| 399 | verify_api_versions(os, service, update) |
Adam Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 400 | |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 401 | display_results(results, update, replace) |
| 402 | if update: |
| 403 | conf_file.close() |
zhang.lei | a4b1cef | 2016-03-01 10:50:01 +0800 | [diff] [blame] | 404 | if opts.output: |
| 405 | with open(opts.output, 'w+') as outfile: |
| 406 | CONF_PARSER.write(outfile) |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 407 | finally: |
Andrea Frittoli (andreaf) | 17209bb | 2015-05-22 10:16:57 -0700 | [diff] [blame] | 408 | icreds.clear_creds() |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 409 | |
| 410 | |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 411 | class TempestVerifyConfig(command.Command): |
| 412 | """Verify your current tempest configuration""" |
| 413 | |
| 414 | def get_parser(self, prog_name): |
| 415 | parser = super(TempestVerifyConfig, self).get_parser(prog_name) |
| 416 | _parser_add_args(parser) |
| 417 | return parser |
| 418 | |
| 419 | def take_action(self, parsed_args): |
| 420 | try: |
Masayuki Igawa | 9262943 | 2016-06-09 12:28:09 +0900 | [diff] [blame] | 421 | main(parsed_args) |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 422 | except Exception: |
| 423 | LOG.exception("Failure verifying configuration.") |
| 424 | traceback.print_exc() |
| 425 | raise |
David Paterson | e45aa84 | 2015-11-18 16:12:27 -0800 | [diff] [blame] | 426 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 427 | if __name__ == "__main__": |
Matthew Treinish | f8b816a | 2014-04-23 20:35:49 +0000 | [diff] [blame] | 428 | main() |