|
0 |
# Copyright 2020 SUSE LLC
|
|
1 |
#
|
|
2 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
3 |
# not use this file except in compliance with the License. You may obtain
|
|
4 |
# a copy of the License at
|
|
5 |
#
|
|
6 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7 |
#
|
|
8 |
# Unless required by applicable law or agreed to in writing, software
|
|
9 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
10 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
11 |
# License for the specific language governing permissions and limitations
|
|
12 |
# under the License.
|
|
13 |
|
|
14 |
import json
|
|
15 |
|
|
16 |
import http.client
|
|
17 |
from tempest.lib.common import rest_client
|
|
18 |
|
|
19 |
from keystone_tempest_plugin.services.identity import clients
|
|
20 |
|
|
21 |
|
|
22 |
class RegisteredLimitsClient(clients.Identity):
|
|
23 |
|
|
24 |
subpath_prefix = 'registered_limits'
|
|
25 |
collection_url = subpath_prefix
|
|
26 |
entity_url = subpath_prefix + '/%s'
|
|
27 |
|
|
28 |
def create_registered_limits(self, payload):
|
|
29 |
"""Create a list of registered limits.
|
|
30 |
|
|
31 |
:param body: A list of registered limits objects.
|
|
32 |
"""
|
|
33 |
post_body = json.dumps({'registered_limits': payload})
|
|
34 |
resp, body = super(RegisteredLimitsClient, self).post(
|
|
35 |
self.collection_url, post_body)
|
|
36 |
self.expected_success(http.client.CREATED, resp.status)
|
|
37 |
body = json.loads(body.decode('utf-8'))
|
|
38 |
return rest_client.ResponseBody(resp, body)
|
|
39 |
|
|
40 |
def list_registered_limits(self, **kwargs):
|
|
41 |
"""List registered limits.
|
|
42 |
|
|
43 |
:param kwargs: Filter by service_id, region_id, or resource_name
|
|
44 |
"""
|
|
45 |
resp, body = super(RegisteredLimitsClient, self).get(
|
|
46 |
self.collection_url, **kwargs)
|
|
47 |
self.expected_success(http.client.OK, resp.status)
|
|
48 |
body = json.loads(body.decode('utf-8'))
|
|
49 |
return rest_client.ResponseBody(resp, body)
|
|
50 |
|
|
51 |
def update_registered_limit(self, registered_limit_id, registered_limit):
|
|
52 |
"""Update a registered limit.
|
|
53 |
|
|
54 |
:param registered_limit_id: ID of registered limit to update
|
|
55 |
:param registered_limit: new registered limit object
|
|
56 |
"""
|
|
57 |
patch_body = json.dumps({'registered_limit': registered_limit})
|
|
58 |
resp, body = super(RegisteredLimitsClient, self).patch(
|
|
59 |
self.entity_url % registered_limit_id, patch_body)
|
|
60 |
self.expected_success(http.client.OK, resp.status)
|
|
61 |
body = json.loads(body.decode('utf-8'))
|
|
62 |
return rest_client.ResponseBody(resp, body)
|
|
63 |
|
|
64 |
def show_registered_limit(self, registered_limit_id):
|
|
65 |
"""Get a registered limit.
|
|
66 |
|
|
67 |
:param registered_limit_id: ID of registered limit to show
|
|
68 |
"""
|
|
69 |
resp, body = super(RegisteredLimitsClient, self).get(
|
|
70 |
self.entity_url % registered_limit_id)
|
|
71 |
self.expected_success(http.client.OK, resp.status)
|
|
72 |
body = json.loads(body.decode('utf-8'))
|
|
73 |
return rest_client.ResponseBody(resp, body)
|
|
74 |
|
|
75 |
def delete_registered_limit(self, registered_limit_id):
|
|
76 |
"""Delete a registered limit.
|
|
77 |
|
|
78 |
:param registered_limit_id: ID of registered limit to delete.
|
|
79 |
"""
|
|
80 |
resp, body = super(RegisteredLimitsClient, self).delete(
|
|
81 |
self.entity_url % registered_limit_id)
|
|
82 |
self.expected_success(http.client.NO_CONTENT, resp.status)
|
|
83 |
return rest_client.ResponseBody(resp, body)
|
|
84 |
|
|
85 |
|
|
86 |
class LimitsClient(clients.Identity):
|
|
87 |
|
|
88 |
subpath_prefix = 'limits'
|
|
89 |
collection_url = subpath_prefix
|
|
90 |
entity_url = subpath_prefix + '/%s'
|
|
91 |
|
|
92 |
def limits_model(self):
|
|
93 |
"""Get limits model from server."""
|
|
94 |
url = self.entity_url % 'model'
|
|
95 |
resp, body = super(LimitsClient, self).get(url)
|
|
96 |
self.expected_success(http.client.OK, resp.status)
|
|
97 |
body = json.loads(body.decode('utf-8'))
|
|
98 |
return rest_client.ResponseBody(resp, body)
|
|
99 |
|
|
100 |
def create_limits(self, payload):
|
|
101 |
"""Create a list of project limits.
|
|
102 |
|
|
103 |
:param body: A list of project limits objects.
|
|
104 |
"""
|
|
105 |
post_body = json.dumps({'limits': payload})
|
|
106 |
resp, body = super(LimitsClient, self).post(
|
|
107 |
self.collection_url, post_body)
|
|
108 |
self.expected_success(http.client.CREATED, resp.status)
|
|
109 |
body = json.loads(body.decode('utf-8'))
|
|
110 |
return rest_client.ResponseBody(resp, body)
|
|
111 |
|
|
112 |
def list_limits(self, **kwargs):
|
|
113 |
"""List project limits.
|
|
114 |
|
|
115 |
:param kwargs: Filter by service_id, region_id, resource_name,
|
|
116 |
or project/domain ID
|
|
117 |
"""
|
|
118 |
resp, body = super(LimitsClient, self).get(
|
|
119 |
self.collection_url, **kwargs)
|
|
120 |
self.expected_success(http.client.OK, resp.status)
|
|
121 |
body = json.loads(body.decode('utf-8'))
|
|
122 |
return rest_client.ResponseBody(resp, body)
|
|
123 |
|
|
124 |
def update_limit(self, limit_id, limit):
|
|
125 |
"""Update a project limit.
|
|
126 |
|
|
127 |
:param limit_id: ID of project limit to update
|
|
128 |
:param limit: new project limit object
|
|
129 |
"""
|
|
130 |
patch_body = json.dumps({'limit': limit})
|
|
131 |
resp, body = super(LimitsClient, self).patch(
|
|
132 |
self.entity_url % limit_id, patch_body)
|
|
133 |
self.expected_success(http.client.OK, resp.status)
|
|
134 |
body = json.loads(body.decode('utf-8'))
|
|
135 |
return rest_client.ResponseBody(resp, body)
|
|
136 |
|
|
137 |
def show_limit(self, limit_id):
|
|
138 |
"""Get a project limit.
|
|
139 |
|
|
140 |
:param limit_id: ID of project limit to show
|
|
141 |
"""
|
|
142 |
resp, body = super(LimitsClient, self).get(self.entity_url % limit_id)
|
|
143 |
self.expected_success(http.client.OK, resp.status)
|
|
144 |
body = json.loads(body.decode('utf-8'))
|
|
145 |
return rest_client.ResponseBody(resp, body)
|
|
146 |
|
|
147 |
def delete_limit(self, limit_id):
|
|
148 |
"""Delete a project limit.
|
|
149 |
|
|
150 |
:param limit_id: ID of project limit to delete.
|
|
151 |
"""
|
|
152 |
resp, body = super(LimitsClient, self).delete(
|
|
153 |
self.entity_url % limit_id)
|
|
154 |
self.expected_success(http.client.NO_CONTENT, resp.status)
|
|
155 |
return rest_client.ResponseBody(resp, body)
|