blob: 48c0e8d6c5d6d8814a502f183ce0cc9f9cdbf68f [file] [log] [blame]
Ken'ichi Ohmichi2b6012b2015-09-03 01:56:19 +00001# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from oslo_serialization import jsonutils as json
16from six.moves import urllib
17
18from tempest.api_schema.response.compute.v2_1 import versions as schema
19from tempest.common import service_client
20
21
22class VersionsClient(service_client.ServiceClient):
23
Ken'ichi Ohmichi5085f062015-09-04 02:12:42 +000024 def _get_base_version_url(self):
Ken'ichi Ohmichi2b6012b2015-09-03 01:56:19 +000025 # NOTE: The URL which is gotten from keystone's catalog contains
26 # API version and project-id like "v2/{project-id}", but we need
27 # to access the URL which doesn't contain them for getting API
28 # versions. For that, here should use raw_request() instead of
29 # get().
30 endpoint = self.base_url
31 url = urllib.parse.urlparse(endpoint)
Ken'ichi Ohmichi5085f062015-09-04 02:12:42 +000032 return '%s://%s/' % (url.scheme, url.netloc)
Ken'ichi Ohmichi2b6012b2015-09-03 01:56:19 +000033
Ken'ichi Ohmichi5085f062015-09-04 02:12:42 +000034 def list_versions(self):
35 version_url = self._get_base_version_url()
Ken'ichi Ohmichi2b6012b2015-09-03 01:56:19 +000036 resp, body = self.raw_request(version_url, 'GET')
37 body = json.loads(body)
38 self.validate_response(schema.list_versions, resp, body)
39 return service_client.ResponseBody(resp, body)
Ken'ichi Ohmichi5085f062015-09-04 02:12:42 +000040
41 def get_version_by_url(self, version_url):
42 """Get the version document by url.
43
44 This gets the version document for a url, useful in testing
45 the contents of things like /v2/ or /v2.1/ in Nova. That
46 controller needs authenticated access, so we have to get
47 ourselves a token before making the request.
48
49 """
50 # we need a token for this request
51 resp, body = self.raw_request(version_url, 'GET',
52 {'X-Auth-Token': self.token})
53 body = json.loads(body)
54 self.validate_response(schema.get_one_version, resp, body)
55 return service_client.ResponseBody(resp, body)