| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
from tempest import config |
| 16 |
|
| 17 |
from octavia_tempest_plugin.common.decorators import skip_if_not_implemented |
| 18 |
from octavia_tempest_plugin.services.load_balancer.v2 import base_client |
| 19 |
from octavia_tempest_plugin.services.load_balancer.v2 import l7policy_client |
| 20 |
|
| 21 |
CONF = config.CONF |
| 22 |
Unset = base_client.Unset |
| 23 |
|
| 24 |
|
| 25 |
class L7RuleClient(base_client.BaseLBaaSClient): |
| 26 |
|
| 27 |
root_tag = 'rule' |
| 28 |
list_root_tag = 'rules' |
| 29 |
resource_name = 'l7rule' |
| 30 |
|
| 31 |
def __init__(self, *args, **kwargs): |
| 32 |
super(L7RuleClient, self).__init__(*args, **kwargs) |
| 33 |
l7policy_list_root_tag = l7policy_client.L7PolicyClient.list_root_tag |
| 34 |
|
| 35 |
self.uri = "{l7policy_base_uri}/{parent}/{object}".format( |
| 36 |
l7policy_base_uri=self.base_uri.format( |
| 37 |
object=l7policy_list_root_tag), |
| 38 |
parent="{parent}", |
| 39 |
object=self.list_root_tag |
| 40 |
) |
| 41 |
|
| 42 |
@skip_if_not_implemented |
| 43 |
def create_l7rule(self, l7policy_id, type, value, compare_type, tags=Unset, |
| 44 |
admin_state_up=Unset, key=Unset, invert=Unset, |
| 45 |
return_object_only=True): |
| 46 |
"""Create a l7rule. |
| 47 |
|
| 48 |
:param l7policy_id: The ID of the l7policy for the l7rule. |
| 49 |
:param type: The L7 rule type. |
| 50 |
:param value: The value to use for the comparison. |
| 51 |
:param compare_type: The comparison type for the L7 rule. |
| 52 |
:param tags: The tags of the L7 rule. |
| 53 |
:param admin_state_up: The administrative state of the resource, which |
| 54 |
is up (true) or down (false). |
| 55 |
:param key: The key to use for the comparison. |
| 56 |
:param invert: When true the logic of the rule is inverted. |
| 57 |
:param return_object_only: If True, the response returns the object |
| 58 |
inside the root tag. False returns the full |
| 59 |
response from the API. |
| 60 |
:raises AssertionError: if the expected_code isn't a valid http success |
| 61 |
response code |
| 62 |
:raises BadRequest: If a 400 response code is received |
| 63 |
:raises Conflict: If a 409 response code is received |
| 64 |
:raises Forbidden: If a 403 response code is received |
| 65 |
:raises Gone: If a 410 response code is received |
| 66 |
:raises InvalidContentType: If a 415 response code is received |
| 67 |
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON |
| 68 |
:raises InvalidHttpSuccessCode: if the read code isn't an expected |
| 69 |
http success code |
| 70 |
:raises NotFound: If a 404 response code is received |
| 71 |
:raises NotImplemented: If a 501 response code is received |
| 72 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 73 |
not in the response body |
| 74 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 75 |
over_limit is in the response body |
| 76 |
:raises ServerFault: If a 500 response code is received |
| 77 |
:raises Unauthorized: If a 401 response code is received |
| 78 |
:raises UnexpectedContentType: If the content-type of the response |
| 79 |
isn't an expect type |
| 80 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 81 |
received and it doesn't fall into any |
| 82 |
of the handled checks |
| 83 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 84 |
couldn't be parsed |
| 85 |
:returns: A l7rule object. |
| 86 |
""" |
| 87 |
kwargs = {arg: value for arg, value in locals().items() |
| 88 |
if arg != 'self' and value is not Unset} |
| 89 |
kwargs['parent_id'] = kwargs.pop('l7policy_id') |
| 90 |
return self._create_object(**kwargs) |
| 91 |
|
| 92 |
@skip_if_not_implemented |
| 93 |
def show_l7rule(self, l7rule_id, l7policy_id, query_params=None, |
| 94 |
return_object_only=True): |
| 95 |
"""Get l7rule details. |
| 96 |
|
| 97 |
:param l7rule_id: The l7rule ID to query. |
| 98 |
:param l7policy_id: The ID of the l7policy for the l7rule. |
| 99 |
:param query_params: The optional query parameters to append to the |
| 100 |
request. Ex. fields=id&fields=name |
| 101 |
:param return_object_only: If True, the response returns the object |
| 102 |
inside the root tag. False returns the full |
| 103 |
response from the API. |
| 104 |
:raises AssertionError: if the expected_code isn't a valid http success |
| 105 |
response code |
| 106 |
:raises BadRequest: If a 400 response code is received |
| 107 |
:raises Conflict: If a 409 response code is received |
| 108 |
:raises Forbidden: If a 403 response code is received |
| 109 |
:raises Gone: If a 410 response code is received |
| 110 |
:raises InvalidContentType: If a 415 response code is received |
| 111 |
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON |
| 112 |
:raises InvalidHttpSuccessCode: if the read code isn't an expected |
| 113 |
http success code |
| 114 |
:raises NotFound: If a 404 response code is received |
| 115 |
:raises NotImplemented: If a 501 response code is received |
| 116 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 117 |
not in the response body |
| 118 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 119 |
over_limit is in the response body |
| 120 |
:raises ServerFault: If a 500 response code is received |
| 121 |
:raises Unauthorized: If a 401 response code is received |
| 122 |
:raises UnexpectedContentType: If the content-type of the response |
| 123 |
isn't an expect type |
| 124 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 125 |
received and it doesn't fall into any |
| 126 |
of the handled checks |
| 127 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 128 |
couldn't be parsed |
| 129 |
:returns: A l7rule object. |
| 130 |
""" |
| 131 |
return self._show_object(obj_id=l7rule_id, |
| 132 |
parent_id=l7policy_id, |
| 133 |
query_params=query_params, |
| 134 |
return_object_only=return_object_only) |
| 135 |
|
| 136 |
@skip_if_not_implemented |
| 137 |
def list_l7rules(self, l7policy_id, query_params=None, |
| 138 |
return_object_only=True): |
| 139 |
"""Get a list of l7rule objects. |
| 140 |
|
| 141 |
:param l7policy_id: The ID of the l7policy for the l7rule. |
| 142 |
:param query_params: The optional query parameters to append to the |
| 143 |
request. Ex. fields=id&fields=name |
| 144 |
:param return_object_only: If True, the response returns the object |
| 145 |
inside the root tag. False returns the full |
| 146 |
response from the API. |
| 147 |
:raises AssertionError: if the expected_code isn't a valid http success |
| 148 |
response code |
| 149 |
:raises BadRequest: If a 400 response code is received |
| 150 |
:raises Conflict: If a 409 response code is received |
| 151 |
:raises Forbidden: If a 403 response code is received |
| 152 |
:raises Gone: If a 410 response code is received |
| 153 |
:raises InvalidContentType: If a 415 response code is received |
| 154 |
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON |
| 155 |
:raises InvalidHttpSuccessCode: if the read code isn't an expected |
| 156 |
http success code |
| 157 |
:raises NotFound: If a 404 response code is received |
| 158 |
:raises NotImplemented: If a 501 response code is received |
| 159 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 160 |
not in the response body |
| 161 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 162 |
over_limit is in the response body |
| 163 |
:raises ServerFault: If a 500 response code is received |
| 164 |
:raises Unauthorized: If a 401 response code is received |
| 165 |
:raises UnexpectedContentType: If the content-type of the response |
| 166 |
isn't an expect type |
| 167 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 168 |
received and it doesn't fall into any |
| 169 |
of the handled checks |
| 170 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 171 |
couldn't be parsed |
| 172 |
:returns: A list of l7rule objects. |
| 173 |
""" |
| 174 |
return self._list_objects(parent_id=l7policy_id, |
| 175 |
query_params=query_params, |
| 176 |
return_object_only=return_object_only) |
| 177 |
|
| 178 |
@skip_if_not_implemented |
| 179 |
def update_l7rule(self, l7rule_id, l7policy_id, type=Unset, value=Unset, |
| 180 |
compare_type=Unset, tags=Unset, admin_state_up=Unset, |
| 181 |
key=Unset, invert=Unset, return_object_only=True): |
| 182 |
"""Update a l7rule. |
| 183 |
|
| 184 |
:param l7rule_id: The l7rule ID to update. |
| 185 |
:param l7policy_id: The ID of the l7policy for the l7rule. |
| 186 |
:param type: The L7 rule type. |
| 187 |
:param value: The value to use for the comparison. |
| 188 |
:param compare_type: The comparison type for the L7 rule. |
| 189 |
:param tags: The tags of the L7 rule. |
| 190 |
:param admin_state_up: The administrative state of the resource, which |
| 191 |
is up (true) or down (false). |
| 192 |
:param key: The key to use for the comparison. |
| 193 |
:param invert: When true the logic of the rule is inverted. |
| 194 |
:param return_object_only: If True, the response returns the object |
| 195 |
inside the root tag. False returns the full |
| 196 |
response from the API. |
| 197 |
:raises AssertionError: if the expected_code isn't a valid http success |
| 198 |
response code |
| 199 |
:raises BadRequest: If a 400 response code is received |
| 200 |
:raises Conflict: If a 409 response code is received |
| 201 |
:raises Forbidden: If a 403 response code is received |
| 202 |
:raises Gone: If a 410 response code is received |
| 203 |
:raises InvalidContentType: If a 415 response code is received |
| 204 |
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON |
| 205 |
:raises InvalidHttpSuccessCode: if the read code isn't an expected |
| 206 |
http success code |
| 207 |
:raises NotFound: If a 404 response code is received |
| 208 |
:raises NotImplemented: If a 501 response code is received |
| 209 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 210 |
not in the response body |
| 211 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 212 |
over_limit is in the response body |
| 213 |
:raises ServerFault: If a 500 response code is received |
| 214 |
:raises Unauthorized: If a 401 response code is received |
| 215 |
:raises UnexpectedContentType: If the content-type of the response |
| 216 |
isn't an expect type |
| 217 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 218 |
received and it doesn't fall into any |
| 219 |
of the handled checks |
| 220 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 221 |
couldn't be parsed |
| 222 |
:returns: A l7rule object. |
| 223 |
""" |
| 224 |
kwargs = {arg: value for arg, value in locals().items() |
| 225 |
if arg != 'self' and value is not Unset} |
| 226 |
kwargs['obj_id'] = kwargs.pop('l7rule_id') |
| 227 |
kwargs['parent_id'] = kwargs.pop('l7policy_id') |
| 228 |
return self._update_object(**kwargs) |
| 229 |
|
| 230 |
@skip_if_not_implemented |
| 231 |
def delete_l7rule(self, l7rule_id, l7policy_id, ignore_errors=False): |
| 232 |
"""Delete a l7rule. |
| 233 |
|
| 234 |
:param l7rule_id: The l7rule ID to delete. |
| 235 |
:param l7policy_id: The ID of the l7policy for the l7rule. |
| 236 |
:param ignore_errors: True if errors should be ignored. |
| 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 NotFound: If a 404 response code is received |
| 248 |
:raises NotImplemented: If a 501 response code is received |
| 249 |
:raises OverLimit: If a 413 response code is received and over_limit is |
| 250 |
not in the response body |
| 251 |
:raises RateLimitExceeded: If a 413 response code is received and |
| 252 |
over_limit is in the response body |
| 253 |
:raises ServerFault: If a 500 response code is received |
| 254 |
:raises Unauthorized: If a 401 response code is received |
| 255 |
:raises UnexpectedContentType: If the content-type of the response |
| 256 |
isn't an expect type |
| 257 |
:raises UnexpectedResponseCode: If a response code above 400 is |
| 258 |
received and it doesn't fall into any |
| 259 |
of the handled checks |
| 260 |
:raises UnprocessableEntity: If a 422 response code is received and |
| 261 |
couldn't be parsed |
| 262 |
:returns: None if ignore_errors is True, the response status code |
| 263 |
if not. |
| 264 |
""" |
| 265 |
return self._delete_obj(obj_id=l7rule_id, |
| 266 |
parent_id=l7policy_id, |
| 267 |
ignore_errors=ignore_errors) |
| 268 |
|
| 269 |
def cleanup_l7rule(self, l7rule_id, l7policy_id, lb_client=None, |
| 270 |
lb_id=None): |
| 271 |
kwargs = {arg: value for arg, value in locals().items() |
| 272 |
if arg != 'self' and value is not Unset} |
| 273 |
kwargs['obj_id'] = kwargs.pop('l7rule_id') |
| 274 |
kwargs['parent_id'] = kwargs.pop('l7policy_id') |
| 275 |
return self._cleanup_obj(**kwargs) |
| 276 |
|
| 277 |
def is_resource_deleted(self, id): |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
raise NotImplementedError() |