Debian Codegraph @

octavia_tempest_plugin/services/load_balancer/v2/flavor_client.py

raw symbols SCIP
1 # Copyright 2019 Rackspace US Inc. All rights reserved.
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
16 from oslo_log import log as logging
17 from tempest.lib import exceptions
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 LOG = logging.getLogger(__name__)
23 Unset = base_client.Unset
24
25
26 class FlavorClient(base_client.BaseLBaaSClient):
27
28 root_tag = 'flavor'
29 list_root_tag = 'flavors'
30
31 @skip_if_not_implemented
32 def create_flavor(self, name, flavor_profile_id, description=Unset,
33 enabled=Unset, return_object_only=True):
34 """Create a flavor.
35
36 :param name: Human-readable name of the resource.
37 :param flavor_profile_id: The ID of the associated flavor profile.
38 :param description: A human-readable description for the resource.
39 :param enabled: If the resource is available for use.
40 The default is True.
41 :raises AssertionError: if the expected_code isn't a valid http success
42 response code
43 :raises BadRequest: If a 400 response code is received
44 :raises Conflict: If a 409 response code is received
45 :raises Forbidden: If a 403 response code is received
46 :raises Gone: If a 410 response code is received
47 :raises InvalidContentType: If a 415 response code is received
48 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
49 :raises InvalidHttpSuccessCode: if the read code isn't an expected
50 http success code
51 :raises NotFound: If a 404 response code is received
52 :raises NotImplemented: If a 501 response code is received
53 :raises OverLimit: If a 413 response code is received and over_limit is
54 not in the response body
55 :raises RateLimitExceeded: If a 413 response code is received and
56 over_limit is in the response body
57 :raises ServerFault: If a 500 response code is received
58 :raises Unauthorized: If a 401 response code is received
59 :raises UnexpectedContentType: If the content-type of the response
60 isn't an expect type
61 :raises UnexpectedResponseCode: If a response code above 400 is
62 received and it doesn't fall into any
63 of the handled checks
64 :raises UnprocessableEntity: If a 422 response code is received and
65 couldn't be parsed
66 :returns: A flavor object.
67 """
68 kwargs = {arg: value for arg, value in locals().items()
69 if arg != 'self' and value is not Unset}
70 return self._create_object(**kwargs)
71
72 @skip_if_not_implemented
73 def show_flavor(self, flavor_id, query_params=None,
74 return_object_only=True):
75 """Get the flavor details.
76
77 :param flavor_id: The flavor ID to query.
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 flavor object.
109 """
110 return self._show_object(obj_id=flavor_id,
111 query_params=query_params,
112 return_object_only=return_object_only)
113
114 @skip_if_not_implemented
115 def list_flavors(self, query_params=None, return_object_only=True):
116 """Get a list of flavor objects.
117
118 :param query_params: The optional query parameters to append to the
119 request. Ex. fields=id&fields=name
120 :param return_object_only: If True, the response returns the object
121 inside the root tag. False returns the full
122 response from the API.
123 :raises AssertionError: if the expected_code isn't a valid http success
124 response code
125 :raises BadRequest: If a 400 response code is received
126 :raises Conflict: If a 409 response code is received
127 :raises Forbidden: If a 403 response code is received
128 :raises Gone: If a 410 response code is received
129 :raises InvalidContentType: If a 415 response code is received
130 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
131 :raises InvalidHttpSuccessCode: if the read code isn't an expected
132 http success code
133 :raises NotFound: If a 404 response code is received
134 :raises NotImplemented: If a 501 response code is received
135 :raises OverLimit: If a 413 response code is received and over_limit is
136 not in the response body
137 :raises RateLimitExceeded: If a 413 response code is received and
138 over_limit is in the response body
139 :raises ServerFault: If a 500 response code is received
140 :raises Unauthorized: If a 401 response code is received
141 :raises UnexpectedContentType: If the content-type of the response
142 isn't an expect type
143 :raises UnexpectedResponseCode: If a response code above 400 is
144 received and it doesn't fall into any
145 of the handled checks
146 :raises UnprocessableEntity: If a 422 response code is received and
147 couldn't be parsed
148 :returns: A list of flavor objects.
149 """
150 return self._list_objects(query_params=query_params,
151 return_object_only=return_object_only)
152
153 @skip_if_not_implemented
154 def update_flavor(self, flavor_id, name=Unset, description=Unset,
155 enabled=Unset, return_object_only=True):
156 """Update a flavor.
157
158 :param flavor_id: The flavor ID to update.
159 :param name: Human-readable name of the resource.
160 :param description: A human-readable description for the resource.
161 :param enabled: If the resource is available for use.
162 :raises AssertionError: if the expected_code isn't a valid http success
163 response code
164 :raises BadRequest: If a 400 response code is received
165 :raises Conflict: If a 409 response code is received
166 :raises Forbidden: If a 403 response code is received
167 :raises Gone: If a 410 response code is received
168 :raises InvalidContentType: If a 415 response code is received
169 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
170 :raises InvalidHttpSuccessCode: if the read code isn't an expected
171 http success code
172 :raises NotFound: If a 404 response code is received
173 :raises NotImplemented: If a 501 response code is received
174 :raises OverLimit: If a 413 response code is received and over_limit is
175 not in the response body
176 :raises RateLimitExceeded: If a 413 response code is received and
177 over_limit is in the response body
178 :raises ServerFault: If a 500 response code is received
179 :raises Unauthorized: If a 401 response code is received
180 :raises UnexpectedContentType: If the content-type of the response
181 isn't an expect type
182 :raises UnexpectedResponseCode: If a response code above 400 is
183 received and it doesn't fall into any
184 of the handled checks
185 :raises UnprocessableEntity: If a 422 response code is received and
186 couldn't be parsed
187 :returns: A flavor object.
188 """
189 kwargs = {arg: value for arg, value in locals().items()
190 if arg != 'self' and value is not Unset}
191 kwargs['obj_id'] = kwargs.pop('flavor_id')
192 return self._update_object(**kwargs)
193
194 @skip_if_not_implemented
195 def delete_flavor(self, flavor_id, ignore_errors=False):
196 """Delete a flavor.
197
198 :param flavor_id: The flavor ID to delete.
199 :param ignore_errors: True if errors should be ignored.
200 :raises AssertionError: if the expected_code isn't a valid http success
201 response code
202 :raises BadRequest: If a 400 response code is received
203 :raises Conflict: If a 409 response code is received
204 :raises Forbidden: If a 403 response code is received
205 :raises Gone: If a 410 response code is received
206 :raises InvalidContentType: If a 415 response code is received
207 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
208 :raises InvalidHttpSuccessCode: if the read code isn't an expected
209 http success code
210 :raises NotFound: If a 404 response code is received
211 :raises NotImplemented: If a 501 response code is received
212 :raises OverLimit: If a 413 response code is received and over_limit is
213 not in the response body
214 :raises RateLimitExceeded: If a 413 response code is received and
215 over_limit is in the response body
216 :raises ServerFault: If a 500 response code is received
217 :raises Unauthorized: If a 401 response code is received
218 :raises UnexpectedContentType: If the content-type of the response
219 isn't an expect type
220 :raises UnexpectedResponseCode: If a response code above 400 is
221 received and it doesn't fall into any
222 of the handled checks
223 :raises UnprocessableEntity: If a 422 response code is received and
224 couldn't be parsed
225 :returns: None if ignore_errors is True, the response status code
226 if not.
227 """
228 return self._delete_obj(obj_id=flavor_id, ignore_errors=ignore_errors)
229
230 def cleanup_a_flavor(self, flavor_id):
231 """Delete a flavor for tempest cleanup.
232
233 We cannot use the cleanup_flavor method as flavors
234 do not have a provisioning_status.
235
236 :param flavor_id: The flavor ID to delete.
237 :raises AssertionError: if the expected_code isn't a valid http success
238 response code
239 :raises BadRequest: If a 400 response code is received
240 :raises Conflict: If a 409 response code is received
241 :raises Forbidden: If a 403 response code is received
242 :raises Gone: If a 410 response code is received
243 :raises InvalidContentType: If a 415 response code is received
244 :raises InvalidHTTPResponseBody: The response body wasn't valid JSON
245 :raises InvalidHttpSuccessCode: if the read code isn't an expected
246 http success code
247 :raises NotImplemented: If a 501 response code is received
248 :raises OverLimit: If a 413 response code is received and over_limit is
249 not in the response body
250 :raises RateLimitExceeded: If a 413 response code is received and
251 over_limit is in the response body
252 :raises ServerFault: If a 500 response code is received
253 :raises Unauthorized: If a 401 response code is received
254 :raises UnexpectedContentType: If the content-type of the response
255 isn't an expect type
256 :raises UnexpectedResponseCode: If a response code above 400 is
257 received and it doesn't fall into any
258 of the handled checks
259 :raises UnprocessableEntity: If a 422 response code is received and
260 couldn't be parsed
261 :returns: None if ignore_errors is True, the response status code
262 if not.
263 """
264 try:
265 self._delete_obj(obj_id=flavor_id)
266 except exceptions.NotFound:
267 # Already gone, cleanup complete
268 LOG.info("Flavor %s is already gone. "
269 "Cleanup considered complete.", flavor_id)