Debian Codegraph @

octavia_tempest_plugin/tests/spare_pool_scenario/v2/test_spare_pool.py

raw symbols SCIP
1 # Copyright 2019 Red Hat 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 from oslo_log import log as logging
16 from tempest import config
17 from tempest.lib.common.utils import data_utils
18 from tempest.lib import decorators
19
20 from octavia_tempest_plugin.common import constants as const
21 from octavia_tempest_plugin.tests import test_base
22 from octavia_tempest_plugin.tests import waiters
23
24 CONF = config.CONF
25 LOG = logging.getLogger(__name__)
26
27
28 class SparePoolTest(test_base.LoadBalancerBaseTestWithCompute):
29
30 @classmethod
31 def skip_checks(cls):
32 super(SparePoolTest, cls).skip_checks()
33
34 if CONF.load_balancer.provider not in const.AMPHORA_PROVIDERS:
35 raise cls.skipException("Amphora tests require provider 'amphora' "
36 "or 'octavia' (alias to 'amphora', "
37 "deprecated) set")
38 if not CONF.loadbalancer_feature_enabled.spare_pool_enabled:
39 raise cls.skipException('[loadbalancer-feature-enabled] '
40 '"spare_pool_enabled" is set to False in '
41 'the Tempest configuration. Spare pool '
42 'tests will be skipped.')
43
44 @classmethod
45 def resource_setup(cls):
46 """Setup resources needed by the tests"""
47 super(SparePoolTest, cls).resource_setup()
48
49 @decorators.idempotent_id('2ba3a2c2-de9d-4556-9535-cbe9209b4eaa')
50 def test_health_manager_failover_to_spare_amp(self):
51 """Tests Health Manager failover to amphora in spare pool.
52
53 * Check amphora spare pool availability
54 * Test the load balancer to make sure it is functioning
55 * Delete amphora compute instance associated to load balancer
56 * Validate load balancer fails over to spare amphora
57 * Send traffic through load balancer
58 * Validate amphora spare pool size is restored
59 """
60 amphora_client = self.os_admin.load_balancer_v2.AmphoraClient()
61 # Check there is at least one amphora in spare pool
62 spare_amps = waiters.wait_for_spare_amps(
63 amphora_client.list_amphorae,
64 CONF.load_balancer.lb_build_interval,
65 CONF.load_balancer.lb_build_timeout)
66
67 # Setup a load balancer for the tests to use
68 lb_name = data_utils.rand_name("lb_spare_pool")
69 lb_kwargs = {const.PROVIDER: CONF.load_balancer.provider,
70 const.NAME: lb_name}
71
72 self._setup_lb_network_kwargs(lb_kwargs, 4)
73
74 lb = self.mem_lb_client.create_loadbalancer(**lb_kwargs)
75 self.lb_id = lb[const.ID]
76 self.addClassResourceCleanup(self.mem_lb_client.cleanup_loadbalancer,
77 self.lb_id, cascade=True)
78
79 if CONF.validation.connect_method == 'floating':
80 port_id = lb[const.VIP_PORT_ID]
81 result = self.lb_mem_float_ip_client.create_floatingip(
82 floating_network_id=CONF.network.public_network_id,
83 port_id=port_id)
84 floating_ip = result['floatingip']
85 LOG.info('lb1_floating_ip: %s', floating_ip)
86 self.addClassResourceCleanup(
87 waiters.wait_for_not_found,
88 self.lb_mem_float_ip_client.delete_floatingip,
89 self.lb_mem_float_ip_client.show_floatingip,
90 floatingip_id=floating_ip['id'])
91 self.lb_vip_address = floating_ip['floating_ip_address']
92 else:
93 self.lb_vip_address = lb[const.VIP_ADDRESS]
94
95 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
96 self.lb_id, const.PROVISIONING_STATUS,
97 const.ACTIVE,
98 CONF.load_balancer.lb_build_interval,
99 CONF.load_balancer.lb_build_timeout)
100
101 # Confirm the spare pool has changed since last check
102 spare_amps_2 = waiters.wait_for_spare_amps(
103 amphora_client.list_amphorae,
104 CONF.load_balancer.lb_build_interval,
105 CONF.load_balancer.lb_build_timeout)
106 self.assertNotEqual(spare_amps, spare_amps_2)
107
108 listener_name = data_utils.rand_name("lb_member_listener1_spare")
109 listener_kwargs = {
110 const.NAME: listener_name,
111 const.PROTOCOL: const.HTTP,
112 const.PROTOCOL_PORT: '80',
113 const.LOADBALANCER_ID: self.lb_id,
114 }
115 listener = self.mem_listener_client.create_listener(**listener_kwargs)
116 self.listener_id = listener[const.ID]
117
118 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
119 self.lb_id, const.PROVISIONING_STATUS,
120 const.ACTIVE,
121 CONF.load_balancer.build_interval,
122 CONF.load_balancer.build_timeout)
123
124 pool_name = data_utils.rand_name("lb_member_pool1-spare")
125 pool_kwargs = {
126 const.NAME: pool_name,
127 const.PROTOCOL: const.HTTP,
128 const.LB_ALGORITHM: self.lb_algorithm,
129 const.LISTENER_ID: self.listener_id,
130 }
131 pool = self.mem_pool_client.create_pool(**pool_kwargs)
132 self.pool_id = pool[const.ID]
133
134 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
135 self.lb_id, const.PROVISIONING_STATUS,
136 const.ACTIVE,
137 CONF.load_balancer.build_interval,
138 CONF.load_balancer.build_timeout)
139
140 # Set up Member 1 for Webserver 1
141 member1_name = data_utils.rand_name("lb_member_member1-spare")
142 member1_kwargs = {
143 const.POOL_ID: self.pool_id,
144 const.NAME: member1_name,
145 const.ADMIN_STATE_UP: True,
146 const.ADDRESS: self.webserver1_ip,
147 const.PROTOCOL_PORT: 80,
148 }
149 if self.lb_member_1_subnet:
150 member1_kwargs[const.SUBNET_ID] = self.lb_member_1_subnet[const.ID]
151
152 self.mem_member_client.create_member(**member1_kwargs)
153 waiters.wait_for_status(
154 self.mem_lb_client.show_loadbalancer, self.lb_id,
155 const.PROVISIONING_STATUS, const.ACTIVE,
156 CONF.load_balancer.check_interval,
157 CONF.load_balancer.check_timeout)
158
159 # Set up Member 2 for Webserver 2
160 member2_name = data_utils.rand_name("lb_member_member2-spare")
161 member2_kwargs = {
162 const.POOL_ID: self.pool_id,
163 const.NAME: member2_name,
164 const.ADMIN_STATE_UP: True,
165 const.ADDRESS: self.webserver2_ip,
166 const.PROTOCOL_PORT: 80,
167 }
168 if self.lb_member_2_subnet:
169 member2_kwargs[const.SUBNET_ID] = self.lb_member_2_subnet[const.ID]
170
171 self.mem_member_client.create_member(**member2_kwargs)
172 waiters.wait_for_status(
173 self.mem_lb_client.show_loadbalancer, self.lb_id,
174 const.PROVISIONING_STATUS, const.ACTIVE,
175 CONF.load_balancer.check_interval,
176 CONF.load_balancer.check_timeout)
177
178 # Send some traffic
179 self.check_members_balanced(self.lb_vip_address)
180
181 # Check there is at least one amphora in spare pool
182 spare_amps = waiters.wait_for_spare_amps(
183 amphora_client.list_amphorae,
184 CONF.load_balancer.lb_build_interval,
185 CONF.load_balancer.lb_build_timeout)
186
187 # Delete amphora compute instance
188 amp = amphora_client.list_amphorae(
189 query_params='{loadbalancer_id}={lb_id}'.format(
190 loadbalancer_id=const.LOADBALANCER_ID, lb_id=self.lb_id))
191
192 self.os_admin_servers_client.delete_server(amp[0][const.COMPUTE_ID])
193
194 # Wait for the amphora failover to start
195 waiters.wait_for_status(
196 self.mem_lb_client.show_loadbalancer,
197 self.lb_id, const.PROVISIONING_STATUS,
198 const.PENDING_UPDATE, CONF.load_balancer.check_interval,
199 CONF.load_balancer.check_timeout)
200
201 # Wait for the load balancer to return to ACTIVE so the
202 # cleanup steps will pass
203 waiters.wait_for_status(
204 self.mem_lb_client.show_loadbalancer,
205 self.lb_id, const.PROVISIONING_STATUS,
206 const.ACTIVE, CONF.load_balancer.lb_build_interval,
207 CONF.load_balancer.lb_build_timeout)
208
209 # Send some traffic
210 self.check_members_balanced(self.lb_vip_address)
211
212 # Confirm the spare pool has changed since last check
213 spare_amps_2 = waiters.wait_for_spare_amps(
214 amphora_client.list_amphorae,
215 CONF.load_balancer.lb_build_interval,
216 CONF.load_balancer.lb_build_timeout)
217 self.assertNotEqual(spare_amps, spare_amps_2)
218
219 # Check there is at least one amphora in spare pool
220 waiters.wait_for_spare_amps(amphora_client.list_amphorae,
221 CONF.load_balancer.lb_build_interval,
222 CONF.load_balancer.lb_build_timeout)