| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import copy |
| 18 |
import testtools |
| 19 |
import time |
| 20 |
from uuid import UUID |
| 21 |
|
| 22 |
from dateutil import parser |
| 23 |
|
| 24 |
from tempest import config |
| 25 |
from tempest.lib.common.utils import data_utils |
| 26 |
from tempest.lib import decorators |
| 27 |
from tempest.lib import exceptions |
| 28 |
|
| 29 |
from octavia_tempest_plugin.common import constants as const |
| 30 |
from octavia_tempest_plugin.tests import test_base |
| 31 |
from octavia_tempest_plugin.tests import waiters |
| 32 |
|
| 33 |
CONF = config.CONF |
| 34 |
|
| 35 |
|
| 36 |
class LoadBalancerAPITest(test_base.LoadBalancerBaseTest): |
| 37 |
"""Test the load balancer object API.""" |
| 38 |
|
| 39 |
|
| 40 |
@decorators.idempotent_id('61c6343c-a5d2-4b9f-8c7d-34ea83f0596b') |
| 41 |
def test_load_balancer_ipv4_create(self): |
| 42 |
self._test_load_balancer_create(4) |
| 43 |
|
| 44 |
|
| 45 |
@decorators.idempotent_id('fc9996de-4f55-4fc4-b8ef-a4b9170c7078') |
| 46 |
@testtools.skipUnless(CONF.load_balancer.test_with_ipv6, |
| 47 |
'IPv6 testing is disabled') |
| 48 |
def test_load_balancer_ipv6_create(self): |
| 49 |
self._test_load_balancer_create(6) |
| 50 |
|
| 51 |
def _test_load_balancer_create(self, ip_version): |
| 52 |
"""Tests load balancer create and basic show APIs. |
| 53 |
|
| 54 |
* Tests that users without the load balancer member role cannot |
| 55 |
create load balancers. |
| 56 |
* Create a fully populated load balancer. |
| 57 |
* Show load balancer details. |
| 58 |
* Validate the show reflects the requested values. |
| 59 |
""" |
| 60 |
lb_name = data_utils.rand_name("lb_member_lb1-create-" |
| 61 |
"ipv{}".format(ip_version)) |
| 62 |
lb_description = data_utils.arbitrary_string(size=255) |
| 63 |
|
| 64 |
lb_kwargs = {const.ADMIN_STATE_UP: True, |
| 65 |
const.DESCRIPTION: lb_description, |
| 66 |
const.PROVIDER: CONF.load_balancer.provider, |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
const.NAME: lb_name} |
| 72 |
|
| 73 |
if self.mem_listener_client.is_version_supported( |
| 74 |
self.api_version, '2.5'): |
| 75 |
lb_tags = ["Hello", "World"] |
| 76 |
lb_kwargs.update({ |
| 77 |
const.TAGS: lb_tags |
| 78 |
}) |
| 79 |
|
| 80 |
self._setup_lb_network_kwargs(lb_kwargs, ip_version, use_fixed_ip=True) |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
lb_kwargs_with_project_id = copy.deepcopy(lb_kwargs) |
| 85 |
lb_kwargs_with_project_id[const.PROJECT_ID] = ( |
| 86 |
self.os_roles_lb_member.credentials.project_id) |
| 87 |
expected_allowed = ['os_admin', 'os_primary', 'os_roles_lb_admin', |
| 88 |
'os_roles_lb_member', 'os_roles_lb_member2'] |
| 89 |
self.check_create_RBAC_enforcement( |
| 90 |
'LoadbalancerClient', 'create_loadbalancer', |
| 91 |
expected_allowed, None, None, **lb_kwargs_with_project_id) |
| 92 |
|
| 93 |
lb = self.mem_lb_client.create_loadbalancer(**lb_kwargs) |
| 94 |
|
| 95 |
self.addClassResourceCleanup( |
| 96 |
self.mem_lb_client.cleanup_loadbalancer, |
| 97 |
lb[const.ID]) |
| 98 |
|
| 99 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 100 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 101 |
const.ACTIVE, |
| 102 |
CONF.load_balancer.lb_build_interval, |
| 103 |
CONF.load_balancer.lb_build_timeout) |
| 104 |
if not CONF.load_balancer.test_with_noop: |
| 105 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 106 |
lb[const.ID], const.OPERATING_STATUS, |
| 107 |
const.ONLINE, |
| 108 |
CONF.load_balancer.check_interval, |
| 109 |
CONF.load_balancer.check_timeout) |
| 110 |
|
| 111 |
self.assertTrue(lb[const.ADMIN_STATE_UP]) |
| 112 |
parser.parse(lb[const.CREATED_AT]) |
| 113 |
parser.parse(lb[const.UPDATED_AT]) |
| 114 |
self.assertEqual(lb_description, lb[const.DESCRIPTION]) |
| 115 |
UUID(lb[const.ID]) |
| 116 |
self.assertEqual(lb_name, lb[const.NAME]) |
| 117 |
|
| 118 |
if CONF.load_balancer.test_with_noop: |
| 119 |
self.assertEqual(const.OFFLINE, lb[const.OPERATING_STATUS]) |
| 120 |
else: |
| 121 |
self.assertEqual(const.ONLINE, lb[const.OPERATING_STATUS]) |
| 122 |
if ip_version == 4: |
| 123 |
self.assertEqual(self.lb_member_vip_net[const.ID], |
| 124 |
lb[const.VIP_NETWORK_ID]) |
| 125 |
else: |
| 126 |
self.assertEqual(self.lb_member_vip_ipv6_net[const.ID], |
| 127 |
lb[const.VIP_NETWORK_ID]) |
| 128 |
|
| 129 |
self.assertEqual(self.os_roles_lb_member.credentials.project_id, |
| 130 |
lb[const.PROJECT_ID]) |
| 131 |
self.assertEqual(CONF.load_balancer.provider, lb[const.PROVIDER]) |
| 132 |
self.assertIsNotNone(lb[const.VIP_PORT_ID]) |
| 133 |
if lb_kwargs[const.VIP_SUBNET_ID]: |
| 134 |
if ip_version == 4 or self.lb_member_vip_ipv6_subnet_stateful: |
| 135 |
self.assertEqual(lb_kwargs[const.VIP_ADDRESS], |
| 136 |
lb[const.VIP_ADDRESS]) |
| 137 |
self.assertEqual(lb_kwargs[const.VIP_SUBNET_ID], |
| 138 |
lb[const.VIP_SUBNET_ID]) |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
try: |
| 143 |
self.mem_lb_client.delete_loadbalancer(lb[const.ID]) |
| 144 |
|
| 145 |
waiters.wait_for_deleted_status_or_not_found( |
| 146 |
self.mem_lb_client.show_loadbalancer, lb[const.ID], |
| 147 |
const.PROVISIONING_STATUS, |
| 148 |
CONF.load_balancer.lb_build_interval, |
| 149 |
CONF.load_balancer.lb_build_timeout) |
| 150 |
except Exception: |
| 151 |
pass |
| 152 |
|
| 153 |
if self.mem_listener_client.is_version_supported( |
| 154 |
self.api_version, '2.5'): |
| 155 |
self.assertCountEqual(lb_kwargs[const.TAGS], lb[const.TAGS]) |
| 156 |
|
| 157 |
@decorators.idempotent_id('643ef031-c800-45f2-b229-3c8f8b37c829') |
| 158 |
def test_load_balancer_delete(self): |
| 159 |
"""Tests load balancer create and delete APIs. |
| 160 |
|
| 161 |
* Creates a load balancer. |
| 162 |
* Validates that other accounts cannot delete the load balancer |
| 163 |
* Deletes the load balancer. |
| 164 |
* Validates the load balancer is in the DELETED state. |
| 165 |
""" |
| 166 |
lb_name = data_utils.rand_name("lb_member_lb1-delete") |
| 167 |
lb = self.mem_lb_client.create_loadbalancer( |
| 168 |
name=lb_name, provider=CONF.load_balancer.provider, |
| 169 |
vip_network_id=self.lb_member_vip_net[const.ID]) |
| 170 |
self.addClassResourceCleanup( |
| 171 |
self.mem_lb_client.cleanup_loadbalancer, |
| 172 |
lb[const.ID]) |
| 173 |
|
| 174 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 175 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 176 |
const.ACTIVE, |
| 177 |
CONF.load_balancer.lb_build_interval, |
| 178 |
CONF.load_balancer.lb_build_timeout) |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 183 |
'os_roles_lb_member'] |
| 184 |
self.check_delete_RBAC_enforcement( |
| 185 |
'LoadbalancerClient', 'delete_loadbalancer', |
| 186 |
expected_allowed, None, None, lb[const.ID]) |
| 187 |
|
| 188 |
self.mem_lb_client.delete_loadbalancer(lb[const.ID]) |
| 189 |
|
| 190 |
waiters.wait_for_deleted_status_or_not_found( |
| 191 |
self.mem_lb_client.show_loadbalancer, lb[const.ID], |
| 192 |
const.PROVISIONING_STATUS, |
| 193 |
CONF.load_balancer.lb_build_interval, |
| 194 |
CONF.load_balancer.lb_build_timeout) |
| 195 |
|
| 196 |
@decorators.idempotent_id('abd784e3-485f-442a-85da-d91365c6b5dd') |
| 197 |
def test_load_balancer_delete_cascade(self): |
| 198 |
"""Tests load balancer create and cascade delete APIs. |
| 199 |
|
| 200 |
* Creates a load balancer. |
| 201 |
* Validates that other accounts cannot delete the load balancer |
| 202 |
* Deletes the load balancer with the cascade parameter. |
| 203 |
* Validates the load balancer is in the DELETED state. |
| 204 |
""" |
| 205 |
lb_name = data_utils.rand_name("lb_member_lb1-cascade_delete") |
| 206 |
lb = self.mem_lb_client.create_loadbalancer( |
| 207 |
name=lb_name, provider=CONF.load_balancer.provider, |
| 208 |
vip_network_id=self.lb_member_vip_net[const.ID]) |
| 209 |
self.addClassResourceCleanup( |
| 210 |
self.mem_lb_client.cleanup_loadbalancer, |
| 211 |
lb[const.ID]) |
| 212 |
|
| 213 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 214 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 215 |
const.ACTIVE, |
| 216 |
CONF.load_balancer.lb_build_interval, |
| 217 |
CONF.load_balancer.lb_build_timeout) |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 224 |
'os_roles_lb_member'] |
| 225 |
self.check_delete_RBAC_enforcement( |
| 226 |
'LoadbalancerClient', 'delete_loadbalancer', |
| 227 |
expected_allowed, None, None, lb[const.ID], cascade=True) |
| 228 |
|
| 229 |
self.mem_lb_client.delete_loadbalancer(lb[const.ID], cascade=True) |
| 230 |
|
| 231 |
waiters.wait_for_deleted_status_or_not_found( |
| 232 |
self.mem_lb_client.show_loadbalancer, lb[const.ID], |
| 233 |
const.PROVISIONING_STATUS, |
| 234 |
CONF.load_balancer.lb_build_interval, |
| 235 |
CONF.load_balancer.lb_build_timeout) |
| 236 |
|
| 237 |
|
| 238 |
def _filter_lbs_by_id(self, lbs, ids): |
| 239 |
return [lb for lb in lbs if lb['id'] not in ids] |
| 240 |
|
| 241 |
def _filter_lbs_by_index(self, lbs, indexes): |
| 242 |
return [lb for i, lb in enumerate(lbs) if i not in indexes] |
| 243 |
|
| 244 |
@decorators.idempotent_id('6546ef3c-c0e2-46af-b892-f795f4d01119') |
| 245 |
def test_load_balancer_list(self): |
| 246 |
"""Tests load balancer list API and field filtering. |
| 247 |
|
| 248 |
* Create three load balancers. |
| 249 |
* Validates that other accounts cannot list the load balancers. |
| 250 |
* List the load balancers using the default sort order. |
| 251 |
* List the load balancers using descending sort order. |
| 252 |
* List the load balancers using ascending sort order. |
| 253 |
* List the load balancers returning one field at a time. |
| 254 |
* List the load balancers returning two fields. |
| 255 |
* List the load balancers filtering to one of the three. |
| 256 |
* List the load balancers filtered, one field, and sorted. |
| 257 |
""" |
| 258 |
|
| 259 |
test_ids = [] |
| 260 |
|
| 261 |
pretest_lbs = self.mem_lb_client.list_loadbalancers() |
| 262 |
|
| 263 |
pretest_lb_ids = [lb['id'] for lb in pretest_lbs] |
| 264 |
|
| 265 |
lb_name = data_utils.rand_name("lb_member_lb2-list") |
| 266 |
lb_description = data_utils.rand_name('B') |
| 267 |
lb_admin_state_up = True |
| 268 |
lb_provider = CONF.load_balancer.provider |
| 269 |
lb_vip_network_id = self.lb_member_vip_net[const.ID] |
| 270 |
|
| 271 |
lb_kwargs = { |
| 272 |
const.ADMIN_STATE_UP: lb_admin_state_up, |
| 273 |
const.DESCRIPTION: lb_description, |
| 274 |
|
| 275 |
|
| 276 |
const.PROVIDER: lb_provider, |
| 277 |
const.NAME: lb_name, |
| 278 |
|
| 279 |
|
| 280 |
const.VIP_NETWORK_ID: lb_vip_network_id |
| 281 |
} |
| 282 |
|
| 283 |
if self.mem_lb_client.is_version_supported(self.api_version, '2.5'): |
| 284 |
lb_tags = ["English", "Mathematics", "Marketing", "Creativity"] |
| 285 |
lb_kwargs.update({const.TAGS: lb_tags}) |
| 286 |
|
| 287 |
lb = self.mem_lb_client.create_loadbalancer( |
| 288 |
**lb_kwargs) |
| 289 |
|
| 290 |
self.addCleanup( |
| 291 |
self.mem_lb_client.cleanup_loadbalancer, |
| 292 |
lb[const.ID]) |
| 293 |
|
| 294 |
lb1 = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 295 |
lb[const.ID], |
| 296 |
const.PROVISIONING_STATUS, |
| 297 |
const.ACTIVE, |
| 298 |
CONF.load_balancer.lb_build_interval, |
| 299 |
CONF.load_balancer.lb_build_timeout) |
| 300 |
if not CONF.load_balancer.test_with_noop: |
| 301 |
lb1 = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 302 |
lb[const.ID], const.OPERATING_STATUS, |
| 303 |
const.ONLINE, |
| 304 |
CONF.load_balancer.check_interval, |
| 305 |
CONF.load_balancer.check_timeout) |
| 306 |
test_ids.append(lb1[const.ID]) |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
time.sleep(1) |
| 312 |
|
| 313 |
lb_name = data_utils.rand_name("lb_member_lb1-list") |
| 314 |
lb_description = data_utils.rand_name('A') |
| 315 |
lb_admin_state_up = True |
| 316 |
lb_provider = CONF.load_balancer.provider |
| 317 |
lb_vip_network_id = self.lb_member_vip_net[const.ID] |
| 318 |
|
| 319 |
lb_kwargs = { |
| 320 |
const.ADMIN_STATE_UP: lb_admin_state_up, |
| 321 |
const.DESCRIPTION: lb_description, |
| 322 |
const.PROVIDER: lb_provider, |
| 323 |
const.NAME: lb_name, |
| 324 |
const.VIP_NETWORK_ID: lb_vip_network_id, |
| 325 |
} |
| 326 |
|
| 327 |
if self.mem_lb_client.is_version_supported(self.api_version, '2.5'): |
| 328 |
lb_tags = ["English", "Spanish", "Soft_skills", "Creativity"] |
| 329 |
lb_kwargs.update({const.TAGS: lb_tags}) |
| 330 |
|
| 331 |
lb = self.mem_lb_client.create_loadbalancer( |
| 332 |
**lb_kwargs) |
| 333 |
|
| 334 |
self.addCleanup( |
| 335 |
self.mem_lb_client.cleanup_loadbalancer, |
| 336 |
lb[const.ID]) |
| 337 |
|
| 338 |
lb2 = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 339 |
lb[const.ID], |
| 340 |
const.PROVISIONING_STATUS, |
| 341 |
const.ACTIVE, |
| 342 |
CONF.load_balancer.lb_build_interval, |
| 343 |
CONF.load_balancer.lb_build_timeout) |
| 344 |
if not CONF.load_balancer.test_with_noop: |
| 345 |
lb2 = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 346 |
lb[const.ID], const.OPERATING_STATUS, |
| 347 |
const.ONLINE, |
| 348 |
CONF.load_balancer.check_interval, |
| 349 |
CONF.load_balancer.check_timeout) |
| 350 |
test_ids.append(lb2[const.ID]) |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
time.sleep(1) |
| 356 |
|
| 357 |
lb_name = data_utils.rand_name("lb_member_lb3-list") |
| 358 |
lb_description = data_utils.rand_name('C') |
| 359 |
lb_admin_state_up = False |
| 360 |
lb_provider = CONF.load_balancer.provider |
| 361 |
lb_vip_network_id = self.lb_member_vip_net[const.ID] |
| 362 |
|
| 363 |
lb_kwargs = { |
| 364 |
const.ADMIN_STATE_UP: lb_admin_state_up, |
| 365 |
const.DESCRIPTION: lb_description, |
| 366 |
const.PROVIDER: lb_provider, |
| 367 |
const.NAME: lb_name, |
| 368 |
const.VIP_NETWORK_ID: lb_vip_network_id, |
| 369 |
} |
| 370 |
|
| 371 |
if self.mem_lb_client.is_version_supported(self.api_version, '2.5'): |
| 372 |
lb_tags = ["English", "Project_management", |
| 373 |
"Communication", "Creativity"] |
| 374 |
lb_kwargs.update({const.TAGS: lb_tags}) |
| 375 |
|
| 376 |
lb = self.mem_lb_client.create_loadbalancer( |
| 377 |
**lb_kwargs) |
| 378 |
|
| 379 |
self.addCleanup( |
| 380 |
self.mem_lb_client.cleanup_loadbalancer, |
| 381 |
lb[const.ID]) |
| 382 |
|
| 383 |
lb3 = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 384 |
lb[const.ID], |
| 385 |
const.PROVISIONING_STATUS, |
| 386 |
const.ACTIVE, |
| 387 |
CONF.load_balancer.lb_build_interval, |
| 388 |
CONF.load_balancer.lb_build_timeout) |
| 389 |
test_ids.append(lb3[const.ID]) |
| 390 |
|
| 391 |
|
| 392 |
expected_allowed = [] |
| 393 |
if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN: |
| 394 |
expected_allowed = ['os_primary', 'os_roles_lb_member2'] |
| 395 |
if CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES: |
| 396 |
expected_allowed = ['os_primary', 'os_roles_lb_member2', |
| 397 |
'os_roles_lb_observer', |
| 398 |
'os_roles_lb_global_observer'] |
| 399 |
if CONF.load_balancer.RBAC_test_type == const.ADVANCED: |
| 400 |
expected_allowed = ['os_roles_lb_observer', 'os_roles_lb_member2'] |
| 401 |
if expected_allowed: |
| 402 |
self.check_list_RBAC_enforcement_count( |
| 403 |
'LoadbalancerClient', 'list_loadbalancers', |
| 404 |
expected_allowed, 0) |
| 405 |
|
| 406 |
|
| 407 |
expected_allowed = [] |
| 408 |
if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN: |
| 409 |
expected_allowed = ['os_admin', 'os_roles_lb_member'] |
| 410 |
if CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES: |
| 411 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 412 |
'os_roles_lb_member'] |
| 413 |
if CONF.load_balancer.RBAC_test_type == const.ADVANCED: |
| 414 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 415 |
'os_roles_lb_member', |
| 416 |
'os_roles_lb_global_observer'] |
| 417 |
if expected_allowed: |
| 418 |
self.check_list_IDs_RBAC_enforcement( |
| 419 |
'LoadbalancerClient', 'list_loadbalancers', |
| 420 |
expected_allowed, test_ids) |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
expected_allowed = [] |
| 427 |
if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN: |
| 428 |
expected_allowed = ['os_admin', 'os_primary', 'os_roles_lb_admin', |
| 429 |
'os_roles_lb_member', 'os_roles_lb_member2'] |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
if CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES: |
| 435 |
expected_allowed = ['os_admin', 'os_primary', 'os_roles_lb_admin', |
| 436 |
'os_roles_lb_observer', |
| 437 |
'os_roles_lb_global_observer', |
| 438 |
'os_roles_lb_member', 'os_roles_lb_member2'] |
| 439 |
if CONF.load_balancer.RBAC_test_type == const.ADVANCED: |
| 440 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 441 |
'os_roles_lb_observer', |
| 442 |
'os_roles_lb_global_observer', |
| 443 |
'os_roles_lb_member', 'os_roles_lb_member2'] |
| 444 |
if expected_allowed: |
| 445 |
self.check_list_RBAC_enforcement( |
| 446 |
'LoadbalancerClient', 'list_loadbalancers', expected_allowed) |
| 447 |
|
| 448 |
|
| 449 |
lbs = self.mem_lb_client.list_loadbalancers() |
| 450 |
lbs = self._filter_lbs_by_id(lbs, pretest_lb_ids) |
| 451 |
self.assertEqual(lb1[const.DESCRIPTION], lbs[0][const.DESCRIPTION]) |
| 452 |
self.assertEqual(lb2[const.DESCRIPTION], lbs[1][const.DESCRIPTION]) |
| 453 |
self.assertEqual(lb3[const.DESCRIPTION], lbs[2][const.DESCRIPTION]) |
| 454 |
|
| 455 |
|
| 456 |
lbs = self.mem_lb_client.list_loadbalancers( |
| 457 |
query_params='{sort}={descr}:{desc}'.format( |
| 458 |
sort=const.SORT, descr=const.DESCRIPTION, desc=const.DESC)) |
| 459 |
lbs = self._filter_lbs_by_id(lbs, pretest_lb_ids) |
| 460 |
self.assertEqual(lb1[const.DESCRIPTION], lbs[1][const.DESCRIPTION]) |
| 461 |
self.assertEqual(lb2[const.DESCRIPTION], lbs[2][const.DESCRIPTION]) |
| 462 |
self.assertEqual(lb3[const.DESCRIPTION], lbs[0][const.DESCRIPTION]) |
| 463 |
|
| 464 |
|
| 465 |
lbs = self.mem_lb_client.list_loadbalancers( |
| 466 |
query_params='{sort}={descr}:{asc}'.format(sort=const.SORT, |
| 467 |
descr=const.DESCRIPTION, |
| 468 |
asc=const.ASC)) |
| 469 |
lbs = self._filter_lbs_by_id(lbs, pretest_lb_ids) |
| 470 |
self.assertEqual(lb1[const.DESCRIPTION], lbs[1][const.DESCRIPTION]) |
| 471 |
self.assertEqual(lb2[const.DESCRIPTION], lbs[0][const.DESCRIPTION]) |
| 472 |
self.assertEqual(lb3[const.DESCRIPTION], lbs[2][const.DESCRIPTION]) |
| 473 |
|
| 474 |
|
| 475 |
pretest_lb_indexes = [] |
| 476 |
lbs = self.mem_lb_client.list_loadbalancers() |
| 477 |
for i, lb in enumerate(lbs): |
| 478 |
if lb['id'] in pretest_lb_ids: |
| 479 |
pretest_lb_indexes.append(i) |
| 480 |
|
| 481 |
|
| 482 |
for field in const.SHOW_LOAD_BALANCER_RESPONSE_FIELDS: |
| 483 |
lbs = self.mem_lb_client.list_loadbalancers( |
| 484 |
query_params='{fields}={field}'.format(fields=const.FIELDS, |
| 485 |
field=field)) |
| 486 |
lbs = self._filter_lbs_by_index(lbs, pretest_lb_indexes) |
| 487 |
self.assertEqual(1, len(lbs[0])) |
| 488 |
self.assertEqual(lb1[field], lbs[0][field]) |
| 489 |
self.assertEqual(lb2[field], lbs[1][field]) |
| 490 |
self.assertEqual(lb3[field], lbs[2][field]) |
| 491 |
|
| 492 |
|
| 493 |
lbs = self.mem_lb_client.list_loadbalancers( |
| 494 |
query_params='{fields}={admin}&{fields}={created}'.format( |
| 495 |
fields=const.FIELDS, admin=const.ADMIN_STATE_UP, |
| 496 |
created=const.CREATED_AT)) |
| 497 |
lbs = self._filter_lbs_by_index(lbs, pretest_lb_indexes) |
| 498 |
self.assertEqual(2, len(lbs[0])) |
| 499 |
self.assertTrue(lbs[0][const.ADMIN_STATE_UP]) |
| 500 |
parser.parse(lbs[0][const.CREATED_AT]) |
| 501 |
self.assertTrue(lbs[1][const.ADMIN_STATE_UP]) |
| 502 |
parser.parse(lbs[1][const.CREATED_AT]) |
| 503 |
self.assertFalse(lbs[2][const.ADMIN_STATE_UP]) |
| 504 |
parser.parse(lbs[2][const.CREATED_AT]) |
| 505 |
|
| 506 |
|
| 507 |
lbs = self.mem_lb_client.list_loadbalancers( |
| 508 |
query_params='{desc}={lb_desc}'.format( |
| 509 |
desc=const.DESCRIPTION, lb_desc=lb2[const.DESCRIPTION])) |
| 510 |
self.assertEqual(1, len(lbs)) |
| 511 |
self.assertEqual(lb2[const.DESCRIPTION], lbs[0][const.DESCRIPTION]) |
| 512 |
|
| 513 |
|
| 514 |
lbs = self.mem_lb_client.list_loadbalancers( |
| 515 |
query_params='{admin}={true}&{fields}={descr}&{fields}={id}&' |
| 516 |
'{sort}={descr}:{desc}'.format( |
| 517 |
admin=const.ADMIN_STATE_UP, |
| 518 |
true=const.ADMIN_STATE_UP_TRUE, |
| 519 |
fields=const.FIELDS, descr=const.DESCRIPTION, |
| 520 |
id=const.ID, sort=const.SORT, desc=const.DESC)) |
| 521 |
lbs = self._filter_lbs_by_id(lbs, pretest_lb_ids) |
| 522 |
|
| 523 |
self.assertEqual(2, len(lbs)) |
| 524 |
|
| 525 |
self.assertEqual(2, len(lbs[0])) |
| 526 |
|
| 527 |
self.assertEqual(lb2[const.DESCRIPTION], lbs[1][const.DESCRIPTION]) |
| 528 |
self.assertEqual(lb1[const.DESCRIPTION], lbs[0][const.DESCRIPTION]) |
| 529 |
|
| 530 |
|
| 531 |
if self.mem_lb_client.is_version_supported( |
| 532 |
self.api_version, '2.5'): |
| 533 |
list_of_lbs = [lb1, lb2, lb3] |
| 534 |
test_list = [] |
| 535 |
for lb in list_of_lbs: |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
if "English" in lb[const.TAGS] and "Creativity" in ( |
| 540 |
lb[const.TAGS]) and "Spanish" not in ( |
| 541 |
lb[const.TAGS]): |
| 542 |
test_list.append(lb[const.NAME]) |
| 543 |
|
| 544 |
|
| 545 |
self.assertEqual( |
| 546 |
test_list, [lb1[const.NAME], lb3[const.NAME]]) |
| 547 |
|
| 548 |
|
| 549 |
self.assertTrue(not any(["" in lb[const.TAGS] |
| 550 |
for lb in list_of_lbs])) |
| 551 |
|
| 552 |
@decorators.idempotent_id('826ae612-8717-4c64-a8a7-cb9570a85870') |
| 553 |
def test_load_balancer_show(self): |
| 554 |
"""Tests load balancer show API. |
| 555 |
|
| 556 |
* Create a fully populated load balancer. |
| 557 |
* Show load balancer details. |
| 558 |
* Validate the show reflects the requested values. |
| 559 |
* Validates that other accounts cannot see the load balancer. |
| 560 |
""" |
| 561 |
lb_name = data_utils.rand_name("lb_member_lb1-show") |
| 562 |
lb_description = data_utils.arbitrary_string(size=255) |
| 563 |
|
| 564 |
lb_kwargs = {const.ADMIN_STATE_UP: False, |
| 565 |
const.DESCRIPTION: lb_description, |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
const.PROVIDER: CONF.load_balancer.provider, |
| 571 |
const.NAME: lb_name} |
| 572 |
|
| 573 |
self._setup_lb_network_kwargs(lb_kwargs, 4, use_fixed_ip=True) |
| 574 |
|
| 575 |
lb = self.mem_lb_client.create_loadbalancer(**lb_kwargs) |
| 576 |
|
| 577 |
self.addClassResourceCleanup( |
| 578 |
self.mem_lb_client.cleanup_loadbalancer, |
| 579 |
lb[const.ID]) |
| 580 |
|
| 581 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 582 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 583 |
const.ACTIVE, |
| 584 |
CONF.load_balancer.lb_build_interval, |
| 585 |
CONF.load_balancer.lb_build_timeout) |
| 586 |
|
| 587 |
self.assertFalse(lb[const.ADMIN_STATE_UP]) |
| 588 |
parser.parse(lb[const.CREATED_AT]) |
| 589 |
parser.parse(lb[const.UPDATED_AT]) |
| 590 |
self.assertEqual(lb_description, lb[const.DESCRIPTION]) |
| 591 |
UUID(lb[const.ID]) |
| 592 |
self.assertEqual(lb_name, lb[const.NAME]) |
| 593 |
self.assertEqual(const.OFFLINE, lb[const.OPERATING_STATUS]) |
| 594 |
self.assertEqual(self.os_roles_lb_member.credentials.project_id, |
| 595 |
lb[const.PROJECT_ID]) |
| 596 |
self.assertEqual(CONF.load_balancer.provider, lb[const.PROVIDER]) |
| 597 |
self.assertEqual(self.lb_member_vip_net[const.ID], |
| 598 |
lb[const.VIP_NETWORK_ID]) |
| 599 |
self.assertIsNotNone(lb[const.VIP_PORT_ID]) |
| 600 |
if lb_kwargs[const.VIP_SUBNET_ID]: |
| 601 |
self.assertEqual(lb_kwargs[const.VIP_ADDRESS], |
| 602 |
lb[const.VIP_ADDRESS]) |
| 603 |
self.assertEqual(lb_kwargs[const.VIP_SUBNET_ID], |
| 604 |
lb[const.VIP_SUBNET_ID]) |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
if CONF.load_balancer.RBAC_test_type == const.ADVANCED: |
| 609 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 610 |
'os_roles_lb_global_observer', |
| 611 |
'os_roles_lb_member'] |
| 612 |
else: |
| 613 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 614 |
'os_roles_lb_member'] |
| 615 |
self.check_show_RBAC_enforcement( |
| 616 |
'LoadbalancerClient', 'show_loadbalancer', |
| 617 |
expected_allowed, lb[const.ID]) |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
try: |
| 622 |
self.mem_lb_client.delete_loadbalancer(lb[const.ID]) |
| 623 |
|
| 624 |
waiters.wait_for_deleted_status_or_not_found( |
| 625 |
self.mem_lb_client.show_loadbalancer, lb[const.ID], |
| 626 |
const.PROVISIONING_STATUS, |
| 627 |
CONF.load_balancer.lb_build_interval, |
| 628 |
CONF.load_balancer.lb_build_timeout) |
| 629 |
except Exception: |
| 630 |
pass |
| 631 |
|
| 632 |
@decorators.idempotent_id('b75a4d15-49d2-4149-a745-635eed1aacc3') |
| 633 |
def test_load_balancer_update(self): |
| 634 |
"""Tests load balancer update and show APIs. |
| 635 |
|
| 636 |
* Create a fully populated load balancer. |
| 637 |
* Show load balancer details. |
| 638 |
* Validate the show reflects the initial values. |
| 639 |
* Validates that other accounts cannot update the load balancer. |
| 640 |
* Update the load balancer details. |
| 641 |
* Show load balancer details. |
| 642 |
* Validate the show reflects the updated values. |
| 643 |
""" |
| 644 |
lb_name = data_utils.rand_name("lb_member_lb1-update") |
| 645 |
lb_description = data_utils.arbitrary_string(size=255) |
| 646 |
|
| 647 |
lb_kwargs = {const.ADMIN_STATE_UP: False, |
| 648 |
const.DESCRIPTION: lb_description, |
| 649 |
const.PROVIDER: CONF.load_balancer.provider, |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
const.NAME: lb_name} |
| 655 |
|
| 656 |
if self.mem_listener_client.is_version_supported( |
| 657 |
self.api_version, '2.5'): |
| 658 |
lb_tags = ["Hello", "World"] |
| 659 |
lb_kwargs.update({ |
| 660 |
const.TAGS: lb_tags |
| 661 |
}) |
| 662 |
|
| 663 |
self._setup_lb_network_kwargs(lb_kwargs, 4, use_fixed_ip=True) |
| 664 |
|
| 665 |
lb = self.mem_lb_client.create_loadbalancer(**lb_kwargs) |
| 666 |
|
| 667 |
self.addClassResourceCleanup( |
| 668 |
self.mem_lb_client.cleanup_loadbalancer, |
| 669 |
lb[const.ID]) |
| 670 |
|
| 671 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 672 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 673 |
const.ACTIVE, |
| 674 |
CONF.load_balancer.lb_build_interval, |
| 675 |
CONF.load_balancer.lb_build_timeout) |
| 676 |
|
| 677 |
self.assertFalse(lb[const.ADMIN_STATE_UP]) |
| 678 |
parser.parse(lb[const.CREATED_AT]) |
| 679 |
parser.parse(lb[const.UPDATED_AT]) |
| 680 |
self.assertEqual(lb_description, lb[const.DESCRIPTION]) |
| 681 |
UUID(lb[const.ID]) |
| 682 |
self.assertEqual(lb_name, lb[const.NAME]) |
| 683 |
self.assertEqual(const.OFFLINE, lb[const.OPERATING_STATUS]) |
| 684 |
self.assertEqual(self.os_roles_lb_member.credentials.project_id, |
| 685 |
lb[const.PROJECT_ID]) |
| 686 |
self.assertEqual(CONF.load_balancer.provider, lb[const.PROVIDER]) |
| 687 |
self.assertEqual(self.lb_member_vip_net[const.ID], |
| 688 |
lb[const.VIP_NETWORK_ID]) |
| 689 |
self.assertIsNotNone(lb[const.VIP_PORT_ID]) |
| 690 |
if lb_kwargs[const.VIP_SUBNET_ID]: |
| 691 |
self.assertEqual(lb_kwargs[const.VIP_ADDRESS], |
| 692 |
lb[const.VIP_ADDRESS]) |
| 693 |
self.assertEqual(lb_kwargs[const.VIP_SUBNET_ID], |
| 694 |
lb[const.VIP_SUBNET_ID]) |
| 695 |
|
| 696 |
if self.mem_listener_client.is_version_supported( |
| 697 |
self.api_version, '2.5'): |
| 698 |
self.assertCountEqual(lb_kwargs[const.TAGS], lb[const.TAGS]) |
| 699 |
|
| 700 |
new_name = data_utils.rand_name("lb_member_lb1-update") |
| 701 |
new_description = data_utils.arbitrary_string(size=255, |
| 702 |
base_text='new') |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 707 |
'os_roles_lb_member'] |
| 708 |
self.check_update_RBAC_enforcement( |
| 709 |
'LoadbalancerClient', 'update_loadbalancer', |
| 710 |
expected_allowed, None, None, lb[const.ID], |
| 711 |
admin_state_up=True) |
| 712 |
|
| 713 |
|
| 714 |
lb_check = self.mem_lb_client.show_loadbalancer(lb[const.ID]) |
| 715 |
self.assertEqual(const.ACTIVE, lb_check[const.PROVISIONING_STATUS]) |
| 716 |
self.assertFalse(lb_check[const.ADMIN_STATE_UP]) |
| 717 |
|
| 718 |
admin_state_up = True |
| 719 |
|
| 720 |
lb_update_kwargs = { |
| 721 |
|
| 722 |
const.ADMIN_STATE_UP: admin_state_up, |
| 723 |
const.DESCRIPTION: new_description, |
| 724 |
|
| 725 |
|
| 726 |
const.NAME: new_name |
| 727 |
} |
| 728 |
|
| 729 |
if self.mem_listener_client.is_version_supported( |
| 730 |
self.api_version, '2.5'): |
| 731 |
new_tags = ["Hola", "Mundo"] |
| 732 |
lb_update_kwargs.update({ |
| 733 |
const.TAGS: new_tags |
| 734 |
}) |
| 735 |
|
| 736 |
lb = self.mem_lb_client.update_loadbalancer( |
| 737 |
lb[const.ID], **lb_update_kwargs) |
| 738 |
|
| 739 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 740 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 741 |
const.ACTIVE, |
| 742 |
CONF.load_balancer.lb_build_interval, |
| 743 |
CONF.load_balancer.lb_build_timeout) |
| 744 |
|
| 745 |
self.assertTrue(lb[const.ADMIN_STATE_UP]) |
| 746 |
self.assertEqual(new_description, lb[const.DESCRIPTION]) |
| 747 |
self.assertEqual(new_name, lb[const.NAME]) |
| 748 |
self.assertCountEqual(lb_update_kwargs[const.TAGS], lb[const.TAGS]) |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
try: |
| 754 |
self.mem_lb_client.delete_loadbalancer(lb[const.ID]) |
| 755 |
|
| 756 |
waiters.wait_for_deleted_status_or_not_found( |
| 757 |
self.mem_lb_client.show_loadbalancer, lb[const.ID], |
| 758 |
const.PROVISIONING_STATUS, |
| 759 |
CONF.load_balancer.lb_build_interval, |
| 760 |
CONF.load_balancer.lb_build_timeout) |
| 761 |
except Exception: |
| 762 |
pass |
| 763 |
|
| 764 |
@decorators.idempotent_id('105afcba-4dd6-46d6-8fa4-bd7330aa1259') |
| 765 |
def test_load_balancer_show_stats(self): |
| 766 |
"""Tests load balancer show statistics API. |
| 767 |
|
| 768 |
* Create a load balancer. |
| 769 |
* Validates that other accounts cannot see the stats for the |
| 770 |
* load balancer. |
| 771 |
* Show load balancer statistics. |
| 772 |
* Validate the show reflects the expected values. |
| 773 |
""" |
| 774 |
lb_name = data_utils.rand_name("lb_member_lb1-show_stats") |
| 775 |
lb = self.mem_lb_client.create_loadbalancer( |
| 776 |
name=lb_name, provider=CONF.load_balancer.provider, |
| 777 |
vip_network_id=self.lb_member_vip_net[const.ID]) |
| 778 |
self.addClassResourceCleanup( |
| 779 |
self.mem_lb_client.cleanup_loadbalancer, |
| 780 |
lb[const.ID]) |
| 781 |
|
| 782 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 783 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 784 |
const.ACTIVE, |
| 785 |
CONF.load_balancer.lb_build_interval, |
| 786 |
CONF.load_balancer.lb_build_timeout) |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
if CONF.load_balancer.RBAC_test_type == const.ADVANCED: |
| 791 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 792 |
'os_roles_lb_global_observer', |
| 793 |
'os_roles_lb_member'] |
| 794 |
else: |
| 795 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 796 |
'os_roles_lb_member'] |
| 797 |
self.check_show_RBAC_enforcement( |
| 798 |
'LoadbalancerClient', 'get_loadbalancer_stats', |
| 799 |
expected_allowed, lb[const.ID]) |
| 800 |
|
| 801 |
stats = self.mem_lb_client.get_loadbalancer_stats(lb[const.ID]) |
| 802 |
|
| 803 |
self.assertEqual(5, len(stats)) |
| 804 |
self.assertEqual(0, stats[const.ACTIVE_CONNECTIONS]) |
| 805 |
self.assertEqual(0, stats[const.BYTES_IN]) |
| 806 |
self.assertEqual(0, stats[const.BYTES_OUT]) |
| 807 |
self.assertEqual(0, stats[const.REQUEST_ERRORS]) |
| 808 |
self.assertEqual(0, stats[const.TOTAL_CONNECTIONS]) |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
try: |
| 813 |
self.mem_lb_client.delete_loadbalancer(lb[const.ID]) |
| 814 |
|
| 815 |
waiters.wait_for_deleted_status_or_not_found( |
| 816 |
self.mem_lb_client.show_loadbalancer, lb[const.ID], |
| 817 |
const.PROVISIONING_STATUS, |
| 818 |
CONF.load_balancer.lb_build_interval, |
| 819 |
CONF.load_balancer.lb_build_timeout) |
| 820 |
except Exception: |
| 821 |
pass |
| 822 |
|
| 823 |
@decorators.idempotent_id('60acc1b0-fa46-41f8-b526-c81ae2f42c30') |
| 824 |
def test_load_balancer_show_status(self): |
| 825 |
"""Tests load balancer show status tree API. |
| 826 |
|
| 827 |
* Create a load balancer. |
| 828 |
* Validates that other accounts cannot see the status for the |
| 829 |
* load balancer. |
| 830 |
* Show load balancer status tree. |
| 831 |
* Validate the show reflects the expected values. |
| 832 |
""" |
| 833 |
lb_name = data_utils.rand_name("lb_member_lb1-status") |
| 834 |
lb = self.mem_lb_client.create_loadbalancer( |
| 835 |
name=lb_name, provider=CONF.load_balancer.provider, |
| 836 |
vip_network_id=self.lb_member_vip_net[const.ID]) |
| 837 |
self.addClassResourceCleanup( |
| 838 |
self.mem_lb_client.cleanup_loadbalancer, |
| 839 |
lb[const.ID]) |
| 840 |
|
| 841 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 842 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 843 |
const.ACTIVE, |
| 844 |
CONF.load_balancer.lb_build_interval, |
| 845 |
CONF.load_balancer.lb_build_timeout) |
| 846 |
if not CONF.load_balancer.test_with_noop: |
| 847 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 848 |
lb[const.ID], const.OPERATING_STATUS, |
| 849 |
const.ONLINE, |
| 850 |
CONF.load_balancer.check_interval, |
| 851 |
CONF.load_balancer.check_timeout) |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
if CONF.load_balancer.RBAC_test_type == const.ADVANCED: |
| 856 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 857 |
'os_roles_lb_global_observer', |
| 858 |
'os_roles_lb_member'] |
| 859 |
else: |
| 860 |
expected_allowed = ['os_admin', 'os_roles_lb_admin', |
| 861 |
'os_roles_lb_member'] |
| 862 |
self.check_show_RBAC_enforcement( |
| 863 |
'LoadbalancerClient', 'get_loadbalancer_status', |
| 864 |
expected_allowed, lb[const.ID]) |
| 865 |
|
| 866 |
status = self.mem_lb_client.get_loadbalancer_status(lb[const.ID]) |
| 867 |
|
| 868 |
self.assertEqual(1, len(status)) |
| 869 |
lb_status = status[const.LOADBALANCER] |
| 870 |
self.assertEqual(5, len(lb_status)) |
| 871 |
self.assertEqual(lb[const.ID], lb_status[const.ID]) |
| 872 |
self.assertEqual([], lb_status[const.LISTENERS]) |
| 873 |
self.assertEqual(lb_name, lb_status[const.NAME]) |
| 874 |
|
| 875 |
if CONF.load_balancer.test_with_noop: |
| 876 |
self.assertEqual(const.OFFLINE, lb_status[const.OPERATING_STATUS]) |
| 877 |
else: |
| 878 |
self.assertEqual(const.ONLINE, lb_status[const.OPERATING_STATUS]) |
| 879 |
self.assertEqual(const.ACTIVE, lb_status[const.PROVISIONING_STATUS]) |
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
try: |
| 884 |
self.mem_lb_client.delete_loadbalancer(lb[const.ID]) |
| 885 |
|
| 886 |
waiters.wait_for_deleted_status_or_not_found( |
| 887 |
self.mem_lb_client.show_loadbalancer, lb[const.ID], |
| 888 |
const.PROVISIONING_STATUS, |
| 889 |
CONF.load_balancer.lb_build_interval, |
| 890 |
CONF.load_balancer.lb_build_timeout) |
| 891 |
except Exception: |
| 892 |
pass |
| 893 |
|
| 894 |
@decorators.idempotent_id('fc2e07a6-9776-4559-90c9-141170d4c397') |
| 895 |
def test_load_balancer_failover(self): |
| 896 |
"""Tests load balancer failover API. |
| 897 |
|
| 898 |
* Create a load balancer. |
| 899 |
* Validates that other accounts cannot failover the load balancer |
| 900 |
* Wait for the load balancer to go ACTIVE. |
| 901 |
* Failover the load balancer. |
| 902 |
* Wait for the load balancer to go ACTIVE. |
| 903 |
""" |
| 904 |
lb_name = data_utils.rand_name("lb_member_lb1-failover") |
| 905 |
lb = self.mem_lb_client.create_loadbalancer( |
| 906 |
name=lb_name, provider=CONF.load_balancer.provider, |
| 907 |
vip_network_id=self.lb_member_vip_net[const.ID]) |
| 908 |
self.addClassResourceCleanup( |
| 909 |
self.mem_lb_client.cleanup_loadbalancer, |
| 910 |
lb[const.ID]) |
| 911 |
|
| 912 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 913 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 914 |
const.ACTIVE, |
| 915 |
CONF.load_balancer.lb_build_interval, |
| 916 |
CONF.load_balancer.lb_build_timeout) |
| 917 |
|
| 918 |
|
| 919 |
if not CONF.load_balancer.RBAC_test_type == const.NONE: |
| 920 |
self.assertRaises(exceptions.Forbidden, |
| 921 |
self.mem_lb_client.failover_loadbalancer, |
| 922 |
lb[const.ID]) |
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
expected_allowed = ['os_admin', 'os_roles_lb_admin'] |
| 927 |
self.check_update_RBAC_enforcement( |
| 928 |
'LoadbalancerClient', 'failover_loadbalancer', |
| 929 |
expected_allowed, None, None, lb[const.ID]) |
| 930 |
|
| 931 |
|
| 932 |
lb = self.mem_lb_client.show_loadbalancer(lb[const.ID]) |
| 933 |
self.assertEqual(const.ACTIVE, lb[const.PROVISIONING_STATUS]) |
| 934 |
|
| 935 |
if CONF.load_balancer.provider in const.AMPHORA_PROVIDERS: |
| 936 |
before_amphorae = self.lb_admin_amphora_client.list_amphorae( |
| 937 |
query_params='{loadbalancer_id}={lb_id}'.format( |
| 938 |
loadbalancer_id=const.LOADBALANCER_ID, lb_id=lb[const.ID])) |
| 939 |
|
| 940 |
admin_lb_client = ( |
| 941 |
self.os_roles_lb_admin.load_balancer_v2.LoadbalancerClient()) |
| 942 |
admin_lb_client.failover_loadbalancer(lb[const.ID]) |
| 943 |
|
| 944 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 945 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 946 |
const.ACTIVE, |
| 947 |
CONF.load_balancer.lb_build_interval, |
| 948 |
CONF.load_balancer.lb_build_timeout) |
| 949 |
|
| 950 |
if CONF.load_balancer.provider in const.AMPHORA_PROVIDERS: |
| 951 |
after_amphorae = self.lb_admin_amphora_client.list_amphorae( |
| 952 |
query_params='{loadbalancer_id}={lb_id}'.format( |
| 953 |
loadbalancer_id=const.LOADBALANCER_ID, lb_id=lb[const.ID])) |
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
for amphora in before_amphorae: |
| 958 |
for new_amp in after_amphorae: |
| 959 |
self.assertNotEqual(amphora[const.ID], new_amp[const.ID]) |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
try: |
| 964 |
self.mem_lb_client.delete_loadbalancer(lb[const.ID]) |
| 965 |
|
| 966 |
waiters.wait_for_deleted_status_or_not_found( |
| 967 |
self.mem_lb_client.show_loadbalancer, lb[const.ID], |
| 968 |
const.PROVISIONING_STATUS, |
| 969 |
CONF.load_balancer.lb_build_interval, |
| 970 |
CONF.load_balancer.lb_build_timeout) |
| 971 |
except Exception: |
| 972 |
pass |