blob: dd8a4a0bd7f3579374435688a3bcc65113cf3045 [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,
Matthew Treinish8c6706d2014-01-07 19:28:18 +000044 'neutron': os.network_client,
Matthew Treinish8b006d22014-01-07 15:37:20 +000045 }
46 if service not in extensions_client:
47 print('No tempest extensions client for %s' % service)
48 exit(1)
49 return extensions_client[service]
50
51
52def get_enabled_extensions(service):
53 extensions_options = {
54 'nova': CONF.compute_feature_enabled.api_extensions,
55 'nova_v3': CONF.compute_feature_enabled.api_v3_extensions,
56 'cinder': CONF.volume_feature_enabled.api_extensions,
Matthew Treinish8c6706d2014-01-07 19:28:18 +000057 'neutron': CONF.network_feature_enabled.api_extensions,
Matthew Treinish8b006d22014-01-07 15:37:20 +000058 }
59 if service not in extensions_options:
60 print('No supported extensions list option for %s' % service)
61 exit(1)
62 return extensions_options[service]
63
64
65def verify_extensions(os, service, results):
66 extensions_client = get_extension_client(os, service)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000067 __, resp = extensions_client.list_extensions()
Matthew Treinish8b006d22014-01-07 15:37:20 +000068 if isinstance(resp, dict):
Matthew Treinish8c6706d2014-01-07 19:28:18 +000069 # Neutron's extension 'name' field has is not a single word (it has
70 # spaces in the string) Since that can't be used for list option the
71 # api_extension option in the network-feature-enabled group uses alias
72 # instead of name.
73 if service == 'neutron':
74 extensions = map(lambda x: x['alias'], resp['extensions'])
75 else:
76 extensions = map(lambda x: x['name'], resp['extensions'])
77
Matthew Treinish8b006d22014-01-07 15:37:20 +000078 else:
79 extensions = map(lambda x: x['name'], resp)
80 if not results.get(service):
81 results[service] = {}
82 extensions_opt = get_enabled_extensions(service)
83 if extensions_opt[0] == 'all':
84 results[service]['extensions'] = 'all'
85 return results
86 # Verify that all configured extensions are actually enabled
87 for extension in extensions_opt:
88 results[service][extension] = extension in extensions
89 # Verify that there aren't additional extensions enabled that aren't
90 # specified in the config list
91 for extension in extensions:
92 if extension not in extensions_opt:
93 results[service][extension] = False
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000094 return results
95
96
97def display_results(results):
Matthew Treinish8b006d22014-01-07 15:37:20 +000098 for service in results:
99 # If all extensions are specified as being enabled there is no way to
100 # verify this so we just assume this to be true
101 if results[service].get('extensions'):
102 continue
103 extension_list = get_enabled_extensions(service)
104 for extension in results[service]:
105 if not results[service][extension]:
106 if extension in extension_list:
107 print("%s extension: %s should not be included in the list"
108 " of enabled extensions" % (service, extension))
109 else:
110 print("%s extension: %s should be included in the list of "
111 "enabled extensions" % (service, extension))
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000112
113
114def main(argv):
Matthew Treinish8b006d22014-01-07 15:37:20 +0000115 print('Running config verification...')
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000116 os = clients.ComputeAdminManager(interface='json')
Matthew Treinish8b006d22014-01-07 15:37:20 +0000117 results = {}
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000118 for service in ['nova', 'nova_v3', 'cinder', 'neutron']:
Matthew Treinish8b006d22014-01-07 15:37:20 +0000119 results = verify_extensions(os, service, results)
Matthew Treinish99afd072013-10-22 18:03:06 +0000120 verify_glance_api_versions(os)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000121 display_results(results)
122
123
124if __name__ == "__main__":
125 main(sys.argv)