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 |
| 19 | |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 20 | import httplib2 |
| 21 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 22 | from tempest import clients |
| 23 | from tempest import config |
| 24 | |
| 25 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 26 | CONF = config.CONF |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 27 | RAW_HTTP = httplib2.Http() |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 28 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 29 | |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 30 | def verify_glance_api_versions(os): |
| 31 | # Check glance api versions |
| 32 | __, versions = os.image_client.get_versions() |
| 33 | if CONF.image_feature_enabled.api_v1 != ('v1.1' in versions or 'v1.0' in |
| 34 | versions): |
Sean Dague | 6b44788 | 2013-12-02 11:09:58 -0500 | [diff] [blame] | 35 | print('Config option image api_v1 should be change to: %s' % ( |
| 36 | not CONF.image_feature_enabled.api_v1)) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 37 | if CONF.image_feature_enabled.api_v2 != ('v2.0' in versions): |
Sean Dague | 6b44788 | 2013-12-02 11:09:58 -0500 | [diff] [blame] | 38 | print('Config option image api_v2 should be change to: %s' % ( |
| 39 | not CONF.image_feature_enabled.api_v2)) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 40 | |
| 41 | |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 42 | def verify_nova_api_versions(os): |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 43 | # Check nova api versions - only get base URL without PATH |
| 44 | os.servers_client.skip_path = True |
Matthew Treinish | a508081 | 2014-02-11 15:49:04 +0000 | [diff] [blame] | 45 | # The nova base endpoint url includes the version but to get the versions |
| 46 | # list the unversioned endpoint is needed |
| 47 | v2_endpoint = os.servers_client.base_url |
| 48 | v2_endpoint_parts = v2_endpoint.split('/') |
| 49 | endpoint = v2_endpoint_parts[0] + '//' + v2_endpoint_parts[2] |
| 50 | __, body = RAW_HTTP.request(endpoint, 'GET') |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 51 | body = json.loads(body) |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 52 | # Restore full base_url |
| 53 | os.servers_client.skip_path = False |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 54 | versions = map(lambda x: x['id'], body['versions']) |
| 55 | if CONF.compute_feature_enabled.api_v3 != ('v3.0' in versions): |
| 56 | print('Config option compute api_v3 should be change to: %s' % ( |
| 57 | not CONF.compute_feature_enabled.api_v3)) |
| 58 | |
| 59 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 60 | def get_extension_client(os, service): |
| 61 | extensions_client = { |
| 62 | 'nova': os.extensions_client, |
| 63 | 'nova_v3': os.extensions_v3_client, |
| 64 | 'cinder': os.volumes_extension_client, |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 65 | 'neutron': os.network_client, |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 66 | 'swift': os.account_client, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 67 | } |
| 68 | if service not in extensions_client: |
| 69 | print('No tempest extensions client for %s' % service) |
| 70 | exit(1) |
| 71 | return extensions_client[service] |
| 72 | |
| 73 | |
| 74 | def get_enabled_extensions(service): |
| 75 | extensions_options = { |
| 76 | 'nova': CONF.compute_feature_enabled.api_extensions, |
| 77 | 'nova_v3': CONF.compute_feature_enabled.api_v3_extensions, |
| 78 | 'cinder': CONF.volume_feature_enabled.api_extensions, |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 79 | 'neutron': CONF.network_feature_enabled.api_extensions, |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 80 | 'swift': CONF.object_storage_feature_enabled.discoverable_apis, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 81 | } |
| 82 | if service not in extensions_options: |
| 83 | print('No supported extensions list option for %s' % service) |
| 84 | exit(1) |
| 85 | return extensions_options[service] |
| 86 | |
| 87 | |
| 88 | def verify_extensions(os, service, results): |
| 89 | extensions_client = get_extension_client(os, service) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 90 | __, resp = extensions_client.list_extensions() |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 91 | if isinstance(resp, dict): |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 92 | # Neutron's extension 'name' field has is not a single word (it has |
| 93 | # spaces in the string) Since that can't be used for list option the |
| 94 | # api_extension option in the network-feature-enabled group uses alias |
| 95 | # instead of name. |
| 96 | if service == 'neutron': |
| 97 | extensions = map(lambda x: x['alias'], resp['extensions']) |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 98 | elif service == 'swift': |
| 99 | # Remove Swift general information from extensions list |
| 100 | resp.pop('swift') |
| 101 | extensions = resp.keys() |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 102 | else: |
| 103 | extensions = map(lambda x: x['name'], resp['extensions']) |
| 104 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 105 | else: |
| 106 | extensions = map(lambda x: x['name'], resp) |
| 107 | if not results.get(service): |
| 108 | results[service] = {} |
| 109 | extensions_opt = get_enabled_extensions(service) |
| 110 | if extensions_opt[0] == 'all': |
| 111 | results[service]['extensions'] = 'all' |
| 112 | return results |
| 113 | # Verify that all configured extensions are actually enabled |
| 114 | for extension in extensions_opt: |
| 115 | results[service][extension] = extension in extensions |
| 116 | # Verify that there aren't additional extensions enabled that aren't |
| 117 | # specified in the config list |
| 118 | for extension in extensions: |
| 119 | if extension not in extensions_opt: |
| 120 | results[service][extension] = False |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 121 | return results |
| 122 | |
| 123 | |
| 124 | def display_results(results): |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 125 | for service in results: |
| 126 | # If all extensions are specified as being enabled there is no way to |
| 127 | # verify this so we just assume this to be true |
| 128 | if results[service].get('extensions'): |
| 129 | continue |
| 130 | extension_list = get_enabled_extensions(service) |
| 131 | for extension in results[service]: |
| 132 | if not results[service][extension]: |
| 133 | if extension in extension_list: |
| 134 | print("%s extension: %s should not be included in the list" |
| 135 | " of enabled extensions" % (service, extension)) |
| 136 | else: |
| 137 | print("%s extension: %s should be included in the list of " |
| 138 | "enabled extensions" % (service, extension)) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 139 | |
| 140 | |
Matthew Treinish | d44fe03 | 2014-01-31 20:07:24 +0000 | [diff] [blame] | 141 | def check_service_availability(service): |
| 142 | if service == 'nova_v3': |
| 143 | service = 'nova' |
| 144 | return getattr(CONF.service_available, service) |
| 145 | |
| 146 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 147 | def main(argv): |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 148 | print('Running config verification...') |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 149 | os = clients.ComputeAdminManager(interface='json') |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 150 | results = {} |
Matthew Treinish | c0120ba | 2014-01-31 20:10:19 +0000 | [diff] [blame] | 151 | for service in ['nova', 'nova_v3', 'cinder', 'neutron', 'swift']: |
Matthew Treinish | d44fe03 | 2014-01-31 20:07:24 +0000 | [diff] [blame] | 152 | # TODO(mtreinish) make this a keystone endpoint check for available |
| 153 | # services |
| 154 | if not check_service_availability(service): |
| 155 | print("%s is not available" % service) |
| 156 | continue |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 157 | results = verify_extensions(os, service, results) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 158 | verify_glance_api_versions(os) |
Matthew Treinish | 4f30eb8 | 2014-01-07 21:04:49 +0000 | [diff] [blame] | 159 | verify_nova_api_versions(os) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 160 | display_results(results) |
| 161 | |
| 162 | |
| 163 | if __name__ == "__main__": |
| 164 | main(sys.argv) |