blob: aac45d3626a2953afb5b3ec68ea68c1867bfdeda [file] [log] [blame]
Rodrigo Duarte4666c642016-04-06 11:52:19 -03001# 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 Sousa79abcf42016-06-16 09:31:01 -030015import json
16
Davanum Srinivasdc948512017-01-04 12:37:45 -050017import six
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030018from six.moves import http_client
Rodrigo Duarte4666c642016-04-06 11:52:19 -030019from tempest import config
20from tempest.lib.common import rest_client
21
22
23CONF = config.CONF
24
25# We only use the identity catalog type
26SERVICE_TYPE = 'identity'
27
28
29class 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 Duarted96e29c2016-04-08 11:53:43 -030041
42
43class 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 Sousa79abcf42016-06-16 09:31:01 -030055 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 Duarted96e29c2016-04-08 11:53:43 -030058
59 def _get(self, entity_id=None, **kwargs):
60 url = self._build_path(entity_id)
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030061 resp, body = super(Federation, self).get(url, **kwargs)
62 self.expected_success(http_client.OK, resp.status)
Davanum Srinivasdc948512017-01-04 12:37:45 -050063 body = json.loads(body if six.PY2 else body.decode('utf-8'))
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030064 return rest_client.ResponseBody(resp, body)
Rodrigo Duarted96e29c2016-04-08 11:53:43 -030065
66 def _patch(self, entity_id, body, **kwargs):
67 url = self._build_path(entity_id)
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030068 resp, body = super(Federation, self).patch(url, body, **kwargs)
69 self.expected_success(http_client.OK, resp.status)
Davanum Srinivasdc948512017-01-04 12:37:45 -050070 body = json.loads(body if six.PY2 else body.decode('utf-8'))
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030071 return rest_client.ResponseBody(resp, body)
Rodrigo Duarted96e29c2016-04-08 11:53:43 -030072
73 def _put(self, entity_id, body, **kwargs):
74 url = self._build_path(entity_id)
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030075 resp, body = super(Federation, self).put(url, body, **kwargs)
76 self.expected_success(http_client.CREATED, resp.status)
Davanum Srinivasdc948512017-01-04 12:37:45 -050077 body = json.loads(body if six.PY2 else body.decode('utf-8'))
Rodrigo Duarte Sousa79abcf42016-06-16 09:31:01 -030078 return rest_client.ResponseBody(resp, body)