| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
import requests |
| 17 |
import testtools |
| 18 |
import time |
| 19 |
|
| 20 |
from oslo_log import log as logging |
| 21 |
from tempest import config |
| 22 |
from tempest.lib.common.utils import data_utils |
| 23 |
from tempest.lib import decorators |
| 24 |
from tempest.lib import exceptions |
| 25 |
|
| 26 |
from octavia_tempest_plugin.common import constants as const |
| 27 |
from octavia_tempest_plugin.services.load_balancer import v2 |
| 28 |
from octavia_tempest_plugin.tests import test_base |
| 29 |
from octavia_tempest_plugin.tests import waiters |
| 30 |
|
| 31 |
CONF = config.CONF |
| 32 |
LOG = logging.getLogger(__name__) |
| 33 |
|
| 34 |
|
| 35 |
@testtools.skipUnless( |
| 36 |
CONF.validation.run_validation, |
| 37 |
'Active-Standby tests will not work without run_validation enabled.') |
| 38 |
class ActiveStandbyScenarioTest(test_base.LoadBalancerBaseTestWithCompute): |
| 39 |
mem_listener_client: v2.ListenerClient |
| 40 |
|
| 41 |
@classmethod |
| 42 |
def resource_setup(cls): |
| 43 |
"""Setup resources needed by the tests.""" |
| 44 |
super(ActiveStandbyScenarioTest, cls).resource_setup() |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
if not cls.lb_admin_flavor_profile_client.is_version_supported( |
| 49 |
cls.api_version, '2.3'): |
| 50 |
return |
| 51 |
|
| 52 |
lb_name = data_utils.rand_name("lb_member_lb1_actstdby") |
| 53 |
lb_kwargs = {const.PROVIDER: CONF.load_balancer.provider, |
| 54 |
const.NAME: lb_name} |
| 55 |
|
| 56 |
|
| 57 |
ip_version = 4 |
| 58 |
cls._setup_lb_network_kwargs(lb_kwargs, ip_version) |
| 59 |
|
| 60 |
lb = cls.mem_lb_client.create_loadbalancer(**lb_kwargs) |
| 61 |
cls.lb_id = lb[const.ID] |
| 62 |
cls.addClassResourceCleanup( |
| 63 |
cls.mem_lb_client.cleanup_loadbalancer, |
| 64 |
cls.lb_id) |
| 65 |
|
| 66 |
if CONF.validation.connect_method == 'floating': |
| 67 |
port_id = lb[const.VIP_PORT_ID] |
| 68 |
result = cls.lb_mem_float_ip_client.create_floatingip( |
| 69 |
floating_network_id=CONF.network.public_network_id, |
| 70 |
port_id=port_id) |
| 71 |
floating_ip = result['floatingip'] |
| 72 |
LOG.info('lb1_floating_ip: %s', floating_ip) |
| 73 |
cls.addClassResourceCleanup( |
| 74 |
waiters.wait_for_not_found, |
| 75 |
cls.lb_mem_float_ip_client.delete_floatingip, |
| 76 |
cls.lb_mem_float_ip_client.show_floatingip, |
| 77 |
floatingip_id=floating_ip['id']) |
| 78 |
cls.lb_vip_address = floating_ip['floating_ip_address'] |
| 79 |
else: |
| 80 |
cls.lb_vip_address = lb[const.VIP_ADDRESS] |
| 81 |
|
| 82 |
waiters.wait_for_status(cls.mem_lb_client.show_loadbalancer, |
| 83 |
cls.lb_id, const.PROVISIONING_STATUS, |
| 84 |
const.ACTIVE, |
| 85 |
CONF.load_balancer.lb_build_interval, |
| 86 |
CONF.load_balancer.lb_build_timeout) |
| 87 |
|
| 88 |
listener_name = data_utils.rand_name("lb_member_listener1_actstdby") |
| 89 |
listener_kwargs = { |
| 90 |
const.NAME: listener_name, |
| 91 |
const.PROTOCOL: const.HTTP, |
| 92 |
const.PROTOCOL_PORT: '80', |
| 93 |
const.LOADBALANCER_ID: cls.lb_id, |
| 94 |
} |
| 95 |
listener = cls.mem_listener_client.create_listener(**listener_kwargs) |
| 96 |
cls.listener_id = listener[const.ID] |
| 97 |
cls.addClassResourceCleanup( |
| 98 |
cls.mem_listener_client.cleanup_listener, |
| 99 |
cls.listener_id, |
| 100 |
lb_client=cls.mem_lb_client, lb_id=cls.lb_id) |
| 101 |
|
| 102 |
waiters.wait_for_status(cls.mem_lb_client.show_loadbalancer, |
| 103 |
cls.lb_id, const.PROVISIONING_STATUS, |
| 104 |
const.ACTIVE, |
| 105 |
CONF.load_balancer.build_interval, |
| 106 |
CONF.load_balancer.build_timeout) |
| 107 |
|
| 108 |
pool_name = data_utils.rand_name("lb_member_pool1_actstdby") |
| 109 |
pool_kwargs = { |
| 110 |
const.NAME: pool_name, |
| 111 |
const.PROTOCOL: const.HTTP, |
| 112 |
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN, |
| 113 |
const.LISTENER_ID: cls.listener_id, |
| 114 |
} |
| 115 |
pool = cls.mem_pool_client.create_pool(**pool_kwargs) |
| 116 |
cls.pool_id = pool[const.ID] |
| 117 |
cls.addClassResourceCleanup( |
| 118 |
cls.mem_pool_client.cleanup_pool, |
| 119 |
cls.pool_id, |
| 120 |
lb_client=cls.mem_lb_client, lb_id=cls.lb_id) |
| 121 |
|
| 122 |
waiters.wait_for_status(cls.mem_lb_client.show_loadbalancer, |
| 123 |
cls.lb_id, const.PROVISIONING_STATUS, |
| 124 |
const.ACTIVE, |
| 125 |
CONF.load_balancer.build_interval, |
| 126 |
CONF.load_balancer.build_timeout) |
| 127 |
|
| 128 |
|
| 129 |
member1_name = data_utils.rand_name("lb_member_member1_actstdby") |
| 130 |
member1_kwargs = { |
| 131 |
const.POOL_ID: cls.pool_id, |
| 132 |
const.NAME: member1_name, |
| 133 |
const.ADMIN_STATE_UP: True, |
| 134 |
const.ADDRESS: cls.webserver1_ip, |
| 135 |
const.PROTOCOL_PORT: 80, |
| 136 |
} |
| 137 |
if cls.lb_member_1_subnet: |
| 138 |
member1_kwargs[const.SUBNET_ID] = cls.lb_member_1_subnet[const.ID] |
| 139 |
|
| 140 |
member1 = cls.mem_member_client.create_member( |
| 141 |
**member1_kwargs) |
| 142 |
cls.addClassResourceCleanup( |
| 143 |
cls.mem_member_client.cleanup_member, |
| 144 |
member1[const.ID], pool_id=cls.pool_id, |
| 145 |
lb_client=cls.mem_lb_client, lb_id=cls.lb_id) |
| 146 |
waiters.wait_for_status( |
| 147 |
cls.mem_lb_client.show_loadbalancer, cls.lb_id, |
| 148 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 149 |
CONF.load_balancer.check_interval, |
| 150 |
CONF.load_balancer.check_timeout) |
| 151 |
|
| 152 |
|
| 153 |
member2_name = data_utils.rand_name("lb_member_member2_actstdby") |
| 154 |
member2_kwargs = { |
| 155 |
const.POOL_ID: cls.pool_id, |
| 156 |
const.NAME: member2_name, |
| 157 |
const.ADMIN_STATE_UP: True, |
| 158 |
const.ADDRESS: cls.webserver2_ip, |
| 159 |
const.PROTOCOL_PORT: 80, |
| 160 |
} |
| 161 |
if cls.lb_member_2_subnet: |
| 162 |
member2_kwargs[const.SUBNET_ID] = cls.lb_member_2_subnet[const.ID] |
| 163 |
|
| 164 |
member2 = cls.mem_member_client.create_member( |
| 165 |
**member2_kwargs) |
| 166 |
cls.addClassResourceCleanup( |
| 167 |
cls.mem_member_client.cleanup_member, |
| 168 |
member2[const.ID], pool_id=cls.pool_id, |
| 169 |
lb_client=cls.mem_lb_client, lb_id=cls.lb_id) |
| 170 |
waiters.wait_for_status( |
| 171 |
cls.mem_lb_client.show_loadbalancer, cls.lb_id, |
| 172 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 173 |
CONF.load_balancer.check_interval, |
| 174 |
CONF.load_balancer.check_timeout) |
| 175 |
|
| 176 |
@testtools.skipIf(CONF.load_balancer.test_with_noop, |
| 177 |
'Active/Standby tests will not work in noop mode.') |
| 178 |
@decorators.idempotent_id('e591fa7a-0eee-485a-8ca0-5cf1a556bdf0') |
| 179 |
def test_active_standby_vrrp_failover(self): |
| 180 |
"""Tests active/standby VRRP failover |
| 181 |
|
| 182 |
* Test the load balancer to make sure it is functioning |
| 183 |
* Identifies the Master and Backup amphora |
| 184 |
* Deletes the Master amphora |
| 185 |
* Sends traffic through the load balancer |
| 186 |
* Validates that the Backup has assumed the Master role |
| 187 |
""" |
| 188 |
amphora_client = self.os_admin.load_balancer_v2.AmphoraClient() |
| 189 |
|
| 190 |
|
| 191 |
if not self.mem_listener_client.is_version_supported( |
| 192 |
self.api_version, '2.4'): |
| 193 |
raise self.skipException( |
| 194 |
'Active/Standby VRRP failover tests require ' |
| 195 |
'Octavia API version 2.3 or newer.') |
| 196 |
|
| 197 |
session = requests.Session() |
| 198 |
|
| 199 |
|
| 200 |
self.check_members_balanced(self.lb_vip_address) |
| 201 |
|
| 202 |
|
| 203 |
amphorae = amphora_client.list_amphorae( |
| 204 |
query_params='{loadbalancer_id}={lb_id}'.format( |
| 205 |
loadbalancer_id=const.LOADBALANCER_ID, |
| 206 |
lb_id=self.lb_id)) |
| 207 |
|
| 208 |
|
| 209 |
if len(amphorae) < 2: |
| 210 |
self.skipTest('Load balancer must be using active/standby ' |
| 211 |
'topology for the VRRP failover test.') |
| 212 |
|
| 213 |
|
| 214 |
r = session.get('http://{0}'.format(self.lb_vip_address), timeout=2) |
| 215 |
|
| 216 |
|
| 217 |
master_amp = None |
| 218 |
backup_amp = None |
| 219 |
start = int(time.time()) |
| 220 |
while True: |
| 221 |
for amp in amphorae: |
| 222 |
amphora_stats = amphora_client.get_amphora_stats( |
| 223 |
amp[const.ID]) |
| 224 |
for listener in amphora_stats: |
| 225 |
if listener[const.TOTAL_CONNECTIONS] > 0: |
| 226 |
master_amp = amp |
| 227 |
break |
| 228 |
|
| 229 |
if master_amp: |
| 230 |
break |
| 231 |
|
| 232 |
|
| 233 |
if master_amp: |
| 234 |
break |
| 235 |
if int(time.time()) - start >= CONF.load_balancer.check_timeout: |
| 236 |
message = ('Unable to find Master amphora in {timeout} ' |
| 237 |
'seconds.'.format( |
| 238 |
timeout=CONF.load_balancer.check_timeout)) |
| 239 |
raise exceptions.TimeoutException(message) |
| 240 |
time.sleep(CONF.load_balancer.check_interval) |
| 241 |
|
| 242 |
|
| 243 |
for amp in amphorae: |
| 244 |
if amp[const.ID] == master_amp[const.ID]: |
| 245 |
continue |
| 246 |
else: |
| 247 |
backup_amp = amp |
| 248 |
self.assertIsNotNone(backup_amp) |
| 249 |
amphora_stats = amphora_client.get_amphora_stats( |
| 250 |
backup_amp[const.ID]) |
| 251 |
for listener in amphora_stats: |
| 252 |
self.assertEqual(0, listener[const.TOTAL_CONNECTIONS]) |
| 253 |
|
| 254 |
|
| 255 |
self.os_admin_servers_client.delete_server( |
| 256 |
master_amp[const.COMPUTE_ID]) |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
for x in range(0, 20): |
| 262 |
try: |
| 263 |
r = session.get('http://{0}'.format(self.lb_vip_address), |
| 264 |
timeout=1) |
| 265 |
LOG.info('Got response: %s', r.text) |
| 266 |
except Exception: |
| 267 |
LOG.info('Load balancer request failed. Looping') |
| 268 |
time.sleep(1) |
| 269 |
|
| 270 |
|
| 271 |
amphora_stats = amphora_client.get_amphora_stats( |
| 272 |
backup_amp[const.ID]) |
| 273 |
connections = 0 |
| 274 |
for listener in amphora_stats: |
| 275 |
connections += listener[const.TOTAL_CONNECTIONS] |
| 276 |
self.assertGreater(connections, 0) |
| 277 |
LOG.info('Backup amphora is now Master.') |
| 278 |
|
| 279 |
waiters.wait_for_status( |
| 280 |
self.mem_lb_client.show_loadbalancer, |
| 281 |
self.lb_id, const.PROVISIONING_STATUS, |
| 282 |
const.PENDING_UPDATE, CONF.load_balancer.check_interval, |
| 283 |
CONF.load_balancer.check_timeout) |
| 284 |
|
| 285 |
|
| 286 |
waiters.wait_for_status( |
| 287 |
self.mem_lb_client.show_loadbalancer, |
| 288 |
self.lb_id, const.PROVISIONING_STATUS, |
| 289 |
const.ACTIVE, CONF.load_balancer.lb_build_interval, |
| 290 |
CONF.load_balancer.lb_build_timeout) |