Rodrigo Duarte | 4666c64 | 2016-04-06 11:52:19 -0300 | [diff] [blame] | 1 | # Copyright 2016 Red Hat, Inc. |
| 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 | |
Rodrigo Duarte Sousa | 79abcf4 | 2016-06-16 09:31:01 -0300 | [diff] [blame^] | 15 | import json |
| 16 | |
| 17 | from six.moves import http_client |
Rodrigo Duarte | 4666c64 | 2016-04-06 11:52:19 -0300 | [diff] [blame] | 18 | from tempest import config |
| 19 | from tempest.lib.common import rest_client |
| 20 | |
| 21 | |
| 22 | CONF = config.CONF |
| 23 | |
| 24 | # We only use the identity catalog type |
| 25 | SERVICE_TYPE = 'identity' |
| 26 | |
| 27 | |
| 28 | class Identity(rest_client.RestClient): |
| 29 | """Tempest REST client for keystone.""" |
| 30 | |
| 31 | # Used by the superclass to build the correct URL paths |
| 32 | api_version = 'v3' |
| 33 | |
| 34 | def __init__(self, auth_provider): |
| 35 | super(Identity, self).__init__( |
| 36 | auth_provider, |
| 37 | SERVICE_TYPE, |
| 38 | CONF.identity.region, |
| 39 | endpoint_type='adminURL') |
Rodrigo Duarte | d96e29c | 2016-04-08 11:53:43 -0300 | [diff] [blame] | 40 | |
| 41 | |
| 42 | class Federation(Identity): |
| 43 | """Tempest REST client for keystone's Federated Identity API.""" |
| 44 | |
| 45 | subpath_prefix = 'OS-FEDERATION' |
| 46 | subpath_suffix = None |
| 47 | |
| 48 | def _build_path(self, entity_id=None): |
| 49 | subpath = '%s/%s' % (self.subpath_prefix, self.subpath_suffix) |
| 50 | return '%s/%s' % (subpath, entity_id) if entity_id else subpath |
| 51 | |
| 52 | def _delete(self, entity_id, **kwargs): |
| 53 | url = self._build_path(entity_id) |
Rodrigo Duarte Sousa | 79abcf4 | 2016-06-16 09:31:01 -0300 | [diff] [blame^] | 54 | resp, body = super(Federation, self).delete(url, **kwargs) |
| 55 | self.expected_success(http_client.NO_CONTENT, resp.status) |
| 56 | return rest_client.ResponseBody(resp, body) |
Rodrigo Duarte | d96e29c | 2016-04-08 11:53:43 -0300 | [diff] [blame] | 57 | |
| 58 | def _get(self, entity_id=None, **kwargs): |
| 59 | url = self._build_path(entity_id) |
Rodrigo Duarte Sousa | 79abcf4 | 2016-06-16 09:31:01 -0300 | [diff] [blame^] | 60 | resp, body = super(Federation, self).get(url, **kwargs) |
| 61 | self.expected_success(http_client.OK, resp.status) |
| 62 | body = json.loads(body) |
| 63 | return rest_client.ResponseBody(resp, body) |
Rodrigo Duarte | d96e29c | 2016-04-08 11:53:43 -0300 | [diff] [blame] | 64 | |
| 65 | def _patch(self, entity_id, body, **kwargs): |
| 66 | url = self._build_path(entity_id) |
Rodrigo Duarte Sousa | 79abcf4 | 2016-06-16 09:31:01 -0300 | [diff] [blame^] | 67 | resp, body = super(Federation, self).patch(url, body, **kwargs) |
| 68 | self.expected_success(http_client.OK, resp.status) |
| 69 | body = json.loads(body) |
| 70 | return rest_client.ResponseBody(resp, body) |
Rodrigo Duarte | d96e29c | 2016-04-08 11:53:43 -0300 | [diff] [blame] | 71 | |
| 72 | def _put(self, entity_id, body, **kwargs): |
| 73 | url = self._build_path(entity_id) |
Rodrigo Duarte Sousa | 79abcf4 | 2016-06-16 09:31:01 -0300 | [diff] [blame^] | 74 | resp, body = super(Federation, self).put(url, body, **kwargs) |
| 75 | self.expected_success(http_client.CREATED, resp.status) |
| 76 | body = json.loads(body) |
| 77 | return rest_client.ResponseBody(resp, body) |