blob: 0c21ceaf8cdc6c9393ca17f4adf6129f183f62ce [file] [log] [blame]
Matthew Treinish1f7b33d2013-10-21 18:07:02 +00001#!/usr/bin/env python
Matthew Treinish1f7b33d2013-10-21 18:07:02 +00002
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
17import sys
18
19from tempest import clients
20from tempest import config
21
22
Sean Dague86bd8422013-12-20 09:56:44 -050023CONF = config.CONF
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000024
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000025
Matthew Treinish99afd072013-10-22 18:03:06 +000026def 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 Dague6b447882013-12-02 11:09:58 -050031 print('Config option image api_v1 should be change to: %s' % (
32 not CONF.image_feature_enabled.api_v1))
Matthew Treinish99afd072013-10-22 18:03:06 +000033 if CONF.image_feature_enabled.api_v2 != ('v2.0' in versions):
Sean Dague6b447882013-12-02 11:09:58 -050034 print('Config option image api_v2 should be change to: %s' % (
35 not CONF.image_feature_enabled.api_v2))
Matthew Treinish99afd072013-10-22 18:03:06 +000036
37
Matthew Treinish8b006d22014-01-07 15:37:20 +000038def 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 Treinish8c6706d2014-01-07 19:28:18 +000043 'neutron': os.network_client,
Matthew Treinish8b006d22014-01-07 15:37:20 +000044 }
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
51def 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 Treinish8c6706d2014-01-07 19:28:18 +000056 'neutron': CONF.network_feature_enabled.api_extensions,
Matthew Treinish8b006d22014-01-07 15:37:20 +000057 }
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
64def verify_extensions(os, service, results):
65 extensions_client = get_extension_client(os, service)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000066 __, resp = extensions_client.list_extensions()
Matthew Treinish8b006d22014-01-07 15:37:20 +000067 if isinstance(resp, dict):
Matthew Treinish8c6706d2014-01-07 19:28:18 +000068 # 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 Treinish8b006d22014-01-07 15:37:20 +000077 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 Treinish1f7b33d2013-10-21 18:07:02 +000093 return results
94
95
96def display_results(results):
Matthew Treinish8b006d22014-01-07 15:37:20 +000097 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 Treinish1f7b33d2013-10-21 18:07:02 +0000111
112
113def main(argv):
Matthew Treinish8b006d22014-01-07 15:37:20 +0000114 print('Running config verification...')
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000115 os = clients.ComputeAdminManager(interface='json')
Matthew Treinish8b006d22014-01-07 15:37:20 +0000116 results = {}
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000117 for service in ['nova', 'nova_v3', 'cinder', 'neutron']:
Matthew Treinish8b006d22014-01-07 15:37:20 +0000118 results = verify_extensions(os, service, results)
Matthew Treinish99afd072013-10-22 18:03:06 +0000119 verify_glance_api_versions(os)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000120 display_results(results)
121
122
123if __name__ == "__main__":
124 main(sys.argv)