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 | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 17 | import json |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 18 | import sys |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 19 | import urlparse |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 20 | |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 21 | import httplib2 |
| 22 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 23 | from tempest import clients |
| 24 | from tempest import config |
| 25 | |
| 26 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 27 | CONF = config.CONF |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 28 | RAW_HTTP = httplib2.Http() |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 29 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 30 | |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 31 | def verify_glance_api_versions(os): |
| 32 | # Check glance api versions |
| 33 | __, versions = os.image_client.get_versions() |
| 34 | if CONF.image_feature_enabled.api_v1 != ('v1.1' in versions or 'v1.0' in |
| 35 | versions): |
Sean Dague | 6b44788 | 2013-12-02 11:09:58 -0500 | [diff] [blame] | 36 | print('Config option image api_v1 should be change to: %s' % ( |
| 37 | not CONF.image_feature_enabled.api_v1)) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 38 | if CONF.image_feature_enabled.api_v2 != ('v2.0' in versions): |
Sean Dague | 6b44788 | 2013-12-02 11:09:58 -0500 | [diff] [blame] | 39 | print('Config option image api_v2 should be change to: %s' % ( |
| 40 | not CONF.image_feature_enabled.api_v2)) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 41 | |
| 42 | |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 43 | def _get_api_versions(os, service): |
| 44 | client_dict = { |
| 45 | 'nova': os.servers_client, |
| 46 | 'keystone': os.identity_client, |
| 47 | } |
| 48 | client_dict[service].skip_path() |
| 49 | endpoint_parts = urlparse.urlparse(client_dict[service]) |
| 50 | endpoint = endpoint_parts.scheme + '//' + endpoint_parts.netloc |
Matthew Treinish | a508081 | 2014-02-11 15:49:04 +0000 | [diff] [blame] | 51 | __, body = RAW_HTTP.request(endpoint, 'GET') |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 52 | client_dict[service].reset_path() |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 53 | body = json.loads(body) |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 54 | if service == 'keystone': |
| 55 | versions = map(lambda x: x['id'], body['versions']['values']) |
| 56 | else: |
| 57 | versions = map(lambda x: x['id'], body['versions']) |
| 58 | return versions |
| 59 | |
| 60 | |
| 61 | def verify_keystone_api_versions(os): |
| 62 | # Check keystone api versions |
| 63 | versions = _get_api_versions(os, 'keystone') |
| 64 | if CONF.identity_feature_enabled.api_v2 != ('v2.0' in versions): |
| 65 | print('Config option identity api_v2 should be change to %s' % ( |
| 66 | not CONF.identity_feature_enabled.api_v2)) |
| 67 | if CONF.identity_feature_enabled.api_v3 != ('v3.0' in versions): |
| 68 | print('Config option identity api_v3 should be change to %s' % ( |
| 69 | not CONF.identity_feature_enabled.api_v3)) |
| 70 | |
| 71 | |
| 72 | def verify_nova_api_versions(os): |
| 73 | versions = _get_api_versions(os, 'nova') |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 74 | if CONF.compute_feature_enabled.api_v3 != ('v3.0' in versions): |
| 75 | print('Config option compute api_v3 should be change to: %s' % ( |
| 76 | not CONF.compute_feature_enabled.api_v3)) |
| 77 | |
| 78 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 79 | def get_extension_client(os, service): |
| 80 | extensions_client = { |
| 81 | 'nova': os.extensions_client, |
| 82 | 'nova_v3': os.extensions_v3_client, |
| 83 | 'cinder': os.volumes_extension_client, |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 84 | 'neutron': os.network_client, |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 85 | 'swift': os.account_client, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 86 | } |
| 87 | if service not in extensions_client: |
| 88 | print('No tempest extensions client for %s' % service) |
| 89 | exit(1) |
| 90 | return extensions_client[service] |
| 91 | |
| 92 | |
| 93 | def get_enabled_extensions(service): |
| 94 | extensions_options = { |
| 95 | 'nova': CONF.compute_feature_enabled.api_extensions, |
| 96 | 'nova_v3': CONF.compute_feature_enabled.api_v3_extensions, |
| 97 | 'cinder': CONF.volume_feature_enabled.api_extensions, |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 98 | 'neutron': CONF.network_feature_enabled.api_extensions, |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 99 | 'swift': CONF.object_storage_feature_enabled.discoverable_apis, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 100 | } |
| 101 | if service not in extensions_options: |
| 102 | print('No supported extensions list option for %s' % service) |
| 103 | exit(1) |
| 104 | return extensions_options[service] |
| 105 | |
| 106 | |
| 107 | def verify_extensions(os, service, results): |
| 108 | extensions_client = get_extension_client(os, service) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 109 | __, resp = extensions_client.list_extensions() |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 110 | if isinstance(resp, dict): |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 111 | # Neutron's extension 'name' field has is not a single word (it has |
| 112 | # spaces in the string) Since that can't be used for list option the |
| 113 | # api_extension option in the network-feature-enabled group uses alias |
| 114 | # instead of name. |
| 115 | if service == 'neutron': |
| 116 | extensions = map(lambda x: x['alias'], resp['extensions']) |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 117 | elif service == 'swift': |
| 118 | # Remove Swift general information from extensions list |
| 119 | resp.pop('swift') |
| 120 | extensions = resp.keys() |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 121 | else: |
| 122 | extensions = map(lambda x: x['name'], resp['extensions']) |
| 123 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 124 | else: |
| 125 | extensions = map(lambda x: x['name'], resp) |
| 126 | if not results.get(service): |
| 127 | results[service] = {} |
| 128 | extensions_opt = get_enabled_extensions(service) |
| 129 | if extensions_opt[0] == 'all': |
| 130 | results[service]['extensions'] = 'all' |
| 131 | return results |
| 132 | # Verify that all configured extensions are actually enabled |
| 133 | for extension in extensions_opt: |
| 134 | results[service][extension] = extension in extensions |
| 135 | # Verify that there aren't additional extensions enabled that aren't |
| 136 | # specified in the config list |
| 137 | for extension in extensions: |
| 138 | if extension not in extensions_opt: |
| 139 | results[service][extension] = False |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 140 | return results |
| 141 | |
| 142 | |
| 143 | def display_results(results): |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 144 | for service in results: |
| 145 | # If all extensions are specified as being enabled there is no way to |
| 146 | # verify this so we just assume this to be true |
| 147 | if results[service].get('extensions'): |
| 148 | continue |
| 149 | extension_list = get_enabled_extensions(service) |
| 150 | for extension in results[service]: |
| 151 | if not results[service][extension]: |
| 152 | if extension in extension_list: |
| 153 | print("%s extension: %s should not be included in the list" |
| 154 | " of enabled extensions" % (service, extension)) |
| 155 | else: |
| 156 | print("%s extension: %s should be included in the list of " |
| 157 | "enabled extensions" % (service, extension)) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 158 | |
| 159 | |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 160 | def check_service_availability(os): |
| 161 | services = [] |
| 162 | avail_services = [] |
| 163 | codename_match = { |
| 164 | 'volume': 'cinder', |
| 165 | 'network': 'neutron', |
| 166 | 'image': 'glance', |
| 167 | 'object_storage': 'swift', |
| 168 | 'compute': 'nova', |
| 169 | 'orchestration': 'heat', |
| 170 | 'metering': 'ceilometer', |
| 171 | 'telemetry': 'ceilometer', |
| 172 | 'data_processing': 'savanna', |
| 173 | 'baremetal': 'ironic', |
| 174 | 'identity': 'keystone' |
| 175 | |
| 176 | } |
| 177 | # Get catalog list for endpoints to use for validation |
| 178 | __, endpoints = os.endpoints_client.list_endpoints() |
| 179 | for endpoint in endpoints: |
| 180 | __, service = os.service_client.get_service(endpoint['service_id']) |
| 181 | services.append(service['type']) |
| 182 | # Pull all catalog types from config file and compare against endpoint list |
| 183 | for cfgname in dir(CONF._config): |
| 184 | cfg = getattr(CONF, cfgname) |
| 185 | catalog_type = getattr(cfg, 'catalog_type', None) |
| 186 | if not catalog_type: |
| 187 | continue |
| 188 | else: |
| 189 | if cfgname == 'identity': |
| 190 | # Keystone is a required service for tempest |
| 191 | continue |
| 192 | if catalog_type not in services: |
| 193 | if getattr(CONF.service_available, codename_match[cfgname]): |
| 194 | print('Endpoint type %s not found either disable service ' |
| 195 | '%s or fix the catalog_type in the config file' % ( |
| 196 | catalog_type, codename_match[cfgname])) |
| 197 | else: |
| 198 | if not getattr(CONF.service_available, |
| 199 | codename_match[cfgname]): |
| 200 | print('Endpoint type %s is available, service %s should be' |
| 201 | ' set as available in the config file.' % ( |
| 202 | catalog_type, codename_match[cfgname])) |
| 203 | else: |
| 204 | avail_services.append(codename_match[cfgname]) |
| 205 | return avail_services |
Matthew Treinish | d44fe03 | 2014-01-31 20:07:24 +0000 | [diff] [blame] | 206 | |
| 207 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 208 | def main(argv): |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 209 | print('Running config verification...') |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 210 | os = clients.ComputeAdminManager(interface='json') |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 211 | services = check_service_availability(os) |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 212 | results = {} |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 213 | for service in ['nova', 'nova_v3', 'cinder', 'neutron', 'swift']: |
Matthew Treinish | 221bd7f | 2014-02-07 21:16:09 +0000 | [diff] [blame] | 214 | if service == 'nova_v3' and 'nova' not in services: |
| 215 | continue |
| 216 | elif service not in services: |
Matthew Treinish | d44fe03 | 2014-01-31 20:07:24 +0000 | [diff] [blame] | 217 | continue |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 218 | results = verify_extensions(os, service, results) |
Matthew Treinish | 864fe07 | 2014-03-02 03:47:26 +0000 | [diff] [blame] | 219 | verify_keystone_api_versions(os) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 220 | verify_glance_api_versions(os) |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 221 | verify_nova_api_versions(os) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 222 | display_results(results) |
| 223 | |
| 224 | |
| 225 | if __name__ == "__main__": |
| 226 | main(sys.argv) |