blob: 8fbb136fc70b5e2cd9247126cfc955a9750ac07f [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# 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
Ken'ichi Ohmichie2325f02017-03-02 13:45:05 -080015import time
16
Matthew Treinish9e26ca82016-02-23 11:43:20 -050017from oslo_serialization import jsonutils as json
Matthew Treinish9e26ca82016-02-23 11:43:20 -050018
19from tempest.lib.api_schema.response.compute.v2_1 import versions as schema
20from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090021from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050022
23
Ghanshyamee9af302016-02-25 06:12:43 +090024class VersionsClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050025
Matthew Treinish9e26ca82016-02-23 11:43:20 -050026 def list_versions(self):
27 version_url = self._get_base_version_url()
Ken'ichi Ohmichie2325f02017-03-02 13:45:05 -080028
29 start = time.time()
Matthew Treinish9e26ca82016-02-23 11:43:20 -050030 resp, body = self.raw_request(version_url, 'GET')
Ken'ichi Ohmichie2325f02017-03-02 13:45:05 -080031 end = time.time()
32 self._log_request('GET', version_url, resp, secs=(end - start),
33 resp_body=body)
34
Ken'ichi Ohmichi3b050492016-10-20 11:51:09 -070035 self._error_checker(resp, body)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050036 body = json.loads(body)
37 self.validate_response(schema.list_versions, resp, body)
38 return rest_client.ResponseBody(resp, body)
39
40 def get_version_by_url(self, version_url):
41 """Get the version document by url.
42
43 This gets the version document for a url, useful in testing
44 the contents of things like /v2/ or /v2.1/ in Nova. That
45 controller needs authenticated access, so we have to get
46 ourselves a token before making the request.
47
48 """
49 # we need a token for this request
50 resp, body = self.raw_request(version_url, 'GET',
51 {'X-Auth-Token': self.token})
Ken'ichi Ohmichi3b050492016-10-20 11:51:09 -070052 self._error_checker(resp, body)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050053 body = json.loads(body)
54 self.validate_response(schema.get_one_version, resp, body)
55 return rest_client.ResponseBody(resp, body)