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