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