blob: e85fb0a090f887f31eab9c30ac65b46c99c1feca [file] [log] [blame]
Jude Cross986e3f52017-07-24 14:57:20 -07001# Copyright 2018 Rackspace US 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
15import ipaddress
16import pkg_resources
17import random
Adam Harwellcd72b562018-05-07 11:37:22 -070018import requests
Jude Cross986e3f52017-07-24 14:57:20 -070019import shlex
20import six
21import string
22import subprocess
23import tempfile
Adam Harwellcd72b562018-05-07 11:37:22 -070024import time
Jude Cross986e3f52017-07-24 14:57:20 -070025
26from oslo_log import log as logging
27from oslo_utils import uuidutils
28from tempest import config
29from tempest.lib.common.utils import data_utils
30from tempest.lib.common.utils.linux import remote_client
Jude Cross986e3f52017-07-24 14:57:20 -070031from tempest.lib import exceptions
32from tempest import test
Michael Johnson04dc5cb2019-01-20 11:03:50 -080033import tenacity
Jude Cross986e3f52017-07-24 14:57:20 -070034
35from octavia_tempest_plugin import clients
36from octavia_tempest_plugin.common import constants as const
37from octavia_tempest_plugin.tests import validators
38from octavia_tempest_plugin.tests import waiters
39
40CONF = config.CONF
41LOG = logging.getLogger(__name__)
42
Michael Johnson04dc5cb2019-01-20 11:03:50 -080043RETRY_ATTEMPTS = 15
44RETRY_INITIAL_DELAY = 1
45RETRY_BACKOFF = 1
46RETRY_MAX = 5
47
Jude Cross986e3f52017-07-24 14:57:20 -070048
49class LoadBalancerBaseTest(test.BaseTestCase):
50 """Base class for load balancer tests."""
51
52 # Setup cls.os_roles_lb_member. cls.os_primary, cls.os_roles_lb_member,
53 # and cls.os_roles_lb_admin credentials.
54 credentials = ['admin', 'primary',
55 ['lb_member', CONF.load_balancer.member_role],
56 ['lb_member2', CONF.load_balancer.member_role],
57 ['lb_admin', CONF.load_balancer.admin_role]]
58
59 client_manager = clients.ManagerV2
Adam Harwelle029af22018-05-24 17:13:28 -070060 webserver1_response = 1
61 webserver2_response = 5
Michael Johnsondfd818a2018-08-21 20:54:54 -070062 used_ips = []
Jude Cross986e3f52017-07-24 14:57:20 -070063
64 @classmethod
65 def skip_checks(cls):
66 """Check if we should skip all of the children tests."""
67 super(LoadBalancerBaseTest, cls).skip_checks()
68
69 service_list = {
70 'load_balancer': CONF.service_available.load_balancer,
71 }
72
73 live_service_list = {
74 'compute': CONF.service_available.nova,
75 'image': CONF.service_available.glance,
76 'neutron': CONF.service_available.neutron
77 }
78
79 if not CONF.load_balancer.test_with_noop:
80 service_list.update(live_service_list)
81
82 for service, available in service_list.items():
83 if not available:
zhangzs2a6cf672018-11-10 16:13:11 +080084 skip_msg = ("{0} skipped as {1} service is not "
Jude Cross986e3f52017-07-24 14:57:20 -070085 "available.".format(cls.__name__, service))
86 raise cls.skipException(skip_msg)
87
88 # We must be able to reach our VIP and instances
89 if not (CONF.network.project_networks_reachable
90 or CONF.network.public_network_id):
91 msg = ('Either project_networks_reachable must be "true", or '
92 'public_network_id must be defined.')
93 raise cls.skipException(msg)
94
95 @classmethod
96 def setup_credentials(cls):
97 """Setup test credentials and network resources."""
98 # Do not auto create network resources
99 cls.set_network_resources()
100 super(LoadBalancerBaseTest, cls).setup_credentials()
101
102 @classmethod
103 def setup_clients(cls):
104 """Setup client aliases."""
105 super(LoadBalancerBaseTest, cls).setup_clients()
106 cls.lb_mem_float_ip_client = cls.os_roles_lb_member.floating_ips_client
107 cls.lb_mem_keypairs_client = cls.os_roles_lb_member.keypairs_client
108 cls.lb_mem_net_client = cls.os_roles_lb_member.networks_client
109 cls.lb_mem_ports_client = cls.os_roles_lb_member.ports_client
110 cls.lb_mem_routers_client = cls.os_roles_lb_member.routers_client
111 cls.lb_mem_SG_client = cls.os_roles_lb_member.security_groups_client
112 cls.lb_mem_SGr_client = (
113 cls.os_roles_lb_member.security_group_rules_client)
114 cls.lb_mem_servers_client = cls.os_roles_lb_member.servers_client
115 cls.lb_mem_subnet_client = cls.os_roles_lb_member.subnets_client
116 cls.mem_lb_client = cls.os_roles_lb_member.loadbalancer_client
Jude Crossfbbd2b42017-08-09 15:21:04 -0700117 cls.mem_listener_client = cls.os_roles_lb_member.listener_client
Adam Harwell8ffce3e2018-05-01 21:18:44 -0700118 cls.mem_pool_client = cls.os_roles_lb_member.pool_client
Adam Harwellde3e0542018-05-03 18:21:06 -0700119 cls.mem_member_client = cls.os_roles_lb_member.member_client
Adam Harwell60ed9d92018-05-10 13:23:13 -0700120 cls.mem_healthmonitor_client = (
121 cls.os_roles_lb_member.healthmonitor_client)
Adam Harwell446f8be2018-05-24 16:51:03 -0700122 cls.mem_l7policy_client = cls.os_roles_lb_member.l7policy_client
Adam Harwelle029af22018-05-24 17:13:28 -0700123 cls.mem_l7rule_client = cls.os_roles_lb_member.l7rule_client
Adam Harwelldfc11ee2018-05-30 09:38:55 -0700124 cls.mem_amphora_client = cls.os_roles_lb_member.amphora_client
Michael Johnsonaff2e862019-01-11 16:38:00 -0800125 cls.lb_admin_flavor_profile_client = (
126 cls.os_roles_lb_admin.flavor_profile_client)
Michael Johnsona2d03072019-01-14 17:18:21 -0800127 cls.lb_admin_flavor_client = cls.os_roles_lb_admin.flavor_client
128 cls.mem_flavor_client = cls.os_roles_lb_member.flavor_client
Michael Johnsonfc223fe2019-01-15 16:40:05 -0800129 cls.mem_provider_client = cls.os_roles_lb_member.provider_client
Carlos Goncalvesc2e12162019-02-14 23:57:44 +0100130 cls.os_admin_servers_client = cls.os_admin.servers_client
Jude Cross986e3f52017-07-24 14:57:20 -0700131
132 @classmethod
133 def resource_setup(cls):
134 """Setup resources needed by the tests."""
135 super(LoadBalancerBaseTest, cls).resource_setup()
136
137 conf_lb = CONF.load_balancer
138
Michael Johnsondfd818a2018-08-21 20:54:54 -0700139 cls.api_version = cls.mem_lb_client.get_max_api_version()
140
Jude Cross986e3f52017-07-24 14:57:20 -0700141 if conf_lb.test_subnet_override and not conf_lb.test_network_override:
142 raise exceptions.InvalidConfiguration(
143 "Configuration value test_network_override must be "
144 "specified if test_subnet_override is used.")
145
146 show_subnet = cls.lb_mem_subnet_client.show_subnet
147 if CONF.load_balancer.test_with_noop:
148 cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()}
149 cls.lb_member_vip_subnet = {'id': uuidutils.generate_uuid()}
150 cls.lb_member_1_net = {'id': uuidutils.generate_uuid()}
151 cls.lb_member_1_subnet = {'id': uuidutils.generate_uuid()}
152 cls.lb_member_2_net = {'id': uuidutils.generate_uuid()}
153 cls.lb_member_2_subnet = {'id': uuidutils.generate_uuid()}
154 if CONF.load_balancer.test_with_ipv6:
Michael Johnson5a16ad32018-10-18 14:49:11 -0700155 cls.lb_member_vip_ipv6_net = {'id': uuidutils.generate_uuid()}
Jude Cross986e3f52017-07-24 14:57:20 -0700156 cls.lb_member_vip_ipv6_subnet = {'id':
157 uuidutils.generate_uuid()}
158 cls.lb_member_1_ipv6_subnet = {'id': uuidutils.generate_uuid()}
159 cls.lb_member_2_ipv6_subnet = {'id': uuidutils.generate_uuid()}
Michael Johnson590fbe12019-07-03 14:30:01 -0700160 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700161 return
162 elif CONF.load_balancer.test_network_override:
163 if conf_lb.test_subnet_override:
164 override_subnet = show_subnet(conf_lb.test_subnet_override)
165 else:
166 override_subnet = None
167
168 show_net = cls.lb_mem_net_client.show_network
169 override_network = show_net(conf_lb.test_network_override)
170 override_network = override_network.get('network')
171
172 cls.lb_member_vip_net = override_network
173 cls.lb_member_vip_subnet = override_subnet
174 cls.lb_member_1_net = override_network
175 cls.lb_member_1_subnet = override_subnet
176 cls.lb_member_2_net = override_network
177 cls.lb_member_2_subnet = override_subnet
178
179 if (CONF.load_balancer.test_with_ipv6 and
180 conf_lb.test_IPv6_subnet_override):
181 override_ipv6_subnet = show_subnet(
182 conf_lb.test_IPv6_subnet_override)
183 cls.lb_member_vip_ipv6_subnet = override_ipv6_subnet
184 cls.lb_member_1_ipv6_subnet = override_ipv6_subnet
185 cls.lb_member_2_ipv6_subnet = override_ipv6_subnet
Michael Johnson590fbe12019-07-03 14:30:01 -0700186 cls.lb_member_vip_ipv6_subnet_stateful = False
187 if (override_ipv6_subnet[0]['ipv6_address_mode'] ==
188 'dhcpv6-stateful'):
189 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700190 else:
191 cls.lb_member_vip_ipv6_subnet = None
192 cls.lb_member_1_ipv6_subnet = None
193 cls.lb_member_2_ipv6_subnet = None
194 else:
195 cls._create_networks()
196
197 LOG.debug('Octavia Setup: lb_member_vip_net = {}'.format(
198 cls.lb_member_vip_net[const.ID]))
199 if cls.lb_member_vip_subnet:
200 LOG.debug('Octavia Setup: lb_member_vip_subnet = {}'.format(
201 cls.lb_member_vip_subnet[const.ID]))
202 LOG.debug('Octavia Setup: lb_member_1_net = {}'.format(
203 cls.lb_member_1_net[const.ID]))
204 if cls.lb_member_1_subnet:
205 LOG.debug('Octavia Setup: lb_member_1_subnet = {}'.format(
206 cls.lb_member_1_subnet[const.ID]))
207 LOG.debug('Octavia Setup: lb_member_2_net = {}'.format(
208 cls.lb_member_2_net[const.ID]))
209 if cls.lb_member_2_subnet:
210 LOG.debug('Octavia Setup: lb_member_2_subnet = {}'.format(
211 cls.lb_member_2_subnet[const.ID]))
Michael Johnson124ba8b2018-08-30 16:06:05 -0700212 if CONF.load_balancer.test_with_ipv6:
213 if cls.lb_member_vip_ipv6_subnet:
214 LOG.debug('Octavia Setup: lb_member_vip_ipv6_subnet = '
215 '{}'.format(cls.lb_member_vip_ipv6_subnet[const.ID]))
216 if cls.lb_member_1_ipv6_subnet:
217 LOG.debug('Octavia Setup: lb_member_1_ipv6_subnet = {}'.format(
218 cls.lb_member_1_ipv6_subnet[const.ID]))
219 if cls.lb_member_2_ipv6_subnet:
220 LOG.debug('Octavia Setup: lb_member_2_ipv6_subnet = {}'.format(
221 cls.lb_member_2_ipv6_subnet[const.ID]))
Jude Cross986e3f52017-07-24 14:57:20 -0700222
Jude Cross986e3f52017-07-24 14:57:20 -0700223 @classmethod
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800224 # Neutron can be slow to clean up ports from the subnets/networks.
225 # Retry this delete a few times if we get a "Conflict" error to give
226 # neutron time to fully cleanup the ports.
227 @tenacity.retry(
228 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
229 wait=tenacity.wait_incrementing(
230 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
231 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
232 def _logging_delete_network(cls, net_id):
233 try:
234 cls.lb_mem_net_client.delete_network(net_id)
235 except Exception:
236 LOG.error('Unable to delete network {}. Active ports:'.format(
237 net_id))
238 LOG.error(cls.lb_mem_ports_client.list_ports())
239 raise
240
241 @classmethod
242 # Neutron can be slow to clean up ports from the subnets/networks.
243 # Retry this delete a few times if we get a "Conflict" error to give
244 # neutron time to fully cleanup the ports.
245 @tenacity.retry(
246 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
247 wait=tenacity.wait_incrementing(
248 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
249 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
250 def _logging_delete_subnet(cls, subnet_id):
251 try:
252 cls.lb_mem_subnet_client.delete_subnet(subnet_id)
253 except Exception:
254 LOG.error('Unable to delete subnet {}. Active ports:'.format(
255 subnet_id))
256 LOG.error(cls.lb_mem_ports_client.list_ports())
257 raise
258
259 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -0700260 def _create_networks(cls):
261 """Creates networks, subnets, and routers used in tests.
262
263 The following are expected to be defined and available to the tests:
264 cls.lb_member_vip_net
265 cls.lb_member_vip_subnet
266 cls.lb_member_vip_ipv6_subnet (optional)
267 cls.lb_member_1_net
268 cls.lb_member_1_subnet
269 cls.lb_member_1_ipv6_subnet (optional)
270 cls.lb_member_2_net
271 cls.lb_member_2_subnet
272 cls.lb_member_2_ipv6_subnet (optional)
273 """
274
275 # Create tenant VIP network
276 network_kwargs = {
277 'name': data_utils.rand_name("lb_member_vip_network")}
278 if CONF.network_feature_enabled.port_security:
279 # Note: Allowed Address Pairs requires port security
280 network_kwargs['port_security_enabled'] = True
281 result = cls.lb_mem_net_client.create_network(**network_kwargs)
282 cls.lb_member_vip_net = result['network']
283 LOG.info('lb_member_vip_net: {}'.format(cls.lb_member_vip_net))
284 cls.addClassResourceCleanup(
285 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800286 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700287 cls.lb_mem_net_client.show_network,
288 cls.lb_member_vip_net['id'])
289
290 # Create tenant VIP subnet
291 subnet_kwargs = {
292 'name': data_utils.rand_name("lb_member_vip_subnet"),
293 'network_id': cls.lb_member_vip_net['id'],
294 'cidr': CONF.load_balancer.vip_subnet_cidr,
295 'ip_version': 4}
296 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
297 cls.lb_member_vip_subnet = result['subnet']
298 LOG.info('lb_member_vip_subnet: {}'.format(cls.lb_member_vip_subnet))
299 cls.addClassResourceCleanup(
300 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800301 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700302 cls.lb_mem_subnet_client.show_subnet,
303 cls.lb_member_vip_subnet['id'])
304
305 # Create tenant VIP IPv6 subnet
306 if CONF.load_balancer.test_with_ipv6:
Adam Harwell2b9432f2019-05-02 13:56:09 -0600307 # See if ipv6-private-subnet exists and use it if so.
308 priv_ipv6_subnet = cls.os_admin.subnets_client.list_subnets(
309 name='ipv6-private-subnet')['subnets']
Michael Johnson5a16ad32018-10-18 14:49:11 -0700310
Michael Johnson590fbe12019-07-03 14:30:01 -0700311 cls.lb_member_vip_ipv6_subnet_stateful = False
312 if (priv_ipv6_subnet[0]['ipv6_address_mode'] ==
313 'dhcpv6-stateful'):
314 cls.lb_member_vip_ipv6_subnet_stateful = True
Adam Harwell2b9432f2019-05-02 13:56:09 -0600315 if len(priv_ipv6_subnet) == 1:
316 cls.lb_member_vip_ipv6_subnet = priv_ipv6_subnet[0]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700317 cls.lb_member_vip_ipv6_net = {
Adam Harwell2b9432f2019-05-02 13:56:09 -0600318 'id': priv_ipv6_subnet[0]['network_id']}
Michael Johnson5a16ad32018-10-18 14:49:11 -0700319 else:
320 subnet_kwargs = {
321 'name': data_utils.rand_name("lb_member_vip_ipv6_subnet"),
322 'network_id': cls.lb_member_vip_net['id'],
323 'cidr': CONF.load_balancer.vip_ipv6_subnet_cidr,
324 'ip_version': 6}
325 result = cls.lb_mem_subnet_client.create_subnet(
326 **subnet_kwargs)
Michael Johnson7c5b9012019-05-28 11:02:29 -0700327 cls.lb_member_vip_ipv6_net = cls.lb_member_vip_net
Michael Johnson5a16ad32018-10-18 14:49:11 -0700328 cls.lb_member_vip_ipv6_subnet = result['subnet']
329 cls.addClassResourceCleanup(
330 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800331 cls._logging_delete_subnet,
Michael Johnson5a16ad32018-10-18 14:49:11 -0700332 cls.lb_mem_subnet_client.show_subnet,
333 cls.lb_member_vip_ipv6_subnet['id'])
Jude Cross986e3f52017-07-24 14:57:20 -0700334 LOG.info('lb_member_vip_ipv6_subnet: {}'.format(
335 cls.lb_member_vip_ipv6_subnet))
Jude Cross986e3f52017-07-24 14:57:20 -0700336
337 # Create tenant member 1 network
338 network_kwargs = {
339 'name': data_utils.rand_name("lb_member_1_network")}
340 if CONF.network_feature_enabled.port_security:
341 if CONF.load_balancer.enable_security_groups:
342 network_kwargs['port_security_enabled'] = True
343 else:
344 network_kwargs['port_security_enabled'] = False
345 result = cls.lb_mem_net_client.create_network(**network_kwargs)
346 cls.lb_member_1_net = result['network']
347 LOG.info('lb_member_1_net: {}'.format(cls.lb_member_1_net))
348 cls.addClassResourceCleanup(
349 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800350 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700351 cls.lb_mem_net_client.show_network,
352 cls.lb_member_1_net['id'])
353
354 # Create tenant member 1 subnet
355 subnet_kwargs = {
356 'name': data_utils.rand_name("lb_member_1_subnet"),
357 'network_id': cls.lb_member_1_net['id'],
358 'cidr': CONF.load_balancer.member_1_ipv4_subnet_cidr,
359 'ip_version': 4}
360 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
361 cls.lb_member_1_subnet = result['subnet']
362 LOG.info('lb_member_1_subnet: {}'.format(cls.lb_member_1_subnet))
363 cls.addClassResourceCleanup(
364 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800365 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700366 cls.lb_mem_subnet_client.show_subnet,
367 cls.lb_member_1_subnet['id'])
368
369 # Create tenant member 1 ipv6 subnet
370 if CONF.load_balancer.test_with_ipv6:
371 subnet_kwargs = {
372 'name': data_utils.rand_name("lb_member_1_ipv6_subnet"),
373 'network_id': cls.lb_member_1_net['id'],
374 'cidr': CONF.load_balancer.member_1_ipv6_subnet_cidr,
375 'ip_version': 6}
376 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700377 cls.lb_member_1_subnet_prefix = (
378 CONF.load_balancer.member_1_ipv6_subnet_cidr.rpartition('/')[2]
379 )
380 assert(cls.lb_member_1_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700381 cls.lb_member_1_ipv6_subnet = result['subnet']
382 LOG.info('lb_member_1_ipv6_subnet: {}'.format(
383 cls.lb_member_1_ipv6_subnet))
384 cls.addClassResourceCleanup(
385 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800386 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700387 cls.lb_mem_subnet_client.show_subnet,
388 cls.lb_member_1_ipv6_subnet['id'])
389
390 # Create tenant member 2 network
391 network_kwargs = {
392 'name': data_utils.rand_name("lb_member_2_network")}
393 if CONF.network_feature_enabled.port_security:
394 if CONF.load_balancer.enable_security_groups:
395 network_kwargs['port_security_enabled'] = True
396 else:
397 network_kwargs['port_security_enabled'] = False
398 result = cls.lb_mem_net_client.create_network(**network_kwargs)
399 cls.lb_member_2_net = result['network']
400 LOG.info('lb_member_2_net: {}'.format(cls.lb_member_2_net))
401 cls.addClassResourceCleanup(
402 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800403 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700404 cls.lb_mem_net_client.show_network,
405 cls.lb_member_2_net['id'])
406
407 # Create tenant member 2 subnet
408 subnet_kwargs = {
409 'name': data_utils.rand_name("lb_member_2_subnet"),
410 'network_id': cls.lb_member_2_net['id'],
411 'cidr': CONF.load_balancer.member_2_ipv4_subnet_cidr,
412 'ip_version': 4}
413 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
414 cls.lb_member_2_subnet = result['subnet']
415 LOG.info('lb_member_2_subnet: {}'.format(cls.lb_member_2_subnet))
416 cls.addClassResourceCleanup(
417 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800418 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700419 cls.lb_mem_subnet_client.show_subnet,
420 cls.lb_member_2_subnet['id'])
421
422 # Create tenant member 2 ipv6 subnet
423 if CONF.load_balancer.test_with_ipv6:
424 subnet_kwargs = {
425 'name': data_utils.rand_name("lb_member_2_ipv6_subnet"),
426 'network_id': cls.lb_member_2_net['id'],
427 'cidr': CONF.load_balancer.member_2_ipv6_subnet_cidr,
428 'ip_version': 6}
429 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700430 cls.lb_member_2_subnet_prefix = (
431 CONF.load_balancer.member_2_ipv6_subnet_cidr.rpartition('/')[2]
432 )
433 assert(cls.lb_member_2_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700434 cls.lb_member_2_ipv6_subnet = result['subnet']
435 LOG.info('lb_member_2_ipv6_subnet: {}'.format(
436 cls.lb_member_2_ipv6_subnet))
437 cls.addClassResourceCleanup(
438 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800439 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700440 cls.lb_mem_subnet_client.show_subnet,
441 cls.lb_member_2_ipv6_subnet['id'])
442
Adam Harwellcd72b562018-05-07 11:37:22 -0700443 @classmethod
Michael Johnson07c9a632018-06-07 13:27:42 -0700444 def _setup_lb_network_kwargs(cls, lb_kwargs, ip_version=None,
445 use_fixed_ip=False):
Adam Harwell60ed9d92018-05-10 13:23:13 -0700446 if not ip_version:
447 ip_version = 6 if CONF.load_balancer.test_with_ipv6 else 4
Michael Johnson5a16ad32018-10-18 14:49:11 -0700448 if cls.lb_member_vip_subnet or cls.lb_member_vip_ipv6_subnet:
Adam Harwellcd72b562018-05-07 11:37:22 -0700449 ip_index = data_utils.rand_int_id(start=10, end=100)
Michael Johnsondfd818a2018-08-21 20:54:54 -0700450 while ip_index in cls.used_ips:
451 ip_index = data_utils.rand_int_id(start=10, end=100)
452 cls.used_ips.append(ip_index)
Adam Harwellcd72b562018-05-07 11:37:22 -0700453 if ip_version == 4:
Adam Harwellcd72b562018-05-07 11:37:22 -0700454 subnet_id = cls.lb_member_vip_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700455 if CONF.load_balancer.test_with_noop:
456 lb_vip_address = '198.18.33.33'
457 else:
458 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
459 network = ipaddress.IPv4Network(subnet['subnet']['cidr'])
460 lb_vip_address = str(network[ip_index])
Adam Harwellcd72b562018-05-07 11:37:22 -0700461 else:
Adam Harwellcd72b562018-05-07 11:37:22 -0700462 subnet_id = cls.lb_member_vip_ipv6_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700463 if CONF.load_balancer.test_with_noop:
464 lb_vip_address = '2001:db8:33:33:33:33:33:33'
465 else:
466 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
467 network = ipaddress.IPv6Network(subnet['subnet']['cidr'])
468 lb_vip_address = str(network[ip_index])
Michael Johnson590fbe12019-07-03 14:30:01 -0700469 # If the subnet is IPv6 slaac or dhcpv6-stateless
470 # neutron does not allow a fixed IP
471 if not cls.lb_member_vip_ipv6_subnet_stateful:
472 use_fixed_ip = False
Adam Harwellcd72b562018-05-07 11:37:22 -0700473 lb_kwargs[const.VIP_SUBNET_ID] = subnet_id
Michael Johnson07c9a632018-06-07 13:27:42 -0700474 if use_fixed_ip:
475 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700476 if CONF.load_balancer.test_with_noop:
477 lb_kwargs[const.VIP_NETWORK_ID] = (
478 cls.lb_member_vip_net[const.ID])
479 else:
480 lb_kwargs[const.VIP_NETWORK_ID] = cls.lb_member_vip_net[const.ID]
481 lb_kwargs[const.VIP_SUBNET_ID] = None
482
483
484class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest):
485 @classmethod
486 def resource_setup(cls):
487 super(LoadBalancerBaseTestWithCompute, cls).resource_setup()
488 # If validation is disabled in this cloud, we won't be able to
489 # start the webservers, so don't even boot them.
490 if not CONF.validation.run_validation:
491 return
492
493 # Create a keypair for the webservers
494 keypair_name = data_utils.rand_name('lb_member_keypair')
495 result = cls.lb_mem_keypairs_client.create_keypair(
496 name=keypair_name)
497 cls.lb_member_keypair = result['keypair']
498 LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair))
499 cls.addClassResourceCleanup(
500 waiters.wait_for_not_found,
501 cls.lb_mem_keypairs_client.delete_keypair,
502 cls.lb_mem_keypairs_client.show_keypair,
503 keypair_name)
504
505 if (CONF.load_balancer.enable_security_groups and
506 CONF.network_feature_enabled.port_security):
507 # Set up the security group for the webservers
508 SG_name = data_utils.rand_name('lb_member_SG')
509 cls.lb_member_sec_group = (
510 cls.lb_mem_SG_client.create_security_group(
511 name=SG_name)['security_group'])
512 cls.addClassResourceCleanup(
513 waiters.wait_for_not_found,
514 cls.lb_mem_SG_client.delete_security_group,
515 cls.lb_mem_SG_client.show_security_group,
516 cls.lb_member_sec_group['id'])
517
518 # Create a security group rule to allow 80-81 (test webservers)
519 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
520 direction='ingress',
521 security_group_id=cls.lb_member_sec_group['id'],
522 protocol='tcp',
523 ethertype='IPv4',
524 port_range_min=80,
525 port_range_max=81)['security_group_rule']
526 cls.addClassResourceCleanup(
527 waiters.wait_for_not_found,
528 cls.lb_mem_SGr_client.delete_security_group_rule,
529 cls.lb_mem_SGr_client.show_security_group_rule,
530 SGr['id'])
531 # Create a security group rule to allow 22 (ssh)
532 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
533 direction='ingress',
534 security_group_id=cls.lb_member_sec_group['id'],
535 protocol='tcp',
536 ethertype='IPv4',
537 port_range_min=22,
538 port_range_max=22)['security_group_rule']
539 cls.addClassResourceCleanup(
540 waiters.wait_for_not_found,
541 cls.lb_mem_SGr_client.delete_security_group_rule,
542 cls.lb_mem_SGr_client.show_security_group_rule,
543 SGr['id'])
544 if CONF.load_balancer.test_with_ipv6:
545 # Create a security group rule to allow 80-81 (test webservers)
546 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
547 direction='ingress',
548 security_group_id=cls.lb_member_sec_group['id'],
549 protocol='tcp',
550 ethertype='IPv6',
551 port_range_min=80,
552 port_range_max=81)['security_group_rule']
553 cls.addClassResourceCleanup(
554 waiters.wait_for_not_found,
555 cls.lb_mem_SGr_client.delete_security_group_rule,
556 cls.lb_mem_SGr_client.show_security_group_rule,
557 SGr['id'])
558 # Create a security group rule to allow 22 (ssh)
559 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
560 direction='ingress',
561 security_group_id=cls.lb_member_sec_group['id'],
562 protocol='tcp',
563 ethertype='IPv6',
564 port_range_min=22,
565 port_range_max=22)['security_group_rule']
566 cls.addClassResourceCleanup(
567 waiters.wait_for_not_found,
568 cls.lb_mem_SGr_client.delete_security_group_rule,
569 cls.lb_mem_SGr_client.show_security_group_rule,
570 SGr['id'])
571
572 LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group))
573
574 # Create webserver 1 instance
575 server_details = cls._create_webserver('lb_member_webserver1',
576 cls.lb_member_1_net)
577
578 cls.lb_member_webserver1 = server_details['server']
579 cls.webserver1_ip = server_details.get('ipv4_address')
580 cls.webserver1_ipv6 = server_details.get('ipv6_address')
581 cls.webserver1_public_ip = server_details['public_ipv4_address']
582
583 LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format(
584 cls.lb_member_webserver1[const.ID]))
585 LOG.debug('Octavia Setup: webserver1_ip = {}'.format(
586 cls.webserver1_ip))
587 LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format(
588 cls.webserver1_ipv6))
589 LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format(
590 cls.webserver1_public_ip))
591
592 # Create webserver 2 instance
593 server_details = cls._create_webserver('lb_member_webserver2',
594 cls.lb_member_2_net)
595
596 cls.lb_member_webserver2 = server_details['server']
597 cls.webserver2_ip = server_details.get('ipv4_address')
598 cls.webserver2_ipv6 = server_details.get('ipv6_address')
599 cls.webserver2_public_ip = server_details['public_ipv4_address']
600
601 LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format(
602 cls.lb_member_webserver2[const.ID]))
603 LOG.debug('Octavia Setup: webserver2_ip = {}'.format(
604 cls.webserver2_ip))
605 LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format(
606 cls.webserver2_ipv6))
607 LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format(
608 cls.webserver2_public_ip))
609
Michael Johnsonbf916df2018-10-17 10:59:28 -0700610 if CONF.load_balancer.test_with_ipv6:
611 # Enable the IPv6 nic in webserver 1
612 cls._enable_ipv6_nic_webserver(
613 cls.webserver1_public_ip, cls.lb_member_keypair['private_key'],
614 cls.webserver1_ipv6, cls.lb_member_1_subnet_prefix)
615
616 # Enable the IPv6 nic in webserver 2
617 cls._enable_ipv6_nic_webserver(
618 cls.webserver2_public_ip, cls.lb_member_keypair['private_key'],
619 cls.webserver2_ipv6, cls.lb_member_2_subnet_prefix)
620
Adam Harwellcd72b562018-05-07 11:37:22 -0700621 # Set up serving on webserver 1
622 cls._install_start_webserver(cls.webserver1_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700623 cls.lb_member_keypair['private_key'],
624 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700625
626 # Validate webserver 1
Adam Harwelle029af22018-05-24 17:13:28 -0700627 cls._validate_webserver(cls.webserver1_public_ip,
628 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700629
630 # Set up serving on webserver 2
631 cls._install_start_webserver(cls.webserver2_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700632 cls.lb_member_keypair['private_key'],
633 cls.webserver2_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700634
635 # Validate webserver 2
Adam Harwelle029af22018-05-24 17:13:28 -0700636 cls._validate_webserver(cls.webserver2_public_ip,
637 cls.webserver2_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700638
639 @classmethod
640 def _create_networks(cls):
641 super(LoadBalancerBaseTestWithCompute, cls)._create_networks()
Jude Cross986e3f52017-07-24 14:57:20 -0700642 # Create a router for the subnets (required for the floating IP)
643 router_name = data_utils.rand_name("lb_member_router")
644 result = cls.lb_mem_routers_client.create_router(
645 name=router_name, admin_state_up=True,
646 external_gateway_info=dict(
647 network_id=CONF.network.public_network_id))
648 cls.lb_member_router = result['router']
649 LOG.info('lb_member_router: {}'.format(cls.lb_member_router))
650 cls.addClassResourceCleanup(
651 waiters.wait_for_not_found,
652 cls.lb_mem_routers_client.delete_router,
653 cls.lb_mem_routers_client.show_router,
654 cls.lb_member_router['id'])
655
656 # Add VIP subnet to router
657 cls.lb_mem_routers_client.add_router_interface(
658 cls.lb_member_router['id'],
659 subnet_id=cls.lb_member_vip_subnet['id'])
660 cls.addClassResourceCleanup(
661 waiters.wait_for_not_found,
662 cls.lb_mem_routers_client.remove_router_interface,
663 cls.lb_mem_routers_client.remove_router_interface,
664 cls.lb_member_router['id'],
665 subnet_id=cls.lb_member_vip_subnet['id'])
666
667 # Add member subnet 1 to router
668 cls.lb_mem_routers_client.add_router_interface(
669 cls.lb_member_router['id'],
670 subnet_id=cls.lb_member_1_subnet['id'])
671 cls.addClassResourceCleanup(
672 waiters.wait_for_not_found,
Jude Cross986e3f52017-07-24 14:57:20 -0700673 cls.lb_mem_routers_client.remove_router_interface,
674 cls.lb_mem_routers_client.remove_router_interface,
675 cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id'])
676
677 # Add member subnet 2 to router
678 cls.lb_mem_routers_client.add_router_interface(
679 cls.lb_member_router['id'],
680 subnet_id=cls.lb_member_2_subnet['id'])
681 cls.addClassResourceCleanup(
682 waiters.wait_for_not_found,
683 cls.lb_mem_routers_client.remove_router_interface,
684 cls.lb_mem_routers_client.remove_router_interface,
685 cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id'])
686
687 @classmethod
688 def _create_webserver(cls, name, network):
689 """Creates a webserver with two ports.
690
691 webserver_details dictionary contains:
692 server - The compute server object
693 ipv4_address - The IPv4 address for the server (optional)
694 ipv6_address - The IPv6 address for the server (optional)
695 public_ipv4_address - The publicly accessible IPv4 address for the
696 server, this may be a floating IP (optional)
697
698 :param name: The name of the server to create.
699 :param network: The network to boot the server on.
700 :returns: webserver_details dictionary.
701 """
702 server_kwargs = {
703 'name': data_utils.rand_name(name),
704 'flavorRef': CONF.compute.flavor_ref,
705 'imageRef': CONF.compute.image_ref,
706 'key_name': cls.lb_member_keypair['name']}
707 if (CONF.load_balancer.enable_security_groups and
708 CONF.network_feature_enabled.port_security):
709 server_kwargs['security_groups'] = [
710 {'name': cls.lb_member_sec_group['name']}]
711 if not CONF.load_balancer.disable_boot_network:
712 server_kwargs['networks'] = [{'uuid': network['id']}]
713
714 # Replace the name for clouds that have limitations
715 if CONF.load_balancer.random_server_name_length:
716 r = random.SystemRandom()
717 server_kwargs['name'] = "m{}".format("".join(
718 [r.choice(string.ascii_uppercase + string.digits)
719 for _ in range(
720 CONF.load_balancer.random_server_name_length - 1)]
721 ))
722 if CONF.load_balancer.availability_zone:
723 server_kwargs['availability_zone'] = (
724 CONF.load_balancer.availability_zone)
725
726 server = cls.lb_mem_servers_client.create_server(
727 **server_kwargs)['server']
728 cls.addClassResourceCleanup(
729 waiters.wait_for_not_found,
730 cls.lb_mem_servers_client.delete_server,
731 cls.lb_mem_servers_client.show_server,
732 server['id'])
733 server = waiters.wait_for_status(
734 cls.lb_mem_servers_client.show_server,
735 server['id'], 'status', 'ACTIVE',
736 CONF.load_balancer.build_interval,
737 CONF.load_balancer.build_timeout,
738 root_tag='server')
739 webserver_details = {'server': server}
740 LOG.info('Created server: {}'.format(server))
741
742 addresses = server['addresses']
743 if CONF.load_balancer.disable_boot_network:
744 instance_network = addresses.values()[0]
745 else:
746 instance_network = addresses[network['name']]
747 for addr in instance_network:
748 if addr['version'] == 4:
749 webserver_details['ipv4_address'] = addr['addr']
750 if addr['version'] == 6:
751 webserver_details['ipv6_address'] = addr['addr']
752
753 if CONF.validation.connect_method == 'floating':
754 result = cls.lb_mem_ports_client.list_ports(
755 network_id=network['id'],
756 mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr'])
757 port_id = result['ports'][0]['id']
758 result = cls.lb_mem_float_ip_client.create_floatingip(
759 floating_network_id=CONF.network.public_network_id,
760 port_id=port_id)
761 floating_ip = result['floatingip']
762 LOG.info('webserver1_floating_ip: {}'.format(floating_ip))
763 cls.addClassResourceCleanup(
764 waiters.wait_for_not_found,
765 cls.lb_mem_float_ip_client.delete_floatingip,
766 cls.lb_mem_float_ip_client.show_floatingip,
767 floatingip_id=floating_ip['id'])
768 webserver_details['public_ipv4_address'] = (
769 floating_ip['floating_ip_address'])
770 else:
771 webserver_details['public_ipv4_address'] = (
772 instance_network[0]['addr'])
773
774 return webserver_details
775
776 @classmethod
Adam Harwellcd72b562018-05-07 11:37:22 -0700777 def _install_start_webserver(cls, ip_address, ssh_key, start_id):
778 local_file = pkg_resources.resource_filename(
779 'octavia_tempest_plugin.contrib.httpd', 'httpd.bin')
780 dest_file = '/dev/shm/httpd.bin'
781
782 linux_client = remote_client.RemoteClient(
783 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key)
784 linux_client.validate_authentication()
785
786 with tempfile.NamedTemporaryFile() as key:
787 key.write(ssh_key.encode('utf-8'))
788 key.flush()
789 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
790 "-o StrictHostKeyChecking=no "
791 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
792 "-i {2} {3} {4}@{5}:{6}").format(
793 CONF.load_balancer.scp_connection_timeout,
794 CONF.load_balancer.scp_connection_attempts,
795 key.name, local_file, CONF.validation.image_ssh_user,
796 ip_address, dest_file)
797 args = shlex.split(cmd)
798 subprocess_args = {'stdout': subprocess.PIPE,
799 'stderr': subprocess.STDOUT,
800 'cwd': None}
801 proc = subprocess.Popen(args, **subprocess_args)
802 stdout, stderr = proc.communicate()
803 if proc.returncode != 0:
804 raise exceptions.CommandFailed(proc.returncode, cmd,
805 stdout, stderr)
806 linux_client.exec_command('sudo screen -d -m {0} -port 80 '
807 '-id {1}'.format(dest_file, start_id))
808 linux_client.exec_command('sudo screen -d -m {0} -port 81 '
809 '-id {1}'.format(dest_file, start_id + 1))
810
Michael Johnsonbf916df2018-10-17 10:59:28 -0700811 # Cirros does not configure the assigned IPv6 address by default
812 # so enable it manually like tempest does here:
813 # tempest/scenario/test_netowrk_v6.py turn_nic6_on()
814 @classmethod
815 def _enable_ipv6_nic_webserver(cls, ip_address, ssh_key,
816 ipv6_address, ipv6_prefix):
817 linux_client = remote_client.RemoteClient(
818 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key)
819 linux_client.validate_authentication()
820
821 linux_client.exec_command('sudo ip address add {0}/{1} dev '
822 'eth0'.format(ipv6_address, ipv6_prefix))
823
Adam Harwellcd72b562018-05-07 11:37:22 -0700824 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -0700825 def _validate_webserver(cls, ip_address, start_id):
826 URL = 'http://{0}'.format(ip_address)
827 validators.validate_URL_response(URL, expected_body=str(start_id))
828 URL = 'http://{0}:81'.format(ip_address)
829 validators.validate_URL_response(URL, expected_body=str(start_id + 1))
830
Michael Johnson0a0f9b32019-01-02 16:58:21 -0800831 def _wait_for_lb_functional(self, vip_address,
832 protocol='http', verify=True):
Adam Harwellcd72b562018-05-07 11:37:22 -0700833 session = requests.Session()
834 start = time.time()
835
836 while time.time() - start < CONF.load_balancer.build_timeout:
837 try:
Michael Johnson0a0f9b32019-01-02 16:58:21 -0800838 session.get("{0}://{1}".format(protocol, vip_address),
839 timeout=2, verify=verify)
Adam Harwellcd72b562018-05-07 11:37:22 -0700840 time.sleep(1)
841 return
842 except Exception:
843 LOG.warning('Server is not passing initial traffic. Waiting.')
844 time.sleep(1)
845 LOG.error('Server did not begin passing traffic within the timeout '
846 'period. Failing test.')
847 raise Exception()
848
Michael Johnson0a0f9b32019-01-02 16:58:21 -0800849 def check_members_balanced(self, vip_address, traffic_member_count=2,
850 protocol='http', verify=True):
Adam Harwellcd72b562018-05-07 11:37:22 -0700851 session = requests.Session()
852 response_counts = {}
853
Michael Johnson5a16ad32018-10-18 14:49:11 -0700854 if ipaddress.ip_address(vip_address).version == 6:
855 vip_address = '[{}]'.format(vip_address)
856
Michael Johnson0a0f9b32019-01-02 16:58:21 -0800857 self._wait_for_lb_functional(vip_address, protocol, verify)
Adam Harwellcd72b562018-05-07 11:37:22 -0700858
859 # Send a number requests to lb vip
860 for i in range(20):
861 try:
Michael Johnson0a0f9b32019-01-02 16:58:21 -0800862 r = session.get('{0}://{1}'.format(protocol, vip_address),
863 timeout=2, verify=verify)
Adam Harwellcd72b562018-05-07 11:37:22 -0700864
865 if r.content in response_counts:
866 response_counts[r.content] += 1
867 else:
868 response_counts[r.content] = 1
869
870 except Exception:
871 LOG.exception('Failed to send request to loadbalancer vip')
872 raise Exception('Failed to connect to lb')
873
874 LOG.debug('Loadbalancer response totals: %s', response_counts)
875 # Ensure the correct number of members
Adam Harwell60ed9d92018-05-10 13:23:13 -0700876 self.assertEqual(traffic_member_count, len(response_counts))
Adam Harwellcd72b562018-05-07 11:37:22 -0700877
878 # Ensure both members got the same number of responses
879 self.assertEqual(1, len(set(response_counts.values())))
Adam Harwelle029af22018-05-24 17:13:28 -0700880
881 def assertConsistentResponse(self, response, url, method='GET', repeat=10,
882 redirect=False, timeout=2, **kwargs):
883 """Assert that a request to URL gets the expected response.
884
885 :param response: Expected response in format (status_code, content).
886 :param url: The URL to request.
887 :param method: The HTTP method to use (GET, POST, PUT, etc)
888 :param repeat: How many times to test the response.
889 :param data: Optional data to send in the request.
890 :param headers: Optional headers to send in the request.
891 :param cookies: Optional cookies to send in the request.
892 :param redirect: Is the request a redirect? If true, assume the passed
893 content should be the next URL in the chain.
Carlos Goncalvesc451ff92018-12-19 19:11:53 +0100894 :param timeout: Optional seconds to wait for the server to send data.
895
Adam Harwelle029af22018-05-24 17:13:28 -0700896 :return: boolean success status
897
898 :raises: testtools.matchers.MismatchError
899 """
900 session = requests.Session()
901 response_code, response_content = response
902
903 for i in range(0, repeat):
904 req = session.request(method, url, allow_redirects=not redirect,
905 timeout=timeout, **kwargs)
906 if response_code:
907 self.assertEqual(response_code, req.status_code)
908 if redirect:
909 self.assertTrue(req.is_redirect)
Carlos Goncalvesc451ff92018-12-19 19:11:53 +0100910 self.assertEqual(response_content,
911 session.get_redirect_target(req))
Adam Harwelle029af22018-05-24 17:13:28 -0700912 elif response_content:
913 self.assertEqual(six.text_type(response_content), req.text)