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 | |
| 17 | import sys |
| 18 | |
| 19 | from tempest import clients |
| 20 | from tempest import config |
| 21 | |
| 22 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 23 | CONF = config.CONF |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 24 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 25 | |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 26 | def verify_glance_api_versions(os): |
| 27 | # Check glance api versions |
| 28 | __, versions = os.image_client.get_versions() |
| 29 | if CONF.image_feature_enabled.api_v1 != ('v1.1' in versions or 'v1.0' in |
| 30 | versions): |
Sean Dague | 6b44788 | 2013-12-02 11:09:58 -0500 | [diff] [blame] | 31 | print('Config option image api_v1 should be change to: %s' % ( |
| 32 | not CONF.image_feature_enabled.api_v1)) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 33 | if CONF.image_feature_enabled.api_v2 != ('v2.0' in versions): |
Sean Dague | 6b44788 | 2013-12-02 11:09:58 -0500 | [diff] [blame] | 34 | print('Config option image api_v2 should be change to: %s' % ( |
| 35 | not CONF.image_feature_enabled.api_v2)) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 36 | |
| 37 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 38 | def get_extension_client(os, service): |
| 39 | extensions_client = { |
| 40 | 'nova': os.extensions_client, |
| 41 | 'nova_v3': os.extensions_v3_client, |
| 42 | 'cinder': os.volumes_extension_client, |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 43 | 'neutron': os.network_client, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 44 | } |
| 45 | if service not in extensions_client: |
| 46 | print('No tempest extensions client for %s' % service) |
| 47 | exit(1) |
| 48 | return extensions_client[service] |
| 49 | |
| 50 | |
| 51 | def get_enabled_extensions(service): |
| 52 | extensions_options = { |
| 53 | 'nova': CONF.compute_feature_enabled.api_extensions, |
| 54 | 'nova_v3': CONF.compute_feature_enabled.api_v3_extensions, |
| 55 | 'cinder': CONF.volume_feature_enabled.api_extensions, |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 56 | 'neutron': CONF.network_feature_enabled.api_extensions, |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 57 | } |
| 58 | if service not in extensions_options: |
| 59 | print('No supported extensions list option for %s' % service) |
| 60 | exit(1) |
| 61 | return extensions_options[service] |
| 62 | |
| 63 | |
| 64 | def verify_extensions(os, service, results): |
| 65 | extensions_client = get_extension_client(os, service) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 66 | __, resp = extensions_client.list_extensions() |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 67 | if isinstance(resp, dict): |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 68 | # Neutron's extension 'name' field has is not a single word (it has |
| 69 | # spaces in the string) Since that can't be used for list option the |
| 70 | # api_extension option in the network-feature-enabled group uses alias |
| 71 | # instead of name. |
| 72 | if service == 'neutron': |
| 73 | extensions = map(lambda x: x['alias'], resp['extensions']) |
| 74 | else: |
| 75 | extensions = map(lambda x: x['name'], resp['extensions']) |
| 76 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 77 | else: |
| 78 | extensions = map(lambda x: x['name'], resp) |
| 79 | if not results.get(service): |
| 80 | results[service] = {} |
| 81 | extensions_opt = get_enabled_extensions(service) |
| 82 | if extensions_opt[0] == 'all': |
| 83 | results[service]['extensions'] = 'all' |
| 84 | return results |
| 85 | # Verify that all configured extensions are actually enabled |
| 86 | for extension in extensions_opt: |
| 87 | results[service][extension] = extension in extensions |
| 88 | # Verify that there aren't additional extensions enabled that aren't |
| 89 | # specified in the config list |
| 90 | for extension in extensions: |
| 91 | if extension not in extensions_opt: |
| 92 | results[service][extension] = False |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 93 | return results |
| 94 | |
| 95 | |
| 96 | def display_results(results): |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 97 | for service in results: |
| 98 | # If all extensions are specified as being enabled there is no way to |
| 99 | # verify this so we just assume this to be true |
| 100 | if results[service].get('extensions'): |
| 101 | continue |
| 102 | extension_list = get_enabled_extensions(service) |
| 103 | for extension in results[service]: |
| 104 | if not results[service][extension]: |
| 105 | if extension in extension_list: |
| 106 | print("%s extension: %s should not be included in the list" |
| 107 | " of enabled extensions" % (service, extension)) |
| 108 | else: |
| 109 | print("%s extension: %s should be included in the list of " |
| 110 | "enabled extensions" % (service, extension)) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 111 | |
| 112 | |
| 113 | def main(argv): |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 114 | print('Running config verification...') |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 115 | os = clients.ComputeAdminManager(interface='json') |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 116 | results = {} |
Matthew Treinish | 8c6706d | 2014-01-07 19:28:18 +0000 | [diff] [blame] | 117 | for service in ['nova', 'nova_v3', 'cinder', 'neutron']: |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame] | 118 | results = verify_extensions(os, service, results) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 119 | verify_glance_api_versions(os) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 120 | display_results(results) |
| 121 | |
| 122 | |
| 123 | if __name__ == "__main__": |
| 124 | main(sys.argv) |