blob: 4be812cf30b2c0213a385fb3f2c355577c26590c [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):
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000043 # Check nova api versions - only get base URL without PATH
44 os.servers_client.skip_path = True
Matthew Treinisha5080812014-02-11 15:49:04 +000045 # The nova base endpoint url includes the version but to get the versions
46 # list the unversioned endpoint is needed
47 v2_endpoint = os.servers_client.base_url
48 v2_endpoint_parts = v2_endpoint.split('/')
49 endpoint = v2_endpoint_parts[0] + '//' + v2_endpoint_parts[2]
50 __, body = RAW_HTTP.request(endpoint, 'GET')
Matthew Treinish4f30eb82014-01-07 21:04:49 +000051 body = json.loads(body)
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000052 # Restore full base_url
53 os.servers_client.skip_path = False
Matthew Treinish4f30eb82014-01-07 21:04:49 +000054 versions = map(lambda x: x['id'], body['versions'])
55 if CONF.compute_feature_enabled.api_v3 != ('v3.0' in versions):
56 print('Config option compute api_v3 should be change to: %s' % (
57 not CONF.compute_feature_enabled.api_v3))
58
59
Matthew Treinish8b006d22014-01-07 15:37:20 +000060def get_extension_client(os, service):
61 extensions_client = {
62 'nova': os.extensions_client,
63 'nova_v3': os.extensions_v3_client,
64 'cinder': os.volumes_extension_client,
Matthew Treinish8c6706d2014-01-07 19:28:18 +000065 'neutron': os.network_client,
Matthew Treinish8b006d22014-01-07 15:37:20 +000066 }
67 if service not in extensions_client:
68 print('No tempest extensions client for %s' % service)
69 exit(1)
70 return extensions_client[service]
71
72
73def get_enabled_extensions(service):
74 extensions_options = {
75 'nova': CONF.compute_feature_enabled.api_extensions,
76 'nova_v3': CONF.compute_feature_enabled.api_v3_extensions,
77 'cinder': CONF.volume_feature_enabled.api_extensions,
Matthew Treinish8c6706d2014-01-07 19:28:18 +000078 'neutron': CONF.network_feature_enabled.api_extensions,
Matthew Treinish8b006d22014-01-07 15:37:20 +000079 }
80 if service not in extensions_options:
81 print('No supported extensions list option for %s' % service)
82 exit(1)
83 return extensions_options[service]
84
85
86def verify_extensions(os, service, results):
87 extensions_client = get_extension_client(os, service)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +000088 __, resp = extensions_client.list_extensions()
Matthew Treinish8b006d22014-01-07 15:37:20 +000089 if isinstance(resp, dict):
Matthew Treinish8c6706d2014-01-07 19:28:18 +000090 # Neutron's extension 'name' field has is not a single word (it has
91 # spaces in the string) Since that can't be used for list option the
92 # api_extension option in the network-feature-enabled group uses alias
93 # instead of name.
94 if service == 'neutron':
95 extensions = map(lambda x: x['alias'], resp['extensions'])
96 else:
97 extensions = map(lambda x: x['name'], resp['extensions'])
98
Matthew Treinish8b006d22014-01-07 15:37:20 +000099 else:
100 extensions = map(lambda x: x['name'], resp)
101 if not results.get(service):
102 results[service] = {}
103 extensions_opt = get_enabled_extensions(service)
104 if extensions_opt[0] == 'all':
105 results[service]['extensions'] = 'all'
106 return results
107 # Verify that all configured extensions are actually enabled
108 for extension in extensions_opt:
109 results[service][extension] = extension in extensions
110 # Verify that there aren't additional extensions enabled that aren't
111 # specified in the config list
112 for extension in extensions:
113 if extension not in extensions_opt:
114 results[service][extension] = False
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000115 return results
116
117
118def display_results(results):
Matthew Treinish8b006d22014-01-07 15:37:20 +0000119 for service in results:
120 # If all extensions are specified as being enabled there is no way to
121 # verify this so we just assume this to be true
122 if results[service].get('extensions'):
123 continue
124 extension_list = get_enabled_extensions(service)
125 for extension in results[service]:
126 if not results[service][extension]:
127 if extension in extension_list:
128 print("%s extension: %s should not be included in the list"
129 " of enabled extensions" % (service, extension))
130 else:
131 print("%s extension: %s should be included in the list of "
132 "enabled extensions" % (service, extension))
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000133
134
Matthew Treinishd44fe032014-01-31 20:07:24 +0000135def check_service_availability(service):
136 if service == 'nova_v3':
137 service = 'nova'
138 return getattr(CONF.service_available, service)
139
140
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000141def main(argv):
Matthew Treinish8b006d22014-01-07 15:37:20 +0000142 print('Running config verification...')
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000143 os = clients.ComputeAdminManager(interface='json')
Matthew Treinish8b006d22014-01-07 15:37:20 +0000144 results = {}
Matthew Treinish8c6706d2014-01-07 19:28:18 +0000145 for service in ['nova', 'nova_v3', 'cinder', 'neutron']:
Matthew Treinishd44fe032014-01-31 20:07:24 +0000146 # TODO(mtreinish) make this a keystone endpoint check for available
147 # services
148 if not check_service_availability(service):
149 print("%s is not available" % service)
150 continue
Matthew Treinish8b006d22014-01-07 15:37:20 +0000151 results = verify_extensions(os, service, results)
Matthew Treinish99afd072013-10-22 18:03:06 +0000152 verify_glance_api_versions(os)
Matthew Treinish4f30eb82014-01-07 21:04:49 +0000153 verify_nova_api_versions(os)
Matthew Treinish1f7b33d2013-10-21 18:07:02 +0000154 display_results(results)
155
156
157if __name__ == "__main__":
158 main(sys.argv)