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 |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 19 | import sys |
| 20 | |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 21 | import httplib2 |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 22 | from oslo_serialization import jsonutils as json |
Matthew Treinish | c795b9e | 2014-06-09 17:01:10 -0400 | [diff] [blame] | 23 | from six import moves |
Matthew Treinish | f077dd2 | 2015-04-23 09:37:41 -0400 | [diff] [blame] | 24 | from six.moves.urllib import parse as urlparse |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 25 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 26 | from tempest import clients |
David Kranz | 799eee1 | 2015-04-08 11:18:19 -0400 | [diff] [blame] | 27 | from tempest.common import credentials |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 28 | from tempest import config |
| 29 | |
| 30 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 31 | CONF = config.CONF |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 32 | CONF_PARSER = None |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 33 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 34 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 35 | def _get_config_file(): |
| 36 | default_config_dir = os.path.join(os.path.abspath( |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 37 | os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), "etc") |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 38 | default_config_file = "tempest.conf" |
| 39 | |
| 40 | conf_dir = os.environ.get('TEMPEST_CONFIG_DIR', default_config_dir) |
| 41 | conf_file = os.environ.get('TEMPEST_CONFIG', default_config_file) |
| 42 | path = os.path.join(conf_dir, conf_file) |
| 43 | fd = open(path, 'rw') |
| 44 | return fd |
| 45 | |
| 46 | |
| 47 | def change_option(option, group, value): |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 48 | if not CONF_PARSER.has_section(group): |
| 49 | CONF_PARSER.add_section(group) |
| 50 | CONF_PARSER.set(group, option, str(value)) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 51 | |
| 52 | |
| 53 | def print_and_or_update(option, group, value, update): |
| 54 | print('Config option %s in group %s should be changed to: %s' |
| 55 | % (option, group, value)) |
| 56 | if update: |
| 57 | change_option(option, group, value) |
| 58 | |
| 59 | |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 60 | def contains_version(prefix, versions): |
| 61 | return any([x for x in versions if x.startswith(prefix)]) |
| 62 | |
| 63 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 64 | def verify_glance_api_versions(os, update): |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 65 | # Check glance api versions |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 66 | _, versions = os.image_client.get_versions() |
| 67 | if CONF.image_feature_enabled.api_v1 != contains_version('v1.', versions): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 68 | print_and_or_update('api_v1', 'image-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 69 | not CONF.image_feature_enabled.api_v1, update) |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 70 | if CONF.image_feature_enabled.api_v2 != contains_version('v2.', versions): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 71 | print_and_or_update('api_v2', 'image-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 72 | not CONF.image_feature_enabled.api_v2, update) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 73 | |
| 74 | |
Matthew Treinish | 9b89624 | 2014-04-23 21:25:27 +0000 | [diff] [blame] | 75 | def _get_unversioned_endpoint(base_url): |
| 76 | endpoint_parts = urlparse.urlparse(base_url) |
| 77 | endpoint = endpoint_parts.scheme + '://' + endpoint_parts.netloc |
| 78 | return endpoint |
| 79 | |
| 80 | |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 81 | def _get_api_versions(os, service): |
| 82 | client_dict = { |
| 83 | 'nova': os.servers_client, |
| 84 | 'keystone': os.identity_client, |
Matthew Treinish | 2e43963 | 2014-03-05 21:53:33 +0000 | [diff] [blame] | 85 | 'cinder': os.volumes_client, |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 86 | } |
| 87 | client_dict[service].skip_path() |
Matthew Treinish | 9b89624 | 2014-04-23 21:25:27 +0000 | [diff] [blame] | 88 | endpoint = _get_unversioned_endpoint(client_dict[service].base_url) |
Matthew Treinish | e1f32cd | 2015-02-17 15:06:13 -0500 | [diff] [blame] | 89 | dscv = CONF.identity.disable_ssl_certificate_validation |
| 90 | ca_certs = CONF.identity.ca_certificates_file |
| 91 | raw_http = httplib2.Http(disable_ssl_certificate_validation=dscv, |
| 92 | ca_certs=ca_certs) |
| 93 | __, body = raw_http.request(endpoint, 'GET') |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 94 | client_dict[service].reset_path() |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 95 | body = json.loads(body) |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 96 | if service == 'keystone': |
| 97 | versions = map(lambda x: x['id'], body['versions']['values']) |
| 98 | else: |
| 99 | versions = map(lambda x: x['id'], body['versions']) |
Matthew Treinish | 0948724 | 2015-05-10 12:43:58 -0400 | [diff] [blame] | 100 | return list(versions) |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 101 | |
| 102 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 103 | def verify_keystone_api_versions(os, update): |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 104 | # Check keystone api versions |
| 105 | versions = _get_api_versions(os, 'keystone') |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 106 | if (CONF.identity_feature_enabled.api_v2 != |
| 107 | contains_version('v2.', versions)): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 108 | print_and_or_update('api_v2', 'identity-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 109 | not CONF.identity_feature_enabled.api_v2, update) |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 110 | if (CONF.identity_feature_enabled.api_v3 != |
| 111 | contains_version('v3.', versions)): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 112 | print_and_or_update('api_v3', 'identity-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 113 | not CONF.identity_feature_enabled.api_v3, update) |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 114 | |
| 115 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 116 | def verify_cinder_api_versions(os, update): |
Matthew Treinish | 2e43963 | 2014-03-05 21:53:33 +0000 | [diff] [blame] | 117 | # Check cinder api versions |
| 118 | versions = _get_api_versions(os, 'cinder') |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 119 | if (CONF.volume_feature_enabled.api_v1 != |
| 120 | contains_version('v1.', versions)): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 121 | print_and_or_update('api_v1', 'volume-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 122 | not CONF.volume_feature_enabled.api_v1, update) |
David Kranz | 0df154d | 2015-06-02 17:02:27 -0400 | [diff] [blame] | 123 | if (CONF.volume_feature_enabled.api_v2 != |
| 124 | contains_version('v2.', versions)): |
Nikita Gerasimov | 35fbdc1 | 2015-08-07 19:58:24 +0300 | [diff] [blame] | 125 | print_and_or_update('api_v2', 'volume-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 126 | not CONF.volume_feature_enabled.api_v2, update) |
Matthew Treinish | 2e43963 | 2014-03-05 21:53:33 +0000 | [diff] [blame] | 127 | |
| 128 | |
Adam Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 129 | def verify_api_versions(os, service, update): |
| 130 | verify = { |
| 131 | 'cinder': verify_cinder_api_versions, |
| 132 | 'glance': verify_glance_api_versions, |
| 133 | 'keystone': verify_keystone_api_versions, |
Adam Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 134 | } |
| 135 | if service not in verify: |
| 136 | return |
| 137 | verify[service](os, update) |
| 138 | |
| 139 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 140 | def get_extension_client(os, service): |
| 141 | extensions_client = { |
| 142 | 'nova': os.extensions_client, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 143 | 'cinder': os.volumes_extension_client, |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 144 | 'neutron': os.network_client, |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 145 | 'swift': os.account_client, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 146 | } |
Ivan Kolodyazhny | bcfc32e | 2015-08-06 13:31:36 +0300 | [diff] [blame] | 147 | # NOTE (e0ne): Use Cinder API v2 by default because v1 is deprecated |
| 148 | if CONF.volume_feature_enabled.api_v2: |
| 149 | extensions_client['cinder'] = os.volumes_v2_extension_client |
| 150 | else: |
| 151 | extensions_client['cinder'] = os.volumes_extension_client |
| 152 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 153 | if service not in extensions_client: |
| 154 | print('No tempest extensions client for %s' % service) |
| 155 | exit(1) |
| 156 | return extensions_client[service] |
| 157 | |
| 158 | |
| 159 | def get_enabled_extensions(service): |
| 160 | extensions_options = { |
| 161 | 'nova': CONF.compute_feature_enabled.api_extensions, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 162 | 'cinder': CONF.volume_feature_enabled.api_extensions, |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 163 | 'neutron': CONF.network_feature_enabled.api_extensions, |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 164 | 'swift': CONF.object_storage_feature_enabled.discoverable_apis, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 165 | } |
| 166 | if service not in extensions_options: |
| 167 | print('No supported extensions list option for %s' % service) |
| 168 | exit(1) |
| 169 | return extensions_options[service] |
| 170 | |
| 171 | |
| 172 | def verify_extensions(os, service, results): |
| 173 | extensions_client = get_extension_client(os, service) |
David Kranz | 5cf4ba4 | 2015-02-10 14:00:50 -0500 | [diff] [blame] | 174 | if service != 'swift': |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 175 | resp = extensions_client.list_extensions() |
| 176 | else: |
| 177 | __, resp = extensions_client.list_extensions() |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 178 | # For Nova, Cinder and Neutron we use the alias name rather than the |
| 179 | # 'name' field because the alias is considered to be the canonical |
| 180 | # name. |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 181 | if isinstance(resp, dict): |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 182 | if service == 'swift': |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 183 | # Remove Swift general information from extensions list |
| 184 | resp.pop('swift') |
| 185 | extensions = resp.keys() |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 186 | else: |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 187 | extensions = map(lambda x: x['alias'], resp['extensions']) |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 188 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 189 | else: |
Matthew Treinish | 54176ce | 2014-12-08 21:28:05 +0000 | [diff] [blame] | 190 | extensions = map(lambda x: x['alias'], resp) |
Matthew Treinish | 0948724 | 2015-05-10 12:43:58 -0400 | [diff] [blame] | 191 | extensions = list(extensions) |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 192 | if not results.get(service): |
| 193 | results[service] = {} |
| 194 | extensions_opt = get_enabled_extensions(service) |
| 195 | if extensions_opt[0] == 'all': |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 196 | results[service]['extensions'] = extensions |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 197 | return results |
| 198 | # Verify that all configured extensions are actually enabled |
| 199 | for extension in extensions_opt: |
| 200 | results[service][extension] = extension in extensions |
| 201 | # Verify that there aren't additional extensions enabled that aren't |
| 202 | # specified in the config list |
| 203 | for extension in extensions: |
| 204 | if extension not in extensions_opt: |
| 205 | results[service][extension] = False |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 206 | return results |
| 207 | |
| 208 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 209 | def display_results(results, update, replace): |
| 210 | update_dict = { |
| 211 | 'swift': 'object-storage-feature-enabled', |
| 212 | 'nova': 'compute-feature-enabled', |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 213 | 'cinder': 'volume-feature-enabled', |
| 214 | 'neutron': 'network-feature-enabled', |
| 215 | } |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 216 | for service in results: |
| 217 | # If all extensions are specified as being enabled there is no way to |
| 218 | # verify this so we just assume this to be true |
| 219 | if results[service].get('extensions'): |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 220 | if replace: |
| 221 | output_list = results[service].get('extensions') |
| 222 | else: |
| 223 | output_list = ['all'] |
| 224 | else: |
| 225 | extension_list = get_enabled_extensions(service) |
| 226 | output_list = [] |
| 227 | for extension in results[service]: |
| 228 | if not results[service][extension]: |
| 229 | if extension in extension_list: |
| 230 | print("%s extension: %s should not be included in the " |
| 231 | "list of enabled extensions" % (service, |
| 232 | extension)) |
| 233 | else: |
| 234 | print("%s extension: %s should be included in the list" |
| 235 | " of enabled extensions" % (service, extension)) |
| 236 | output_list.append(extension) |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 237 | else: |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 238 | output_list.append(extension) |
| 239 | if update: |
| 240 | # Sort List |
| 241 | output_list.sort() |
| 242 | # Convert list to a string |
| 243 | output_string = ', '.join(output_list) |
| 244 | if service == 'swift': |
| 245 | change_option('discoverable_apis', update_dict[service], |
| 246 | output_string) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 247 | else: |
| 248 | change_option('api_extensions', update_dict[service], |
| 249 | output_string) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 250 | |
| 251 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 252 | def check_service_availability(os, update): |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 253 | services = [] |
| 254 | avail_services = [] |
| 255 | codename_match = { |
| 256 | 'volume': 'cinder', |
| 257 | 'network': 'neutron', |
| 258 | 'image': 'glance', |
| 259 | 'object_storage': 'swift', |
| 260 | 'compute': 'nova', |
| 261 | 'orchestration': 'heat', |
| 262 | 'metering': 'ceilometer', |
| 263 | 'telemetry': 'ceilometer', |
Matthew Treinish | 42d50f6 | 2014-04-11 19:47:13 +0000 | [diff] [blame] | 264 | 'data_processing': 'sahara', |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 265 | 'baremetal': 'ironic', |
Matthew Treinish | 42d50f6 | 2014-04-11 19:47:13 +0000 | [diff] [blame] | 266 | 'identity': 'keystone', |
Victoria MartÃnez de la Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 267 | 'messaging': 'zaqar', |
Matthew Treinish | 42d50f6 | 2014-04-11 19:47:13 +0000 | [diff] [blame] | 268 | 'database': 'trove' |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 269 | } |
| 270 | # Get catalog list for endpoints to use for validation |
David Kranz | 4571408 | 2015-04-01 14:47:33 -0400 | [diff] [blame] | 271 | _token, auth_data = os.auth_provider.get_auth() |
David Kranz | 799eee1 | 2015-04-08 11:18:19 -0400 | [diff] [blame] | 272 | if os.auth_version == 'v2': |
| 273 | catalog_key = 'serviceCatalog' |
| 274 | else: |
| 275 | catalog_key = 'catalog' |
| 276 | for entry in auth_data[catalog_key]: |
David Kranz | 4571408 | 2015-04-01 14:47:33 -0400 | [diff] [blame] | 277 | services.append(entry['type']) |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 278 | # Pull all catalog types from config file and compare against endpoint list |
| 279 | for cfgname in dir(CONF._config): |
| 280 | cfg = getattr(CONF, cfgname) |
| 281 | catalog_type = getattr(cfg, 'catalog_type', None) |
| 282 | if not catalog_type: |
| 283 | continue |
| 284 | else: |
| 285 | if cfgname == 'identity': |
| 286 | # Keystone is a required service for tempest |
| 287 | continue |
| 288 | if catalog_type not in services: |
| 289 | if getattr(CONF.service_available, codename_match[cfgname]): |
| 290 | print('Endpoint type %s not found either disable service ' |
| 291 | '%s or fix the catalog_type in the config file' % ( |
Matthew Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 292 | catalog_type, codename_match[cfgname])) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 293 | if update: |
| 294 | change_option(codename_match[cfgname], |
| 295 | 'service_available', False) |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 296 | else: |
| 297 | if not getattr(CONF.service_available, |
| 298 | codename_match[cfgname]): |
| 299 | print('Endpoint type %s is available, service %s should be' |
| 300 | ' set as available in the config file.' % ( |
Matthew Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 301 | catalog_type, codename_match[cfgname])) |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 302 | if update: |
| 303 | change_option(codename_match[cfgname], |
| 304 | 'service_available', True) |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 305 | # If we are going to enable this we should allow |
| 306 | # extension checks. |
| 307 | avail_services.append(codename_match[cfgname]) |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 308 | else: |
| 309 | avail_services.append(codename_match[cfgname]) |
| 310 | return avail_services |
Matthew Treinish | d44fe03 | 2014-01-31 20:07:24 +0000 | [diff] [blame] | 311 | |
| 312 | |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 313 | def parse_args(): |
| 314 | parser = argparse.ArgumentParser() |
| 315 | parser.add_argument('-u', '--update', action='store_true', |
| 316 | help='Update the config file with results from api ' |
| 317 | 'queries. This assumes whatever is set in the ' |
| 318 | 'config file is incorrect. In the case of ' |
| 319 | 'endpoint checks where it could either be the ' |
| 320 | 'incorrect catalog type or the service available ' |
| 321 | 'option the service available option is assumed ' |
| 322 | 'to be incorrect and is thus changed') |
| 323 | parser.add_argument('-o', '--output', |
| 324 | help="Output file to write an updated config file to. " |
| 325 | "This has to be a separate file from the " |
| 326 | "original config file. If one isn't specified " |
| 327 | "with -u the new config file will be printed to " |
| 328 | "STDOUT") |
| 329 | parser.add_argument('-r', '--replace-ext', action='store_true', |
| 330 | help="If specified the all option will be replaced " |
| 331 | "with a full list of extensions") |
| 332 | args = parser.parse_args() |
| 333 | return args |
| 334 | |
| 335 | |
Matthew Treinish | f8b816a | 2014-04-23 20:35:49 +0000 | [diff] [blame] | 336 | def main(): |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 337 | print('Running config verification...') |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 338 | opts = parse_args() |
| 339 | update = opts.update |
| 340 | replace = opts.replace_ext |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 341 | global CONF_PARSER |
| 342 | |
| 343 | outfile = sys.stdout |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 344 | if update: |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 345 | conf_file = _get_config_file() |
Matthew Treinish | f097171 | 2014-04-11 20:08:53 +0000 | [diff] [blame] | 346 | if opts.output: |
David Kranz | f20ac32 | 2014-05-02 16:46:15 -0400 | [diff] [blame] | 347 | outfile = open(opts.output, 'w+') |
| 348 | CONF_PARSER = moves.configparser.SafeConfigParser() |
| 349 | CONF_PARSER.optionxform = str |
| 350 | CONF_PARSER.readfp(conf_file) |
David Kranz | 799eee1 | 2015-04-08 11:18:19 -0400 | [diff] [blame] | 351 | icreds = credentials.get_isolated_credentials('verify_tempest_config') |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 352 | try: |
| 353 | os = clients.Manager(icreds.get_primary_creds()) |
| 354 | services = check_service_availability(os, update) |
| 355 | results = {} |
| 356 | for service in ['nova', 'cinder', 'neutron', 'swift']: |
| 357 | if service not in services: |
| 358 | continue |
| 359 | results = verify_extensions(os, service, results) |
Adam Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 360 | |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 361 | # Verify API versions of all services in the keystone catalog and |
| 362 | # keystone itself. |
| 363 | services.append('keystone') |
| 364 | for service in services: |
| 365 | verify_api_versions(os, service, update) |
Adam Gandelman | 03af556 | 2014-10-07 12:22:48 -0700 | [diff] [blame] | 366 | |
David Kranz | 5fcac94 | 2015-05-08 17:43:45 -0400 | [diff] [blame] | 367 | display_results(results, update, replace) |
| 368 | if update: |
| 369 | conf_file.close() |
| 370 | CONF_PARSER.write(outfile) |
| 371 | outfile.close() |
| 372 | finally: |
| 373 | icreds.clear_isolated_creds() |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 374 | |
| 375 | |
| 376 | if __name__ == "__main__": |
Matthew Treinish | f8b816a | 2014-04-23 20:35:49 +0000 | [diff] [blame] | 377 | main() |