| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 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 AvailabilityZoneClient(base_client.BaseLBaaSClient): |
| 27 |
|
| 28 |
root_tag = 'availability_zone' |
| 29 |
list_root_tag = 'availability_zones' |
| 30 |
|
| 31 |
resource_path = 'availabilityzones' |
| 32 |
|
| 33 |
def __init__(self, *args, **kwargs): |
| 34 |
super(AvailabilityZoneClient, self).__init__(*args, **kwargs) |
| 35 |
self.uri = self.base_uri.format(object=self.resource_path) |
| 36 |
|
| 37 |
@skip_if_not_implemented |
| 38 |
def create_availability_zone(self, name, availability_zone_profile_id, |
| 39 |
description=Unset, enabled=Unset, |
| 40 |
return_object_only=True): |
| 41 |
"""Create an availability zone. |
| 42 |
|
| 43 |
:param name: Human-readable name of the resource. |
| 44 |
:param availability_zone_profile_id: The ID of the associated |
| 45 |
availability zone profile. |
| 46 |
:param description: A human-readable description for the resource. |
| 47 |
:param enabled: If the resource is available for use. |
| 48 |
The default is True. |
| 49 |
:raises AssertionError: if the expected_code isn't a valid http success |
| 50 |
response code |
| 51 |
:raises BadRequest: If a 400 response code is received |
| 52 |
:raises Conflict: If a 409 response code is received |
| 53 |
:raises Forbidden: If a 403 response code is received |
| 54 |
:raises Gone: If a 410 response code is received |
| 55 |
:raises InvalidContentType: If a 415 response code is received |
| 56 |
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON |
| 57 |
:raises InvalidHttpSuccessCode: if the read code isn't an expected |
| 58 |
http success code |
| 59 |
:raises NotFound: If a 404 response code is received |
| 60 |
:raises NotImplemented: If a 501 response code is received |
| 61 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 62 |
not in the response body |
| 63 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 64 |
over_limit is in the response body |
| 65 |
:raises ServerFault: If a 500 response code is received |
| 66 |
:raises Unauthorized: If a 401 response code is received |
| 67 |
:raises UnexpectedContentType: If the content-type of the response |
| 68 |
isn't an expect type |
| 69 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 70 |
received and it doesn't fall into any |
| 71 |
of the handled checks |
| 72 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 73 |
couldn't be parsed |
| 74 |
:returns: An availability zone object. |
| 75 |
""" |
| 76 |
kwargs = {arg: value for arg, value in locals().items() |
| 77 |
if arg != 'self' and value is not Unset} |
| 78 |
return self._create_object(**kwargs) |
| 79 |
|
| 80 |
@skip_if_not_implemented |
| 81 |
def show_availability_zone(self, availability_zone_name, query_params=None, |
| 82 |
return_object_only=True): |
| 83 |
"""Get the availability zone details. |
| 84 |
|
| 85 |
:param availability_zone_name: The availability zone name to query. |
| 86 |
:param query_params: The optional query parameters to append to the |
| 87 |
request. Ex. fields=id&fields=name |
| 88 |
:param return_object_only: If True, the response returns the object |
| 89 |
inside the root tag. False returns the full |
| 90 |
response from the API. |
| 91 |
:raises AssertionError: if the expected_code isn't a valid http success |
| 92 |
response code |
| 93 |
:raises BadRequest: If a 400 response code is received |
| 94 |
:raises Conflict: If a 409 response code is received |
| 95 |
:raises Forbidden: If a 403 response code is received |
| 96 |
:raises Gone: If a 410 response code is received |
| 97 |
:raises InvalidContentType: If a 415 response code is received |
| 98 |
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON |
| 99 |
:raises InvalidHttpSuccessCode: if the read code isn't an expected |
| 100 |
http success code |
| 101 |
:raises NotFound: If a 404 response code is received |
| 102 |
:raises NotImplemented: If a 501 response code is received |
| 103 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 104 |
not in the response body |
| 105 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 106 |
over_limit is in the response body |
| 107 |
:raises ServerFault: If a 500 response code is received |
| 108 |
:raises Unauthorized: If a 401 response code is received |
| 109 |
:raises UnexpectedContentType: If the content-type of the response |
| 110 |
isn't an expect type |
| 111 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 112 |
received and it doesn't fall into any |
| 113 |
of the handled checks |
| 114 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 115 |
couldn't be parsed |
| 116 |
:returns: An availability zone object. |
| 117 |
""" |
| 118 |
return self._show_object(obj_id=availability_zone_name, |
| 119 |
query_params=query_params, |
| 120 |
return_object_only=return_object_only) |
| 121 |
|
| 122 |
@skip_if_not_implemented |
| 123 |
def list_availability_zones(self, query_params=None, |
| 124 |
return_object_only=True): |
| 125 |
"""Get a list of availability zone objects. |
| 126 |
|
| 127 |
:param query_params: The optional query parameters to append to the |
| 128 |
request. Ex. fields=id&fields=name |
| 129 |
:param return_object_only: If True, the response returns the object |
| 130 |
inside the root tag. False returns the full |
| 131 |
response from the API. |
| 132 |
:raises AssertionError: if the expected_code isn't a valid http success |
| 133 |
response code |
| 134 |
:raises BadRequest: If a 400 response code is received |
| 135 |
:raises Conflict: If a 409 response code is received |
| 136 |
:raises Forbidden: If a 403 response code is received |
| 137 |
:raises Gone: If a 410 response code is received |
| 138 |
:raises InvalidContentType: If a 415 response code is received |
| 139 |
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON |
| 140 |
:raises InvalidHttpSuccessCode: if the read code isn't an expected |
| 141 |
http success code |
| 142 |
:raises NotFound: If a 404 response code is received |
| 143 |
:raises NotImplemented: If a 501 response code is received |
| 144 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 145 |
not in the response body |
| 146 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 147 |
over_limit is in the response body |
| 148 |
:raises ServerFault: If a 500 response code is received |
| 149 |
:raises Unauthorized: If a 401 response code is received |
| 150 |
:raises UnexpectedContentType: If the content-type of the response |
| 151 |
isn't an expect type |
| 152 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 153 |
received and it doesn't fall into any |
| 154 |
of the handled checks |
| 155 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 156 |
couldn't be parsed |
| 157 |
:returns: A list of availability zone objects. |
| 158 |
""" |
| 159 |
return self._list_objects(query_params=query_params, |
| 160 |
return_object_only=return_object_only) |
| 161 |
|
| 162 |
@skip_if_not_implemented |
| 163 |
def update_availability_zone(self, availability_zone_name, |
| 164 |
description=Unset, enabled=Unset, |
| 165 |
return_object_only=True): |
| 166 |
"""Update an availability zone. |
| 167 |
|
| 168 |
:param availability_zone_name: The availability zone name to update. |
| 169 |
:param description: A human-readable description for the resource. |
| 170 |
:param enabled: If the resource is available for use. |
| 171 |
:raises AssertionError: if the expected_code isn't a valid http success |
| 172 |
response code |
| 173 |
:raises BadRequest: If a 400 response code is received |
| 174 |
:raises Conflict: If a 409 response code is received |
| 175 |
:raises Forbidden: If a 403 response code is received |
| 176 |
:raises Gone: If a 410 response code is received |
| 177 |
:raises InvalidContentType: If a 415 response code is received |
| 178 |
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON |
| 179 |
:raises InvalidHttpSuccessCode: if the read code isn't an expected |
| 180 |
http success code |
| 181 |
:raises NotFound: If a 404 response code is received |
| 182 |
:raises NotImplemented: If a 501 response code is received |
| 183 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 184 |
not in the response body |
| 185 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 186 |
over_limit is in the response body |
| 187 |
:raises ServerFault: If a 500 response code is received |
| 188 |
:raises Unauthorized: If a 401 response code is received |
| 189 |
:raises UnexpectedContentType: If the content-type of the response |
| 190 |
isn't an expect type |
| 191 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 192 |
received and it doesn't fall into any |
| 193 |
of the handled checks |
| 194 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 195 |
couldn't be parsed |
| 196 |
:returns: An availability zone object. |
| 197 |
""" |
| 198 |
kwargs = {arg: value for arg, value in locals().items() |
| 199 |
if arg != 'self' and value is not Unset} |
| 200 |
kwargs['obj_id'] = kwargs.pop('availability_zone_name') |
| 201 |
return self._update_object(**kwargs) |
| 202 |
|
| 203 |
@skip_if_not_implemented |
| 204 |
def delete_availability_zone(self, availability_zone_name, |
| 205 |
ignore_errors=False): |
| 206 |
"""Delete an availability zone. |
| 207 |
|
| 208 |
:param availability_zone_name: The availability zone name to delete. |
| 209 |
:param ignore_errors: True if errors should be ignored. |
| 210 |
:raises AssertionError: if the expected_code isn't a valid http success |
| 211 |
response code |
| 212 |
:raises BadRequest: If a 400 response code is received |
| 213 |
:raises Conflict: If a 409 response code is received |
| 214 |
:raises Forbidden: If a 403 response code is received |
| 215 |
:raises Gone: If a 410 response code is received |
| 216 |
:raises InvalidContentType: If a 415 response code is received |
| 217 |
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON |
| 218 |
:raises InvalidHttpSuccessCode: if the read code isn't an expected |
| 219 |
http success code |
| 220 |
:raises NotFound: If a 404 response code is received |
| 221 |
:raises NotImplemented: If a 501 response code is received |
| 222 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 223 |
not in the response body |
| 224 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 225 |
over_limit is in the response body |
| 226 |
:raises ServerFault: If a 500 response code is received |
| 227 |
:raises Unauthorized: If a 401 response code is received |
| 228 |
:raises UnexpectedContentType: If the content-type of the response |
| 229 |
isn't an expect type |
| 230 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 231 |
received and it doesn't fall into any |
| 232 |
of the handled checks |
| 233 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 234 |
couldn't be parsed |
| 235 |
:returns: None if ignore_errors is True, the response status code |
| 236 |
if not. |
| 237 |
""" |
| 238 |
return self._delete_obj(obj_id=availability_zone_name, |
| 239 |
ignore_errors=ignore_errors) |
| 240 |
|
| 241 |
def cleanup_an_availability_zone(self, availability_zone_name): |
| 242 |
"""Delete an availability zone for tempest cleanup. |
| 243 |
|
| 244 |
We cannot use the cleanup_availability_zone method as availability |
| 245 |
zones do not have a provisioning_status. |
| 246 |
|
| 247 |
:param availability_zone_name: The availability zone name to delete. |
| 248 |
:raises AssertionError: if the expected_code isn't a valid http success |
| 249 |
response code |
| 250 |
:raises BadRequest: If a 400 response code is received |
| 251 |
:raises Conflict: If a 409 response code is received |
| 252 |
:raises Forbidden: If a 403 response code is received |
| 253 |
:raises Gone: If a 410 response code is received |
| 254 |
:raises InvalidContentType: If a 415 response code is received |
| 255 |
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON |
| 256 |
:raises InvalidHttpSuccessCode: if the read code isn't an expected |
| 257 |
http success code |
| 258 |
:raises NotImplemented: If a 501 response code is received |
| 259 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 260 |
not in the response body |
| 261 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 262 |
over_limit is in the response body |
| 263 |
:raises ServerFault: If a 500 response code is received |
| 264 |
:raises Unauthorized: If a 401 response code is received |
| 265 |
:raises UnexpectedContentType: If the content-type of the response |
| 266 |
isn't an expect type |
| 267 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 268 |
received and it doesn't fall into any |
| 269 |
of the handled checks |
| 270 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 271 |
couldn't be parsed |
| 272 |
:returns: None if ignore_errors is True, the response status code |
| 273 |
if not. |
| 274 |
""" |
| 275 |
try: |
| 276 |
self._delete_obj(obj_id=availability_zone_name) |
| 277 |
except exceptions.NotFound: |
| 278 |
|
| 279 |
LOG.info("Availability zone %s is already gone. " |
| 280 |
"Cleanup considered complete.", availability_zone_name) |