blob: 558360d0a66047a67d46e105d5cf423706f71491 [file] [log] [blame]
Matthew Treinish1f7b33d2013-10-21 18:07:02 +00001#!/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
18import sys
19
20from tempest import clients
21from tempest import config
22
23
Sean Dague86bd8422013-12-20 09:56:44 -050024CONF = config.CONF
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000025
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000026
Matthew Treinish99afd072013-10-22 18:03:06 +000027def 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 Dague6b447882013-12-02 11:09:58 -050032 print('Config option image api_v1 should be change to: %s' % (
33 not CONF.image_feature_enabled.api_v1))
Matthew Treinish99afd072013-10-22 18:03:06 +000034 if CONF.image_feature_enabled.api_v2 != ('v2.0' in versions):
Sean Dague6b447882013-12-02 11:09:58 -050035 print('Config option image api_v2 should be change to: %s' % (
36 not CONF.image_feature_enabled.api_v2))
Matthew Treinish99afd072013-10-22 18:03:06 +000037
38
Matthew Treinish8b006d22014-01-07 15:37:20 +000039def 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
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,
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
63def verify_extensions(os, service, results):
64 extensions_client = get_extension_client(os, service)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000065 __, resp = extensions_client.list_extensions()
Matthew Treinish8b006d22014-01-07 15:37:20 +000066 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 Treinish1f7b33d2013-10-21 18:07:02 +000084 return results
85
86
87def display_results(results):
Matthew Treinish8b006d22014-01-07 15:37:20 +000088 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 Treinish1f7b33d2013-10-21 18:07:02 +0000102
103
104def main(argv):
Matthew Treinish8b006d22014-01-07 15:37:20 +0000105 print('Running config verification...')
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000106 os = clients.ComputeAdminManager(interface='json')
Matthew Treinish8b006d22014-01-07 15:37:20 +0000107 results = {}
108 for service in ['nova', 'nova_v3', 'cinder']:
109 results = verify_extensions(os, service, results)
Matthew Treinish99afd072013-10-22 18:03:06 +0000110 verify_glance_api_versions(os)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000111 display_results(results)
112
113
114if __name__ == "__main__":
115 main(sys.argv)