Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 3 | |
| 4 | # Copyright 2013 IBM Corp. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | import sys |
| 19 | |
| 20 | from tempest import clients |
| 21 | from tempest import config |
| 22 | |
| 23 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 24 | CONF = config.CONF |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 25 | |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 26 | |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 27 | def verify_glance_api_versions(os): |
| 28 | # Check glance api versions |
| 29 | __, versions = os.image_client.get_versions() |
| 30 | if CONF.image_feature_enabled.api_v1 != ('v1.1' in versions or 'v1.0' in |
| 31 | versions): |
Sean Dague | 6b44788 | 2013-12-02 11:09:58 -0500 | [diff] [blame] | 32 | print('Config option image api_v1 should be change to: %s' % ( |
| 33 | not CONF.image_feature_enabled.api_v1)) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 34 | if CONF.image_feature_enabled.api_v2 != ('v2.0' in versions): |
Sean Dague | 6b44788 | 2013-12-02 11:09:58 -0500 | [diff] [blame] | 35 | print('Config option image api_v2 should be change to: %s' % ( |
| 36 | not CONF.image_feature_enabled.api_v2)) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 37 | |
| 38 | |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame^] | 39 | def get_extension_client(os, service): |
| 40 | extensions_client = { |
| 41 | 'nova': os.extensions_client, |
| 42 | 'nova_v3': os.extensions_v3_client, |
| 43 | 'cinder': os.volumes_extension_client, |
| 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, |
| 56 | } |
| 57 | if service not in extensions_options: |
| 58 | print('No supported extensions list option for %s' % service) |
| 59 | exit(1) |
| 60 | return extensions_options[service] |
| 61 | |
| 62 | |
| 63 | def verify_extensions(os, service, results): |
| 64 | extensions_client = get_extension_client(os, service) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 65 | __, resp = extensions_client.list_extensions() |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame^] | 66 | if isinstance(resp, dict): |
| 67 | extensions = map(lambda x: x['name'], resp['extensions']) |
| 68 | else: |
| 69 | extensions = map(lambda x: x['name'], resp) |
| 70 | if not results.get(service): |
| 71 | results[service] = {} |
| 72 | extensions_opt = get_enabled_extensions(service) |
| 73 | if extensions_opt[0] == 'all': |
| 74 | results[service]['extensions'] = 'all' |
| 75 | return results |
| 76 | # Verify that all configured extensions are actually enabled |
| 77 | for extension in extensions_opt: |
| 78 | results[service][extension] = extension in extensions |
| 79 | # Verify that there aren't additional extensions enabled that aren't |
| 80 | # specified in the config list |
| 81 | for extension in extensions: |
| 82 | if extension not in extensions_opt: |
| 83 | results[service][extension] = False |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 84 | return results |
| 85 | |
| 86 | |
| 87 | def display_results(results): |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame^] | 88 | for service in results: |
| 89 | # If all extensions are specified as being enabled there is no way to |
| 90 | # verify this so we just assume this to be true |
| 91 | if results[service].get('extensions'): |
| 92 | continue |
| 93 | extension_list = get_enabled_extensions(service) |
| 94 | for extension in results[service]: |
| 95 | if not results[service][extension]: |
| 96 | if extension in extension_list: |
| 97 | print("%s extension: %s should not be included in the list" |
| 98 | " of enabled extensions" % (service, extension)) |
| 99 | else: |
| 100 | print("%s extension: %s should be included in the list of " |
| 101 | "enabled extensions" % (service, extension)) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 102 | |
| 103 | |
| 104 | def main(argv): |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame^] | 105 | print('Running config verification...') |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 106 | os = clients.ComputeAdminManager(interface='json') |
Matthew Treinish | 8b006d2 | 2014-01-07 15:37:20 +0000 | [diff] [blame^] | 107 | results = {} |
| 108 | for service in ['nova', 'nova_v3', 'cinder']: |
| 109 | results = verify_extensions(os, service, results) |
Matthew Treinish | 99afd07 | 2013-10-22 18:03:06 +0000 | [diff] [blame] | 110 | verify_glance_api_versions(os) |
Matthew Treinish | 1f7b33d | 2013-10-21 18:07:02 +0000 | [diff] [blame] | 111 | display_results(results) |
| 112 | |
| 113 | |
| 114 | if __name__ == "__main__": |
| 115 | main(sys.argv) |