Debian Codegraph @

octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py

raw symbols SCIP
1 # Copyright 2018 GoDaddy
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
15 from oslo_serialization import jsonutils
16
17 from tempest import config
18
19 from octavia_tempest_plugin.common.decorators import skip_if_not_implemented
20 from octavia_tempest_plugin.services.load_balancer.v2 import base_client
21
22 CONF = config.CONF
23
24
25 class AmphoraClient(base_client.BaseLBaaSClient):
26
27 root_tag = 'amphora'
28 list_root_tag = 'amphorae'
29 stats_root_tag = 'amphora_stats'
30 base_uri = '/v2.0/octavia/{object}'
31
32 @skip_if_not_implemented
33 def show_amphora(self, amphora_id, query_params=None,
34 return_object_only=True):
35 """Get amphora details.
36
37 :param amphora_id: The amphora ID to query.
38 :param query_params: The optional query parameters to append to the
39 request. Ex. fields=id&fields=name
40 :param return_object_only: If True, the response returns the object
41 inside the root tag. False returns the full
42 response from the API.
43 :raises AssertionError: if the expected_code isn't a valid http success
44 response code
45 :raises BadRequest: If a 400 response code is received
46 :raises Conflict: If a 409 response code is received
47 :raises Forbidden: If a 403 response code is received
48 :raises Gone: If a 410 response code is received
49 :raises InvalidContentType: If a 415 response code is received
50 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
51 :raises InvalidHttpSuccessCode: if the read code isn't an expected
52 http success code
53 :raises NotFound: If a 404 response code is received
54 :raises NotImplemented: If a 501 response code is received
55 :raises OverLimit: If a 413 response code is received and over_limit is
56 not in the response body
57 :raises RateLimitExceeded: If a 413 response code is received and
58 over_limit is in the response body
59 :raises ServerFault: If a 500 response code is received
60 :raises Unauthorized: If a 401 response code is received
61 :raises UnexpectedContentType: If the content-type of the response
62 isn't an expect type
63 :raises UnexpectedResponseCode: If a response code above 400 is
64 received and it doesn't fall into any
65 of the handled checks
66 :raises UnprocessableEntity: If a 422 response code is received and
67 couldn't be parsed
68 :returns: An amphora object.
69 """
70 return self._show_object(obj_id=amphora_id,
71 query_params=query_params,
72 return_object_only=return_object_only)
73
74 @skip_if_not_implemented
75 def list_amphorae(self, query_params=None, return_object_only=True):
76 """Get a list of amphora objects.
77
78 :param query_params: The optional query parameters to append to the
79 request. Ex. fields=id&fields=name
80 :param return_object_only: If True, the response returns the object
81 inside the root tag. False returns the full
82 response from the API.
83 :raises AssertionError: if the expected_code isn't a valid http success
84 response code
85 :raises BadRequest: If a 400 response code is received
86 :raises Conflict: If a 409 response code is received
87 :raises Forbidden: If a 403 response code is received
88 :raises Gone: If a 410 response code is received
89 :raises InvalidContentType: If a 415 response code is received
90 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
91 :raises InvalidHttpSuccessCode: if the read code isn't an expected
92 http success code
93 :raises NotFound: If a 404 response code is received
94 :raises NotImplemented: If a 501 response code is received
95 :raises OverLimit: If a 413 response code is received and over_limit is
96 not in the response body
97 :raises RateLimitExceeded: If a 413 response code is received and
98 over_limit is in the response body
99 :raises ServerFault: If a 500 response code is received
100 :raises Unauthorized: If a 401 response code is received
101 :raises UnexpectedContentType: If the content-type of the response
102 isn't an expect type
103 :raises UnexpectedResponseCode: If a response code above 400 is
104 received and it doesn't fall into any
105 of the handled checks
106 :raises UnprocessableEntity: If a 422 response code is received and
107 couldn't be parsed
108 :returns: A list of amphora objects.
109 """
110 return self._list_objects(query_params=query_params,
111 return_object_only=return_object_only)
112
113 @skip_if_not_implemented
114 def get_amphora_stats(self, amphora_id, query_params=None,
115 return_object_only=True):
116 """Get amphora statistics.
117
118 :param amphora_id: The amphora ID to query.
119 :param query_params: The optional query parameters to append to the
120 request. Ex. fields=id&fields=name
121 :param return_object_only: If True, the response returns the object
122 inside the root tag. False returns the full
123 response from the API.
124 :raises AssertionError: if the expected_code isn't a valid http success
125 response code
126 :raises BadRequest: If a 400 response code is received
127 :raises Conflict: If a 409 response code is received
128 :raises Forbidden: If a 403 response code is received
129 :raises Gone: If a 410 response code is received
130 :raises InvalidContentType: If a 415 response code is received
131 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
132 :raises InvalidHttpSuccessCode: if the read code isn't an expected
133 http success code
134 :raises NotFound: If a 404 response code is received
135 :raises NotImplemented: If a 501 response code is received
136 :raises OverLimit: If a 413 response code is received and over_limit is
137 not in the response body
138 :raises RateLimitExceeded: If a 413 response code is received and
139 over_limit is in the response body
140 :raises ServerFault: If a 500 response code is received
141 :raises Unauthorized: If a 401 response code is received
142 :raises UnexpectedContentType: If the content-type of the response
143 isn't an expect type
144 :raises UnexpectedResponseCode: If a response code above 400 is
145 received and it doesn't fall into any
146 of the handled checks
147 :raises UnprocessableEntity: If a 422 response code is received and
148 couldn't be parsed
149 :returns: An amphora statistics object.
150 """
151 uri = self.base_uri.format(object=self.list_root_tag)
152 if query_params:
153 request_uri = '{0}/{1}/stats?{2}'.format(uri, amphora_id,
154 query_params)
155 else:
156 request_uri = '{0}/{1}/stats'.format(uri, amphora_id)
157
158 response, body = self.get(request_uri)
159 self.expected_success(200, response.status)
160 if return_object_only:
161 return jsonutils.loads(body.decode('utf-8'))[self.stats_root_tag]
162 else:
163 return jsonutils.loads(body.decode('utf-8'))
164
165 @skip_if_not_implemented
166 def update_amphora_config(self, amphora_id):
167 """Update the amphora agent configuration.
168
169 :param amphora_id: The ID of the amphora to update.
170 :raises AssertionError: if the expected_code isn't a valid http success
171 response code
172 :raises BadRequest: If a 400 response code is received
173 :raises Conflict: If a 409 response code is received
174 :raises Forbidden: If a 403 response code is received
175 :raises Gone: If a 410 response code is received
176 :raises InvalidContentType: If a 415 response code is received
177 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
178 :raises InvalidHttpSuccessCode: if the read code isn't an expected
179 http success code
180 :raises NotFound: If a 404 response code is received
181 :raises NotImplemented: If a 501 response code is received
182 :raises OverLimit: If a 413 response code is received and over_limit is
183 not in the response body
184 :raises RateLimitExceeded: If a 413 response code is received and
185 over_limit is in the response body
186 :raises ServerFault: If a 500 response code is received
187 :raises Unauthorized: If a 401 response code is received
188 :raises UnexpectedContentType: If the content-type of the response
189 isn't an expect type
190 :raises UnexpectedResponseCode: If a response code above 400 is
191 received and it doesn't fall into any
192 of the handled checks
193 :raises UnprocessableEntity: If a 422 response code is received and
194 couldn't be parsed
195 :returns: None
196 """
197 uri = '{0}/{1}/config'.format(self.uri, amphora_id)
198 response, body = self.put(uri, '')
199 self.expected_success(202, response.status)
200
201 @skip_if_not_implemented
202 def amphora_failover(self, amphora_id):
203 """Failover an amphora.
204
205 :param amphora_id: The ID of the amphora to failover.
206 :raises AssertionError: if the expected_code isn't a valid http success
207 response code
208 :raises BadRequest: If a 400 response code is received
209 :raises Conflict: If a 409 response code is received
210 :raises Forbidden: If a 403 response code is received
211 :raises Gone: If a 410 response code is received
212 :raises InvalidContentType: If a 415 response code is received
213 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
214 :raises InvalidHttpSuccessCode: if the read code isn't an expected
215 http success code
216 :raises NotFound: If a 404 response code is received
217 :raises NotImplemented: If a 501 response code is received
218 :raises OverLimit: If a 413 response code is received and over_limit is
219 not in the response body
220 :raises RateLimitExceeded: If a 413 response code is received and
221 over_limit is in the response body
222 :raises ServerFault: If a 500 response code is received
223 :raises Unauthorized: If a 401 response code is received
224 :raises UnexpectedContentType: If the content-type of the response
225 isn't an expect type
226 :raises UnexpectedResponseCode: If a response code above 400 is
227 received and it doesn't fall into any
228 of the handled checks
229 :raises UnprocessableEntity: If a 422 response code is received and
230 couldn't be parsed
231 :returns: None
232 """
233 uri = '{0}/{1}/failover'.format(self.uri, amphora_id)
234 response, body = self.put(uri, '')
235 self.expected_success(202, response.status)