blob: b3934026def40c8f0f58201913a50ee94dc5bead [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
Matthew Treinish4f30eb82014-01-07 21:04:49 +000017import json
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000018import sys
19
Matthew Treinish4f30eb82014-01-07 21:04:49 +000020import httplib2
21
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000022from tempest import clients
23from tempest import config
24
25
Sean Dague86bd8422013-12-20 09:56:44 -050026CONF = config.CONF
Matthew Treinish4f30eb82014-01-07 21:04:49 +000027RAW_HTTP = httplib2.Http()
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000028
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000029
Matthew Treinish99afd072013-10-22 18:03:06 +000030def verify_glance_api_versions(os):
31 # Check glance api versions
32 __, versions = os.image_client.get_versions()
33 if CONF.image_feature_enabled.api_v1 != ('v1.1' in versions or 'v1.0' in
34 versions):
Sean Dague6b447882013-12-02 11:09:58 -050035 print('Config option image api_v1 should be change to: %s' % (
36 not CONF.image_feature_enabled.api_v1))
Matthew Treinish99afd072013-10-22 18:03:06 +000037 if CONF.image_feature_enabled.api_v2 != ('v2.0' in versions):
Sean Dague6b447882013-12-02 11:09:58 -050038 print('Config option image api_v2 should be change to: %s' % (
39 not CONF.image_feature_enabled.api_v2))
Matthew Treinish99afd072013-10-22 18:03:06 +000040
41
Matthew Treinish4f30eb82014-01-07 21:04:49 +000042def verify_nova_api_versions(os):
43 # Check nova api versions
44 os.servers_client._set_auth()
45 v2_endpoint = os.servers_client.base_url
46 endpoint = 'http://' + v2_endpoint.split('/')[2]
47 __, body = RAW_HTTP.request(endpoint, 'GET')
48 body = json.loads(body)
49 versions = map(lambda x: x['id'], body['versions'])
50 if CONF.compute_feature_enabled.api_v3 != ('v3.0' in versions):
51 print('Config option compute api_v3 should be change to: %s' % (
52 not CONF.compute_feature_enabled.api_v3))
53
54
Matthew Treinish8b006d22014-01-07 15:37:20 +000055def get_extension_client(os, service):
56 extensions_client = {
57 'nova': os.extensions_client,
58 'nova_v3': os.extensions_v3_client,
59 'cinder': os.volumes_extension_client,
Matthew Treinish8c6706d2014-01-07 19:28:18 +000060 'neutron': os.network_client,
Matthew Treinish8b006d22014-01-07 15:37:20 +000061 }
62 if service not in extensions_client:
63 print('No tempest extensions client for %s' % service)
64 exit(1)
65 return extensions_client[service]
66
67
68def get_enabled_extensions(service):
69 extensions_options = {
70 'nova': CONF.compute_feature_enabled.api_extensions,
71 'nova_v3': CONF.compute_feature_enabled.api_v3_extensions,
72 'cinder': CONF.volume_feature_enabled.api_extensions,
Matthew Treinish8c6706d2014-01-07 19:28:18 +000073 'neutron': CONF.network_feature_enabled.api_extensions,
Matthew Treinish8b006d22014-01-07 15:37:20 +000074 }
75 if service not in extensions_options:
76 print('No supported extensions list option for %s' % service)
77 exit(1)
78 return extensions_options[service]
79
80
81def verify_extensions(os, service, results):
82 extensions_client = get_extension_client(os, service)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000083 __, resp = extensions_client.list_extensions()
Matthew Treinish8b006d22014-01-07 15:37:20 +000084 if isinstance(resp, dict):
Matthew Treinish8c6706d2014-01-07 19:28:18 +000085 # Neutron's extension 'name' field has is not a single word (it has
86 # spaces in the string) Since that can't be used for list option the
87 # api_extension option in the network-feature-enabled group uses alias
88 # instead of name.
89 if service == 'neutron':
90 extensions = map(lambda x: x['alias'], resp['extensions'])
91 else:
92 extensions = map(lambda x: x['name'], resp['extensions'])
93
Matthew Treinish8b006d22014-01-07 15:37:20 +000094 else:
95 extensions = map(lambda x: x['name'], resp)
96 if not results.get(service):
97 results[service] = {}
98 extensions_opt = get_enabled_extensions(service)
99 if extensions_opt[0] == 'all':
100 results[service]['extensions'] = 'all'
101 return results
102 # Verify that all configured extensions are actually enabled
103 for extension in extensions_opt:
104 results[service][extension] = extension in extensions
105 # Verify that there aren't additional extensions enabled that aren't
106 # specified in the config list
107 for extension in extensions:
108 if extension not in extensions_opt:
109 results[service][extension] = False
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000110 return results
111
112
113def display_results(results):
Matthew Treinish8b006d22014-01-07 15:37:20 +0000114 for service in results:
115 # If all extensions are specified as being enabled there is no way to
116 # verify this so we just assume this to be true
117 if results[service].get('extensions'):
118 continue
119 extension_list = get_enabled_extensions(service)
120 for extension in results[service]:
121 if not results[service][extension]:
122 if extension in extension_list:
123 print("%s extension: %s should not be included in the list"
124 " of enabled extensions" % (service, extension))
125 else:
126 print("%s extension: %s should be included in the list of "
127 "enabled extensions" % (service, extension))
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000128
129
130def main(argv):
Matthew Treinish8b006d22014-01-07 15:37:20 +0000131 print('Running config verification...')
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000132 os = clients.ComputeAdminManager(interface='json')
Matthew Treinish8b006d22014-01-07 15:37:20 +0000133 results = {}
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000134 for service in ['nova', 'nova_v3', 'cinder', 'neutron']:
Matthew Treinish8b006d22014-01-07 15:37:20 +0000135 results = verify_extensions(os, service, results)
Matthew Treinish99afd072013-10-22 18:03:06 +0000136 verify_glance_api_versions(os)
Matthew Treinish4f30eb82014-01-07 21:04:49 +0000137 verify_nova_api_versions(os)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000138 display_results(results)
139
140
141if __name__ == "__main__":
142 main(sys.argv)