blob: 8a2c3c70dc1482737ac4cd81299fa5a4262aa7f1 [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
Michael Johnsonbaf12e02020-10-27 16:10:28 -070016import os
Jude Cross986e3f52017-07-24 14:57:20 -070017import random
18import shlex
Jude Cross986e3f52017-07-24 14:57:20 -070019import string
20import subprocess
21import tempfile
22
Michael Johnsonbaf12e02020-10-27 16:10:28 -070023from cryptography.hazmat.primitives import serialization
Jude Cross986e3f52017-07-24 14:57:20 -070024from oslo_log import log as logging
25from oslo_utils import uuidutils
26from tempest import config
27from tempest.lib.common.utils import data_utils
28from tempest.lib.common.utils.linux import remote_client
Jude Cross986e3f52017-07-24 14:57:20 -070029from tempest.lib import exceptions
30from tempest import test
Michael Johnson04dc5cb2019-01-20 11:03:50 -080031import tenacity
Jude Cross986e3f52017-07-24 14:57:20 -070032
33from octavia_tempest_plugin import clients
Michael Johnsonbaf12e02020-10-27 16:10:28 -070034from octavia_tempest_plugin.common import cert_utils
Jude Cross986e3f52017-07-24 14:57:20 -070035from octavia_tempest_plugin.common import constants as const
36from octavia_tempest_plugin.tests import validators
37from octavia_tempest_plugin.tests import waiters
38
39CONF = config.CONF
40LOG = logging.getLogger(__name__)
41
Michael Johnson04dc5cb2019-01-20 11:03:50 -080042RETRY_ATTEMPTS = 15
43RETRY_INITIAL_DELAY = 1
44RETRY_BACKOFF = 1
45RETRY_MAX = 5
46
Gregory Thiemonge29d17902019-04-30 15:06:17 +020047
Michael Johnson89bdbcd2020-03-19 15:59:19 -070048class LoadBalancerBaseTest(validators.ValidatorsMixin, test.BaseTestCase):
Jude Cross986e3f52017-07-24 14:57:20 -070049 """Base class for load balancer tests."""
50
51 # Setup cls.os_roles_lb_member. cls.os_primary, cls.os_roles_lb_member,
52 # and cls.os_roles_lb_admin credentials.
53 credentials = ['admin', 'primary',
54 ['lb_member', CONF.load_balancer.member_role],
55 ['lb_member2', CONF.load_balancer.member_role],
56 ['lb_admin', CONF.load_balancer.admin_role]]
57
58 client_manager = clients.ManagerV2
Adam Harwelle029af22018-05-24 17:13:28 -070059 webserver1_response = 1
60 webserver2_response = 5
Michael Johnsondfd818a2018-08-21 20:54:54 -070061 used_ips = []
Jude Cross986e3f52017-07-24 14:57:20 -070062
Michael Johnson89bdbcd2020-03-19 15:59:19 -070063 SRC_PORT_NUMBER_MIN = 32768
64 SRC_PORT_NUMBER_MAX = 61000
Gregory Thiemonge29d17902019-04-30 15:06:17 +020065 src_port_number = SRC_PORT_NUMBER_MIN
66
Jude Cross986e3f52017-07-24 14:57:20 -070067 @classmethod
68 def skip_checks(cls):
69 """Check if we should skip all of the children tests."""
70 super(LoadBalancerBaseTest, cls).skip_checks()
71
72 service_list = {
73 'load_balancer': CONF.service_available.load_balancer,
74 }
75
76 live_service_list = {
77 'compute': CONF.service_available.nova,
78 'image': CONF.service_available.glance,
79 'neutron': CONF.service_available.neutron
80 }
81
82 if not CONF.load_balancer.test_with_noop:
83 service_list.update(live_service_list)
84
85 for service, available in service_list.items():
86 if not available:
zhangzs2a6cf672018-11-10 16:13:11 +080087 skip_msg = ("{0} skipped as {1} service is not "
Jude Cross986e3f52017-07-24 14:57:20 -070088 "available.".format(cls.__name__, service))
89 raise cls.skipException(skip_msg)
90
91 # We must be able to reach our VIP and instances
92 if not (CONF.network.project_networks_reachable
93 or CONF.network.public_network_id):
94 msg = ('Either project_networks_reachable must be "true", or '
95 'public_network_id must be defined.')
96 raise cls.skipException(msg)
97
98 @classmethod
99 def setup_credentials(cls):
100 """Setup test credentials and network resources."""
101 # Do not auto create network resources
102 cls.set_network_resources()
103 super(LoadBalancerBaseTest, cls).setup_credentials()
104
105 @classmethod
106 def setup_clients(cls):
107 """Setup client aliases."""
108 super(LoadBalancerBaseTest, cls).setup_clients()
109 cls.lb_mem_float_ip_client = cls.os_roles_lb_member.floating_ips_client
110 cls.lb_mem_keypairs_client = cls.os_roles_lb_member.keypairs_client
111 cls.lb_mem_net_client = cls.os_roles_lb_member.networks_client
112 cls.lb_mem_ports_client = cls.os_roles_lb_member.ports_client
113 cls.lb_mem_routers_client = cls.os_roles_lb_member.routers_client
114 cls.lb_mem_SG_client = cls.os_roles_lb_member.security_groups_client
115 cls.lb_mem_SGr_client = (
116 cls.os_roles_lb_member.security_group_rules_client)
117 cls.lb_mem_servers_client = cls.os_roles_lb_member.servers_client
118 cls.lb_mem_subnet_client = cls.os_roles_lb_member.subnets_client
119 cls.mem_lb_client = cls.os_roles_lb_member.loadbalancer_client
Jude Crossfbbd2b42017-08-09 15:21:04 -0700120 cls.mem_listener_client = cls.os_roles_lb_member.listener_client
Adam Harwell8ffce3e2018-05-01 21:18:44 -0700121 cls.mem_pool_client = cls.os_roles_lb_member.pool_client
Adam Harwellde3e0542018-05-03 18:21:06 -0700122 cls.mem_member_client = cls.os_roles_lb_member.member_client
Adam Harwell60ed9d92018-05-10 13:23:13 -0700123 cls.mem_healthmonitor_client = (
124 cls.os_roles_lb_member.healthmonitor_client)
Adam Harwell446f8be2018-05-24 16:51:03 -0700125 cls.mem_l7policy_client = cls.os_roles_lb_member.l7policy_client
Adam Harwelle029af22018-05-24 17:13:28 -0700126 cls.mem_l7rule_client = cls.os_roles_lb_member.l7rule_client
Michael Johnson2b10e0a2019-01-25 15:42:13 -0800127 cls.lb_admin_amphora_client = cls.os_roles_lb_admin.amphora_client
Michael Johnsonaff2e862019-01-11 16:38:00 -0800128 cls.lb_admin_flavor_profile_client = (
129 cls.os_roles_lb_admin.flavor_profile_client)
Michael Johnsona2d03072019-01-14 17:18:21 -0800130 cls.lb_admin_flavor_client = cls.os_roles_lb_admin.flavor_client
131 cls.mem_flavor_client = cls.os_roles_lb_member.flavor_client
Michael Johnsonfc223fe2019-01-15 16:40:05 -0800132 cls.mem_provider_client = cls.os_roles_lb_member.provider_client
Carlos Goncalvesc2e12162019-02-14 23:57:44 +0100133 cls.os_admin_servers_client = cls.os_admin.servers_client
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800134 cls.lb_admin_flavor_capabilities_client = (
Michael Johnson77df0322019-01-15 18:27:58 -0800135 cls.os_roles_lb_admin.flavor_capabilities_client)
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800136 cls.lb_admin_availability_zone_capabilities_client = (
137 cls.os_roles_lb_admin.availability_zone_capabilities_client)
138 cls.lb_admin_availability_zone_profile_client = (
139 cls.os_roles_lb_admin.availability_zone_profile_client)
140 cls.lb_admin_availability_zone_client = (
141 cls.os_roles_lb_admin.availability_zone_client)
142 cls.mem_availability_zone_client = (
143 cls.os_roles_lb_member.availability_zone_client)
Jude Cross986e3f52017-07-24 14:57:20 -0700144
145 @classmethod
146 def resource_setup(cls):
147 """Setup resources needed by the tests."""
148 super(LoadBalancerBaseTest, cls).resource_setup()
149
150 conf_lb = CONF.load_balancer
151
Michael Johnsondfd818a2018-08-21 20:54:54 -0700152 cls.api_version = cls.mem_lb_client.get_max_api_version()
153
Jude Cross986e3f52017-07-24 14:57:20 -0700154 if conf_lb.test_subnet_override and not conf_lb.test_network_override:
155 raise exceptions.InvalidConfiguration(
156 "Configuration value test_network_override must be "
157 "specified if test_subnet_override is used.")
158
Michael Johnson6a9236a2020-08-04 23:54:54 +0000159 # TODO(johnsom) Remove this
Maciej Józefczykb6df5f82019-12-10 10:12:30 +0000160 # Get loadbalancing algorithms supported by provider driver.
161 try:
162 algorithms = const.SUPPORTED_LB_ALGORITHMS[
163 CONF.load_balancer.provider]
164 except KeyError:
165 algorithms = const.SUPPORTED_LB_ALGORITHMS['default']
166 # Set default algorithm as first from the list.
167 cls.lb_algorithm = algorithms[0]
168
Jude Cross986e3f52017-07-24 14:57:20 -0700169 show_subnet = cls.lb_mem_subnet_client.show_subnet
170 if CONF.load_balancer.test_with_noop:
171 cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()}
172 cls.lb_member_vip_subnet = {'id': uuidutils.generate_uuid()}
173 cls.lb_member_1_net = {'id': uuidutils.generate_uuid()}
174 cls.lb_member_1_subnet = {'id': uuidutils.generate_uuid()}
175 cls.lb_member_2_net = {'id': uuidutils.generate_uuid()}
176 cls.lb_member_2_subnet = {'id': uuidutils.generate_uuid()}
177 if CONF.load_balancer.test_with_ipv6:
Michael Johnson5a16ad32018-10-18 14:49:11 -0700178 cls.lb_member_vip_ipv6_net = {'id': uuidutils.generate_uuid()}
Jude Cross986e3f52017-07-24 14:57:20 -0700179 cls.lb_member_vip_ipv6_subnet = {'id':
180 uuidutils.generate_uuid()}
181 cls.lb_member_1_ipv6_subnet = {'id': uuidutils.generate_uuid()}
182 cls.lb_member_2_ipv6_subnet = {'id': uuidutils.generate_uuid()}
Michael Johnson590fbe12019-07-03 14:30:01 -0700183 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700184 return
185 elif CONF.load_balancer.test_network_override:
186 if conf_lb.test_subnet_override:
187 override_subnet = show_subnet(conf_lb.test_subnet_override)
188 else:
189 override_subnet = None
190
191 show_net = cls.lb_mem_net_client.show_network
192 override_network = show_net(conf_lb.test_network_override)
193 override_network = override_network.get('network')
194
195 cls.lb_member_vip_net = override_network
196 cls.lb_member_vip_subnet = override_subnet
197 cls.lb_member_1_net = override_network
198 cls.lb_member_1_subnet = override_subnet
199 cls.lb_member_2_net = override_network
200 cls.lb_member_2_subnet = override_subnet
201
202 if (CONF.load_balancer.test_with_ipv6 and
203 conf_lb.test_IPv6_subnet_override):
204 override_ipv6_subnet = show_subnet(
205 conf_lb.test_IPv6_subnet_override)
206 cls.lb_member_vip_ipv6_subnet = override_ipv6_subnet
207 cls.lb_member_1_ipv6_subnet = override_ipv6_subnet
208 cls.lb_member_2_ipv6_subnet = override_ipv6_subnet
Michael Johnson590fbe12019-07-03 14:30:01 -0700209 cls.lb_member_vip_ipv6_subnet_stateful = False
210 if (override_ipv6_subnet[0]['ipv6_address_mode'] ==
211 'dhcpv6-stateful'):
212 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700213 else:
214 cls.lb_member_vip_ipv6_subnet = None
215 cls.lb_member_1_ipv6_subnet = None
216 cls.lb_member_2_ipv6_subnet = None
217 else:
218 cls._create_networks()
219
220 LOG.debug('Octavia Setup: lb_member_vip_net = {}'.format(
221 cls.lb_member_vip_net[const.ID]))
222 if cls.lb_member_vip_subnet:
223 LOG.debug('Octavia Setup: lb_member_vip_subnet = {}'.format(
224 cls.lb_member_vip_subnet[const.ID]))
225 LOG.debug('Octavia Setup: lb_member_1_net = {}'.format(
226 cls.lb_member_1_net[const.ID]))
227 if cls.lb_member_1_subnet:
228 LOG.debug('Octavia Setup: lb_member_1_subnet = {}'.format(
229 cls.lb_member_1_subnet[const.ID]))
230 LOG.debug('Octavia Setup: lb_member_2_net = {}'.format(
231 cls.lb_member_2_net[const.ID]))
232 if cls.lb_member_2_subnet:
233 LOG.debug('Octavia Setup: lb_member_2_subnet = {}'.format(
234 cls.lb_member_2_subnet[const.ID]))
Michael Johnson124ba8b2018-08-30 16:06:05 -0700235 if CONF.load_balancer.test_with_ipv6:
236 if cls.lb_member_vip_ipv6_subnet:
237 LOG.debug('Octavia Setup: lb_member_vip_ipv6_subnet = '
238 '{}'.format(cls.lb_member_vip_ipv6_subnet[const.ID]))
239 if cls.lb_member_1_ipv6_subnet:
240 LOG.debug('Octavia Setup: lb_member_1_ipv6_subnet = {}'.format(
241 cls.lb_member_1_ipv6_subnet[const.ID]))
242 if cls.lb_member_2_ipv6_subnet:
243 LOG.debug('Octavia Setup: lb_member_2_ipv6_subnet = {}'.format(
244 cls.lb_member_2_ipv6_subnet[const.ID]))
Jude Cross986e3f52017-07-24 14:57:20 -0700245
Jude Cross986e3f52017-07-24 14:57:20 -0700246 @classmethod
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800247 # Neutron can be slow to clean up ports from the subnets/networks.
248 # Retry this delete a few times if we get a "Conflict" error to give
249 # neutron time to fully cleanup the ports.
250 @tenacity.retry(
251 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
252 wait=tenacity.wait_incrementing(
253 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
254 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
255 def _logging_delete_network(cls, net_id):
256 try:
257 cls.lb_mem_net_client.delete_network(net_id)
258 except Exception:
259 LOG.error('Unable to delete network {}. Active ports:'.format(
260 net_id))
261 LOG.error(cls.lb_mem_ports_client.list_ports())
262 raise
263
264 @classmethod
265 # Neutron can be slow to clean up ports from the subnets/networks.
266 # Retry this delete a few times if we get a "Conflict" error to give
267 # neutron time to fully cleanup the ports.
268 @tenacity.retry(
269 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
270 wait=tenacity.wait_incrementing(
271 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
272 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
273 def _logging_delete_subnet(cls, subnet_id):
274 try:
275 cls.lb_mem_subnet_client.delete_subnet(subnet_id)
276 except Exception:
277 LOG.error('Unable to delete subnet {}. Active ports:'.format(
278 subnet_id))
279 LOG.error(cls.lb_mem_ports_client.list_ports())
280 raise
281
282 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -0700283 def _create_networks(cls):
284 """Creates networks, subnets, and routers used in tests.
285
286 The following are expected to be defined and available to the tests:
287 cls.lb_member_vip_net
288 cls.lb_member_vip_subnet
289 cls.lb_member_vip_ipv6_subnet (optional)
290 cls.lb_member_1_net
291 cls.lb_member_1_subnet
292 cls.lb_member_1_ipv6_subnet (optional)
293 cls.lb_member_2_net
294 cls.lb_member_2_subnet
295 cls.lb_member_2_ipv6_subnet (optional)
296 """
297
298 # Create tenant VIP network
299 network_kwargs = {
300 'name': data_utils.rand_name("lb_member_vip_network")}
301 if CONF.network_feature_enabled.port_security:
Andreas Jaeger4215b702020-03-28 20:13:46 +0100302 # Note: Allowed Address Pairs requires port security
303 network_kwargs['port_security_enabled'] = True
Jude Cross986e3f52017-07-24 14:57:20 -0700304 result = cls.lb_mem_net_client.create_network(**network_kwargs)
305 cls.lb_member_vip_net = result['network']
306 LOG.info('lb_member_vip_net: {}'.format(cls.lb_member_vip_net))
307 cls.addClassResourceCleanup(
308 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800309 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700310 cls.lb_mem_net_client.show_network,
311 cls.lb_member_vip_net['id'])
312
313 # Create tenant VIP subnet
314 subnet_kwargs = {
315 'name': data_utils.rand_name("lb_member_vip_subnet"),
316 'network_id': cls.lb_member_vip_net['id'],
317 'cidr': CONF.load_balancer.vip_subnet_cidr,
318 'ip_version': 4}
319 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
320 cls.lb_member_vip_subnet = result['subnet']
321 LOG.info('lb_member_vip_subnet: {}'.format(cls.lb_member_vip_subnet))
322 cls.addClassResourceCleanup(
323 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800324 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700325 cls.lb_mem_subnet_client.show_subnet,
326 cls.lb_member_vip_subnet['id'])
327
328 # Create tenant VIP IPv6 subnet
329 if CONF.load_balancer.test_with_ipv6:
Adam Harwell2b9432f2019-05-02 13:56:09 -0600330 # See if ipv6-private-subnet exists and use it if so.
331 priv_ipv6_subnet = cls.os_admin.subnets_client.list_subnets(
332 name='ipv6-private-subnet')['subnets']
Michael Johnson5a16ad32018-10-18 14:49:11 -0700333
Michael Johnson590fbe12019-07-03 14:30:01 -0700334 cls.lb_member_vip_ipv6_subnet_stateful = False
Adam Harwell2b9432f2019-05-02 13:56:09 -0600335 if len(priv_ipv6_subnet) == 1:
Carlos Goncalves84af48c2019-07-25 15:51:30 +0200336 if (priv_ipv6_subnet[0]['ipv6_address_mode'] ==
337 'dhcpv6-stateful'):
338 cls.lb_member_vip_ipv6_subnet_stateful = True
Adam Harwell2b9432f2019-05-02 13:56:09 -0600339 cls.lb_member_vip_ipv6_subnet = priv_ipv6_subnet[0]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700340 cls.lb_member_vip_ipv6_net = {
Adam Harwell2b9432f2019-05-02 13:56:09 -0600341 'id': priv_ipv6_subnet[0]['network_id']}
Michael Johnson5a16ad32018-10-18 14:49:11 -0700342 else:
343 subnet_kwargs = {
344 'name': data_utils.rand_name("lb_member_vip_ipv6_subnet"),
345 'network_id': cls.lb_member_vip_net['id'],
346 'cidr': CONF.load_balancer.vip_ipv6_subnet_cidr,
347 'ip_version': 6}
348 result = cls.lb_mem_subnet_client.create_subnet(
349 **subnet_kwargs)
Michael Johnson7c5b9012019-05-28 11:02:29 -0700350 cls.lb_member_vip_ipv6_net = cls.lb_member_vip_net
Michael Johnson5a16ad32018-10-18 14:49:11 -0700351 cls.lb_member_vip_ipv6_subnet = result['subnet']
352 cls.addClassResourceCleanup(
353 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800354 cls._logging_delete_subnet,
Michael Johnson5a16ad32018-10-18 14:49:11 -0700355 cls.lb_mem_subnet_client.show_subnet,
356 cls.lb_member_vip_ipv6_subnet['id'])
Carlos Goncalves84af48c2019-07-25 15:51:30 +0200357
Jude Cross986e3f52017-07-24 14:57:20 -0700358 LOG.info('lb_member_vip_ipv6_subnet: {}'.format(
359 cls.lb_member_vip_ipv6_subnet))
Jude Cross986e3f52017-07-24 14:57:20 -0700360
361 # Create tenant member 1 network
362 network_kwargs = {
363 'name': data_utils.rand_name("lb_member_1_network")}
364 if CONF.network_feature_enabled.port_security:
365 if CONF.load_balancer.enable_security_groups:
366 network_kwargs['port_security_enabled'] = True
367 else:
368 network_kwargs['port_security_enabled'] = False
369 result = cls.lb_mem_net_client.create_network(**network_kwargs)
370 cls.lb_member_1_net = result['network']
371 LOG.info('lb_member_1_net: {}'.format(cls.lb_member_1_net))
372 cls.addClassResourceCleanup(
373 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800374 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700375 cls.lb_mem_net_client.show_network,
376 cls.lb_member_1_net['id'])
377
378 # Create tenant member 1 subnet
379 subnet_kwargs = {
380 'name': data_utils.rand_name("lb_member_1_subnet"),
381 'network_id': cls.lb_member_1_net['id'],
382 'cidr': CONF.load_balancer.member_1_ipv4_subnet_cidr,
383 'ip_version': 4}
384 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
385 cls.lb_member_1_subnet = result['subnet']
386 LOG.info('lb_member_1_subnet: {}'.format(cls.lb_member_1_subnet))
387 cls.addClassResourceCleanup(
388 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800389 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700390 cls.lb_mem_subnet_client.show_subnet,
391 cls.lb_member_1_subnet['id'])
392
393 # Create tenant member 1 ipv6 subnet
394 if CONF.load_balancer.test_with_ipv6:
395 subnet_kwargs = {
396 'name': data_utils.rand_name("lb_member_1_ipv6_subnet"),
397 'network_id': cls.lb_member_1_net['id'],
398 'cidr': CONF.load_balancer.member_1_ipv6_subnet_cidr,
399 'ip_version': 6}
400 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700401 cls.lb_member_1_subnet_prefix = (
402 CONF.load_balancer.member_1_ipv6_subnet_cidr.rpartition('/')[2]
403 )
404 assert(cls.lb_member_1_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700405 cls.lb_member_1_ipv6_subnet = result['subnet']
406 LOG.info('lb_member_1_ipv6_subnet: {}'.format(
407 cls.lb_member_1_ipv6_subnet))
408 cls.addClassResourceCleanup(
409 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800410 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700411 cls.lb_mem_subnet_client.show_subnet,
412 cls.lb_member_1_ipv6_subnet['id'])
413
414 # Create tenant member 2 network
415 network_kwargs = {
416 'name': data_utils.rand_name("lb_member_2_network")}
417 if CONF.network_feature_enabled.port_security:
418 if CONF.load_balancer.enable_security_groups:
419 network_kwargs['port_security_enabled'] = True
420 else:
421 network_kwargs['port_security_enabled'] = False
422 result = cls.lb_mem_net_client.create_network(**network_kwargs)
423 cls.lb_member_2_net = result['network']
424 LOG.info('lb_member_2_net: {}'.format(cls.lb_member_2_net))
425 cls.addClassResourceCleanup(
426 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800427 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700428 cls.lb_mem_net_client.show_network,
429 cls.lb_member_2_net['id'])
430
431 # Create tenant member 2 subnet
432 subnet_kwargs = {
433 'name': data_utils.rand_name("lb_member_2_subnet"),
434 'network_id': cls.lb_member_2_net['id'],
435 'cidr': CONF.load_balancer.member_2_ipv4_subnet_cidr,
436 'ip_version': 4}
437 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
438 cls.lb_member_2_subnet = result['subnet']
439 LOG.info('lb_member_2_subnet: {}'.format(cls.lb_member_2_subnet))
440 cls.addClassResourceCleanup(
441 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800442 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700443 cls.lb_mem_subnet_client.show_subnet,
444 cls.lb_member_2_subnet['id'])
445
446 # Create tenant member 2 ipv6 subnet
447 if CONF.load_balancer.test_with_ipv6:
448 subnet_kwargs = {
449 'name': data_utils.rand_name("lb_member_2_ipv6_subnet"),
450 'network_id': cls.lb_member_2_net['id'],
451 'cidr': CONF.load_balancer.member_2_ipv6_subnet_cidr,
452 'ip_version': 6}
453 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700454 cls.lb_member_2_subnet_prefix = (
455 CONF.load_balancer.member_2_ipv6_subnet_cidr.rpartition('/')[2]
456 )
457 assert(cls.lb_member_2_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700458 cls.lb_member_2_ipv6_subnet = result['subnet']
459 LOG.info('lb_member_2_ipv6_subnet: {}'.format(
460 cls.lb_member_2_ipv6_subnet))
461 cls.addClassResourceCleanup(
462 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800463 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700464 cls.lb_mem_subnet_client.show_subnet,
465 cls.lb_member_2_ipv6_subnet['id'])
466
Adam Harwellcd72b562018-05-07 11:37:22 -0700467 @classmethod
Michael Johnson07c9a632018-06-07 13:27:42 -0700468 def _setup_lb_network_kwargs(cls, lb_kwargs, ip_version=None,
469 use_fixed_ip=False):
Adam Harwell60ed9d92018-05-10 13:23:13 -0700470 if not ip_version:
471 ip_version = 6 if CONF.load_balancer.test_with_ipv6 else 4
Michael Johnson5a16ad32018-10-18 14:49:11 -0700472 if cls.lb_member_vip_subnet or cls.lb_member_vip_ipv6_subnet:
Adam Harwellcd72b562018-05-07 11:37:22 -0700473 ip_index = data_utils.rand_int_id(start=10, end=100)
Michael Johnsondfd818a2018-08-21 20:54:54 -0700474 while ip_index in cls.used_ips:
475 ip_index = data_utils.rand_int_id(start=10, end=100)
476 cls.used_ips.append(ip_index)
Adam Harwellcd72b562018-05-07 11:37:22 -0700477 if ip_version == 4:
Adam Harwellcd72b562018-05-07 11:37:22 -0700478 subnet_id = cls.lb_member_vip_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700479 if CONF.load_balancer.test_with_noop:
480 lb_vip_address = '198.18.33.33'
481 else:
482 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
483 network = ipaddress.IPv4Network(subnet['subnet']['cidr'])
484 lb_vip_address = str(network[ip_index])
Adam Harwellcd72b562018-05-07 11:37:22 -0700485 else:
Adam Harwellcd72b562018-05-07 11:37:22 -0700486 subnet_id = cls.lb_member_vip_ipv6_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700487 if CONF.load_balancer.test_with_noop:
488 lb_vip_address = '2001:db8:33:33:33:33:33:33'
489 else:
490 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
491 network = ipaddress.IPv6Network(subnet['subnet']['cidr'])
492 lb_vip_address = str(network[ip_index])
Michael Johnson590fbe12019-07-03 14:30:01 -0700493 # If the subnet is IPv6 slaac or dhcpv6-stateless
494 # neutron does not allow a fixed IP
495 if not cls.lb_member_vip_ipv6_subnet_stateful:
496 use_fixed_ip = False
Adam Harwellcd72b562018-05-07 11:37:22 -0700497 lb_kwargs[const.VIP_SUBNET_ID] = subnet_id
Michael Johnson07c9a632018-06-07 13:27:42 -0700498 if use_fixed_ip:
499 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700500 if CONF.load_balancer.test_with_noop:
501 lb_kwargs[const.VIP_NETWORK_ID] = (
502 cls.lb_member_vip_net[const.ID])
Carlos Goncalvesbb238552020-01-15 10:10:55 +0000503 if ip_version == 6:
504 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700505 else:
506 lb_kwargs[const.VIP_NETWORK_ID] = cls.lb_member_vip_net[const.ID]
507 lb_kwargs[const.VIP_SUBNET_ID] = None
508
509
510class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest):
511 @classmethod
512 def resource_setup(cls):
513 super(LoadBalancerBaseTestWithCompute, cls).resource_setup()
514 # If validation is disabled in this cloud, we won't be able to
515 # start the webservers, so don't even boot them.
516 if not CONF.validation.run_validation:
517 return
518
519 # Create a keypair for the webservers
520 keypair_name = data_utils.rand_name('lb_member_keypair')
521 result = cls.lb_mem_keypairs_client.create_keypair(
522 name=keypair_name)
523 cls.lb_member_keypair = result['keypair']
524 LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair))
525 cls.addClassResourceCleanup(
526 waiters.wait_for_not_found,
527 cls.lb_mem_keypairs_client.delete_keypair,
528 cls.lb_mem_keypairs_client.show_keypair,
529 keypair_name)
530
531 if (CONF.load_balancer.enable_security_groups and
532 CONF.network_feature_enabled.port_security):
533 # Set up the security group for the webservers
534 SG_name = data_utils.rand_name('lb_member_SG')
535 cls.lb_member_sec_group = (
536 cls.lb_mem_SG_client.create_security_group(
537 name=SG_name)['security_group'])
538 cls.addClassResourceCleanup(
539 waiters.wait_for_not_found,
540 cls.lb_mem_SG_client.delete_security_group,
541 cls.lb_mem_SG_client.show_security_group,
542 cls.lb_member_sec_group['id'])
543
544 # Create a security group rule to allow 80-81 (test webservers)
545 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
546 direction='ingress',
547 security_group_id=cls.lb_member_sec_group['id'],
548 protocol='tcp',
549 ethertype='IPv4',
550 port_range_min=80,
551 port_range_max=81)['security_group_rule']
552 cls.addClassResourceCleanup(
553 waiters.wait_for_not_found,
554 cls.lb_mem_SGr_client.delete_security_group_rule,
555 cls.lb_mem_SGr_client.show_security_group_rule,
556 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200557 # Create a security group rule to allow UDP 80-81 (test webservers)
558 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
559 direction='ingress',
560 security_group_id=cls.lb_member_sec_group['id'],
561 protocol='udp',
562 ethertype='IPv4',
563 port_range_min=80,
564 port_range_max=81)['security_group_rule']
565 cls.addClassResourceCleanup(
566 waiters.wait_for_not_found,
567 cls.lb_mem_SGr_client.delete_security_group_rule,
568 cls.lb_mem_SGr_client.show_security_group_rule,
569 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700570 # Create a security group rule to allow 443 (test webservers)
571 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
572 direction='ingress',
573 security_group_id=cls.lb_member_sec_group['id'],
574 protocol='tcp',
575 ethertype='IPv4',
576 port_range_min=443,
577 port_range_max=443)['security_group_rule']
578 cls.addClassResourceCleanup(
579 waiters.wait_for_not_found,
580 cls.lb_mem_SGr_client.delete_security_group_rule,
581 cls.lb_mem_SGr_client.show_security_group_rule,
582 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200583 # Create a security group rule to allow UDP 9999 (test webservers)
584 # Port 9999 is used to illustrate health monitor ERRORs on closed
585 # ports.
586 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
587 direction='ingress',
588 security_group_id=cls.lb_member_sec_group['id'],
589 protocol='udp',
590 ethertype='IPv4',
591 port_range_min=9999,
592 port_range_max=9999)['security_group_rule']
593 cls.addClassResourceCleanup(
594 waiters.wait_for_not_found,
595 cls.lb_mem_SGr_client.delete_security_group_rule,
596 cls.lb_mem_SGr_client.show_security_group_rule,
597 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700598 # Create a security group rule to allow 22 (ssh)
599 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
600 direction='ingress',
601 security_group_id=cls.lb_member_sec_group['id'],
602 protocol='tcp',
603 ethertype='IPv4',
604 port_range_min=22,
605 port_range_max=22)['security_group_rule']
606 cls.addClassResourceCleanup(
607 waiters.wait_for_not_found,
608 cls.lb_mem_SGr_client.delete_security_group_rule,
609 cls.lb_mem_SGr_client.show_security_group_rule,
610 SGr['id'])
611 if CONF.load_balancer.test_with_ipv6:
612 # Create a security group rule to allow 80-81 (test webservers)
613 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
614 direction='ingress',
615 security_group_id=cls.lb_member_sec_group['id'],
616 protocol='tcp',
617 ethertype='IPv6',
618 port_range_min=80,
619 port_range_max=81)['security_group_rule']
620 cls.addClassResourceCleanup(
621 waiters.wait_for_not_found,
622 cls.lb_mem_SGr_client.delete_security_group_rule,
623 cls.lb_mem_SGr_client.show_security_group_rule,
624 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200625 # Create a security group rule to allow UDP 80-81 (test
626 # webservers)
627 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
628 direction='ingress',
629 security_group_id=cls.lb_member_sec_group['id'],
630 protocol='udp',
631 ethertype='IPv6',
632 port_range_min=80,
633 port_range_max=81)['security_group_rule']
634 cls.addClassResourceCleanup(
635 waiters.wait_for_not_found,
636 cls.lb_mem_SGr_client.delete_security_group_rule,
637 cls.lb_mem_SGr_client.show_security_group_rule,
638 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700639 # Create a security group rule to allow 443 (test webservers)
640 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
641 direction='ingress',
642 security_group_id=cls.lb_member_sec_group['id'],
643 protocol='tcp',
644 ethertype='IPv6',
645 port_range_min=443,
646 port_range_max=443)['security_group_rule']
647 cls.addClassResourceCleanup(
648 waiters.wait_for_not_found,
649 cls.lb_mem_SGr_client.delete_security_group_rule,
650 cls.lb_mem_SGr_client.show_security_group_rule,
651 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700652 # Create a security group rule to allow 22 (ssh)
653 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
654 direction='ingress',
655 security_group_id=cls.lb_member_sec_group['id'],
656 protocol='tcp',
657 ethertype='IPv6',
658 port_range_min=22,
659 port_range_max=22)['security_group_rule']
660 cls.addClassResourceCleanup(
661 waiters.wait_for_not_found,
662 cls.lb_mem_SGr_client.delete_security_group_rule,
663 cls.lb_mem_SGr_client.show_security_group_rule,
664 SGr['id'])
665
666 LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group))
667
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700668 # Setup backend member reencryption PKI
669 cls._create_backend_reencryption_pki()
670
Adam Harwellcd72b562018-05-07 11:37:22 -0700671 # Create webserver 1 instance
672 server_details = cls._create_webserver('lb_member_webserver1',
673 cls.lb_member_1_net)
674
675 cls.lb_member_webserver1 = server_details['server']
676 cls.webserver1_ip = server_details.get('ipv4_address')
677 cls.webserver1_ipv6 = server_details.get('ipv6_address')
678 cls.webserver1_public_ip = server_details['public_ipv4_address']
679
680 LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format(
681 cls.lb_member_webserver1[const.ID]))
682 LOG.debug('Octavia Setup: webserver1_ip = {}'.format(
683 cls.webserver1_ip))
684 LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format(
685 cls.webserver1_ipv6))
686 LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format(
687 cls.webserver1_public_ip))
688
689 # Create webserver 2 instance
690 server_details = cls._create_webserver('lb_member_webserver2',
691 cls.lb_member_2_net)
692
693 cls.lb_member_webserver2 = server_details['server']
694 cls.webserver2_ip = server_details.get('ipv4_address')
695 cls.webserver2_ipv6 = server_details.get('ipv6_address')
696 cls.webserver2_public_ip = server_details['public_ipv4_address']
697
698 LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format(
699 cls.lb_member_webserver2[const.ID]))
700 LOG.debug('Octavia Setup: webserver2_ip = {}'.format(
701 cls.webserver2_ip))
702 LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format(
703 cls.webserver2_ipv6))
704 LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format(
705 cls.webserver2_public_ip))
706
Michael Johnsonbf916df2018-10-17 10:59:28 -0700707 if CONF.load_balancer.test_with_ipv6:
708 # Enable the IPv6 nic in webserver 1
709 cls._enable_ipv6_nic_webserver(
710 cls.webserver1_public_ip, cls.lb_member_keypair['private_key'],
711 cls.webserver1_ipv6, cls.lb_member_1_subnet_prefix)
712
713 # Enable the IPv6 nic in webserver 2
714 cls._enable_ipv6_nic_webserver(
715 cls.webserver2_public_ip, cls.lb_member_keypair['private_key'],
716 cls.webserver2_ipv6, cls.lb_member_2_subnet_prefix)
717
Adam Harwellcd72b562018-05-07 11:37:22 -0700718 # Set up serving on webserver 1
719 cls._install_start_webserver(cls.webserver1_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700720 cls.lb_member_keypair['private_key'],
721 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700722
723 # Validate webserver 1
Adam Harwelle029af22018-05-24 17:13:28 -0700724 cls._validate_webserver(cls.webserver1_public_ip,
725 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700726
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200727 # Validate udp server 1
728 cls._validate_udp_server(cls.webserver1_public_ip,
729 cls.webserver1_response)
730
Adam Harwellcd72b562018-05-07 11:37:22 -0700731 # Set up serving on webserver 2
732 cls._install_start_webserver(cls.webserver2_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700733 cls.lb_member_keypair['private_key'],
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700734 cls.webserver2_response, revoke_cert=True)
Adam Harwellcd72b562018-05-07 11:37:22 -0700735
736 # Validate webserver 2
Adam Harwelle029af22018-05-24 17:13:28 -0700737 cls._validate_webserver(cls.webserver2_public_ip,
738 cls.webserver2_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700739
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200740 # Validate udp server 2
741 cls._validate_udp_server(cls.webserver2_public_ip,
742 cls.webserver2_response)
743
Adam Harwellcd72b562018-05-07 11:37:22 -0700744 @classmethod
745 def _create_networks(cls):
746 super(LoadBalancerBaseTestWithCompute, cls)._create_networks()
Jude Cross986e3f52017-07-24 14:57:20 -0700747 # Create a router for the subnets (required for the floating IP)
748 router_name = data_utils.rand_name("lb_member_router")
749 result = cls.lb_mem_routers_client.create_router(
750 name=router_name, admin_state_up=True,
751 external_gateway_info=dict(
752 network_id=CONF.network.public_network_id))
753 cls.lb_member_router = result['router']
754 LOG.info('lb_member_router: {}'.format(cls.lb_member_router))
755 cls.addClassResourceCleanup(
756 waiters.wait_for_not_found,
757 cls.lb_mem_routers_client.delete_router,
758 cls.lb_mem_routers_client.show_router,
759 cls.lb_member_router['id'])
760
761 # Add VIP subnet to router
762 cls.lb_mem_routers_client.add_router_interface(
763 cls.lb_member_router['id'],
764 subnet_id=cls.lb_member_vip_subnet['id'])
765 cls.addClassResourceCleanup(
766 waiters.wait_for_not_found,
767 cls.lb_mem_routers_client.remove_router_interface,
768 cls.lb_mem_routers_client.remove_router_interface,
769 cls.lb_member_router['id'],
770 subnet_id=cls.lb_member_vip_subnet['id'])
771
772 # Add member subnet 1 to router
773 cls.lb_mem_routers_client.add_router_interface(
774 cls.lb_member_router['id'],
775 subnet_id=cls.lb_member_1_subnet['id'])
776 cls.addClassResourceCleanup(
777 waiters.wait_for_not_found,
Jude Cross986e3f52017-07-24 14:57:20 -0700778 cls.lb_mem_routers_client.remove_router_interface,
779 cls.lb_mem_routers_client.remove_router_interface,
780 cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id'])
781
782 # Add member subnet 2 to router
783 cls.lb_mem_routers_client.add_router_interface(
784 cls.lb_member_router['id'],
785 subnet_id=cls.lb_member_2_subnet['id'])
786 cls.addClassResourceCleanup(
787 waiters.wait_for_not_found,
788 cls.lb_mem_routers_client.remove_router_interface,
789 cls.lb_mem_routers_client.remove_router_interface,
790 cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id'])
791
792 @classmethod
793 def _create_webserver(cls, name, network):
794 """Creates a webserver with two ports.
795
796 webserver_details dictionary contains:
797 server - The compute server object
798 ipv4_address - The IPv4 address for the server (optional)
799 ipv6_address - The IPv6 address for the server (optional)
800 public_ipv4_address - The publicly accessible IPv4 address for the
801 server, this may be a floating IP (optional)
802
803 :param name: The name of the server to create.
804 :param network: The network to boot the server on.
805 :returns: webserver_details dictionary.
806 """
807 server_kwargs = {
808 'name': data_utils.rand_name(name),
809 'flavorRef': CONF.compute.flavor_ref,
810 'imageRef': CONF.compute.image_ref,
811 'key_name': cls.lb_member_keypair['name']}
812 if (CONF.load_balancer.enable_security_groups and
813 CONF.network_feature_enabled.port_security):
814 server_kwargs['security_groups'] = [
815 {'name': cls.lb_member_sec_group['name']}]
816 if not CONF.load_balancer.disable_boot_network:
817 server_kwargs['networks'] = [{'uuid': network['id']}]
818
819 # Replace the name for clouds that have limitations
820 if CONF.load_balancer.random_server_name_length:
821 r = random.SystemRandom()
822 server_kwargs['name'] = "m{}".format("".join(
823 [r.choice(string.ascii_uppercase + string.digits)
824 for _ in range(
825 CONF.load_balancer.random_server_name_length - 1)]
826 ))
827 if CONF.load_balancer.availability_zone:
828 server_kwargs['availability_zone'] = (
829 CONF.load_balancer.availability_zone)
830
831 server = cls.lb_mem_servers_client.create_server(
832 **server_kwargs)['server']
833 cls.addClassResourceCleanup(
834 waiters.wait_for_not_found,
835 cls.lb_mem_servers_client.delete_server,
836 cls.lb_mem_servers_client.show_server,
837 server['id'])
838 server = waiters.wait_for_status(
839 cls.lb_mem_servers_client.show_server,
840 server['id'], 'status', 'ACTIVE',
841 CONF.load_balancer.build_interval,
842 CONF.load_balancer.build_timeout,
843 root_tag='server')
844 webserver_details = {'server': server}
845 LOG.info('Created server: {}'.format(server))
846
847 addresses = server['addresses']
848 if CONF.load_balancer.disable_boot_network:
849 instance_network = addresses.values()[0]
850 else:
851 instance_network = addresses[network['name']]
852 for addr in instance_network:
853 if addr['version'] == 4:
854 webserver_details['ipv4_address'] = addr['addr']
855 if addr['version'] == 6:
856 webserver_details['ipv6_address'] = addr['addr']
857
858 if CONF.validation.connect_method == 'floating':
859 result = cls.lb_mem_ports_client.list_ports(
860 network_id=network['id'],
861 mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr'])
862 port_id = result['ports'][0]['id']
863 result = cls.lb_mem_float_ip_client.create_floatingip(
864 floating_network_id=CONF.network.public_network_id,
865 port_id=port_id)
866 floating_ip = result['floatingip']
867 LOG.info('webserver1_floating_ip: {}'.format(floating_ip))
868 cls.addClassResourceCleanup(
869 waiters.wait_for_not_found,
870 cls.lb_mem_float_ip_client.delete_floatingip,
871 cls.lb_mem_float_ip_client.show_floatingip,
872 floatingip_id=floating_ip['id'])
873 webserver_details['public_ipv4_address'] = (
874 floating_ip['floating_ip_address'])
875 else:
876 webserver_details['public_ipv4_address'] = (
877 instance_network[0]['addr'])
878
879 return webserver_details
880
881 @classmethod
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700882 def _install_start_webserver(cls, ip_address, ssh_key, start_id,
883 revoke_cert=False):
Michael Johnson27357352020-11-13 13:55:09 -0800884 local_file = CONF.load_balancer.test_server_path
Adam Harwellcd72b562018-05-07 11:37:22 -0700885
886 linux_client = remote_client.RemoteClient(
887 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key)
888 linux_client.validate_authentication()
889
890 with tempfile.NamedTemporaryFile() as key:
891 key.write(ssh_key.encode('utf-8'))
892 key.flush()
893 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
894 "-o StrictHostKeyChecking=no "
895 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
896 "-i {2} {3} {4}@{5}:{6}").format(
897 CONF.load_balancer.scp_connection_timeout,
898 CONF.load_balancer.scp_connection_attempts,
899 key.name, local_file, CONF.validation.image_ssh_user,
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700900 ip_address, const.TEST_SERVER_BINARY)
Adam Harwellcd72b562018-05-07 11:37:22 -0700901 args = shlex.split(cmd)
902 subprocess_args = {'stdout': subprocess.PIPE,
903 'stderr': subprocess.STDOUT,
904 'cwd': None}
905 proc = subprocess.Popen(args, **subprocess_args)
906 stdout, stderr = proc.communicate()
907 if proc.returncode != 0:
908 raise exceptions.CommandFailed(proc.returncode, cmd,
909 stdout, stderr)
Gregory Thiemongef72a8862019-08-06 17:25:42 +0200910
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700911 cls._load_member_pki_content(ip_address, key,
912 revoke_cert=revoke_cert)
913
Gregory Thiemongef72a8862019-08-06 17:25:42 +0200914 # Enabling memory overcommit allows to run golang static binaries
915 # compiled with a recent golang toolchain (>=1.11). Those binaries
916 # allocate a large amount of virtual memory at init time, and this
917 # allocation fails in tempest's nano flavor (64MB of RAM)
918 # (golang issue reported in https://github.com/golang/go/issues/28114,
919 # follow-up: https://github.com/golang/go/issues/28081)
920 # TODO(gthiemonge): Remove this call when golang issue is resolved.
921 linux_client.exec_command('sudo sh -c "echo 1 > '
922 '/proc/sys/vm/overcommit_memory"')
923
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700924 # The initial process also supports HTTPS and HTTPS with client auth
925 linux_client.exec_command(
926 'sudo screen -d -m {0} -port 80 -id {1} -https_port 443 -cert {2} '
927 '-key {3} -https_client_auth_port 9443 -client_ca {4}'.format(
928 const.TEST_SERVER_BINARY, start_id, const.TEST_SERVER_CERT,
929 const.TEST_SERVER_KEY, const.TEST_SERVER_CLIENT_CA))
930
Adam Harwellcd72b562018-05-07 11:37:22 -0700931 linux_client.exec_command('sudo screen -d -m {0} -port 81 '
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700932 '-id {1}'.format(const.TEST_SERVER_BINARY,
933 start_id + 1))
Adam Harwellcd72b562018-05-07 11:37:22 -0700934
Michael Johnsonbf916df2018-10-17 10:59:28 -0700935 # Cirros does not configure the assigned IPv6 address by default
936 # so enable it manually like tempest does here:
937 # tempest/scenario/test_netowrk_v6.py turn_nic6_on()
938 @classmethod
939 def _enable_ipv6_nic_webserver(cls, ip_address, ssh_key,
940 ipv6_address, ipv6_prefix):
941 linux_client = remote_client.RemoteClient(
942 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key)
943 linux_client.validate_authentication()
944
945 linux_client.exec_command('sudo ip address add {0}/{1} dev '
946 'eth0'.format(ipv6_address, ipv6_prefix))
947
Adam Harwellcd72b562018-05-07 11:37:22 -0700948 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -0700949 def _validate_webserver(cls, ip_address, start_id):
950 URL = 'http://{0}'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -0700951 cls.validate_URL_response(URL, expected_body=str(start_id))
Jude Cross986e3f52017-07-24 14:57:20 -0700952 URL = 'http://{0}:81'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -0700953 cls.validate_URL_response(URL, expected_body=str(start_id + 1))
Jude Cross986e3f52017-07-24 14:57:20 -0700954
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200955 @classmethod
956 def _validate_udp_server(cls, ip_address, start_id):
Michael Johnson89bdbcd2020-03-19 15:59:19 -0700957 res = cls.make_udp_request(ip_address, 80)
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200958 if res != str(start_id):
959 raise Exception("Response from test server doesn't match the "
960 "expected value ({0} != {1}).".format(
961 res, str(start_id)))
962
Michael Johnson89bdbcd2020-03-19 15:59:19 -0700963 res = cls.make_udp_request(ip_address, 81)
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200964 if res != str(start_id + 1):
965 raise Exception("Response from test server doesn't match the "
966 "expected value ({0} != {1}).".format(
967 res, str(start_id + 1)))
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700968
969 @classmethod
970 def _create_backend_reencryption_pki(cls):
971 # Create a CA self-signed cert and key for the member test servers
972 cls.member_ca_cert, cls.member_ca_key = (
973 cert_utils.generate_ca_cert_and_key())
974
975 LOG.debug('Member CA Cert: %s', cls.member_ca_cert.public_bytes(
976 serialization.Encoding.PEM))
977 LOG.debug('Member CA private Key: %s', cls.member_ca_key.private_bytes(
978 encoding=serialization.Encoding.PEM,
979 format=serialization.PrivateFormat.TraditionalOpenSSL,
980 encryption_algorithm=serialization.NoEncryption()))
981 LOG.debug('Member CA public Key: %s',
982 cls.member_ca_key.public_key().public_bytes(
983 encoding=serialization.Encoding.PEM,
984 format=serialization.PublicFormat.SubjectPublicKeyInfo))
985
986 # Create the member client authentication CA
987 cls.member_client_ca_cert, member_client_ca_key = (
988 cert_utils.generate_ca_cert_and_key())
989
990 # Create client cert and key
991 cls.member_client_cn = uuidutils.generate_uuid()
992 cls.member_client_cert, cls.member_client_key = (
993 cert_utils.generate_client_cert_and_key(
994 cls.member_client_ca_cert, member_client_ca_key,
995 cls.member_client_cn))
996 # Note: We are not revoking a client cert here as we don't need to
997 # test the backend web server CRL checking.
998
999 @classmethod
1000 def _load_member_pki_content(cls, ip_address, ssh_key, revoke_cert=False):
1001 # Create webserver certificate and key
1002 cert, key = cert_utils.generate_server_cert_and_key(
1003 cls.member_ca_cert, cls.member_ca_key, ip_address)
1004
1005 LOG.debug('%s Cert: %s', ip_address, cert.public_bytes(
1006 serialization.Encoding.PEM))
1007 LOG.debug('%s private Key: %s', ip_address, key.private_bytes(
1008 encoding=serialization.Encoding.PEM,
1009 format=serialization.PrivateFormat.TraditionalOpenSSL,
1010 encryption_algorithm=serialization.NoEncryption()))
1011 public_key = key.public_key()
1012 LOG.debug('%s public Key: %s', ip_address, public_key.public_bytes(
1013 encoding=serialization.Encoding.PEM,
1014 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1015
1016 # Create a CRL with a revoked certificate
1017 if revoke_cert:
1018 # Create a CRL with webserver 2 revoked
1019 cls.member_crl = cert_utils.generate_certificate_revocation_list(
1020 cls.member_ca_cert, cls.member_ca_key, cert)
1021
1022 # Load the certificate, key, and client CA certificate into the
1023 # test server.
1024 with tempfile.TemporaryDirectory() as tmpdir:
1025 os.umask(0)
1026 files_to_send = []
1027 cert_filename = os.path.join(tmpdir, const.CERT_PEM)
1028 files_to_send.append(cert_filename)
1029 with open(os.open(cert_filename, os.O_CREAT | os.O_WRONLY,
1030 0o700), 'w') as fh:
1031 fh.write(cert.public_bytes(
1032 serialization.Encoding.PEM).decode('utf-8'))
1033 fh.flush()
1034 key_filename = os.path.join(tmpdir, const.KEY_PEM)
1035 files_to_send.append(key_filename)
1036 with open(os.open(key_filename, os.O_CREAT | os.O_WRONLY,
1037 0o700), 'w') as fh:
1038 fh.write(key.private_bytes(
1039 encoding=serialization.Encoding.PEM,
1040 format=serialization.PrivateFormat.TraditionalOpenSSL,
1041 encryption_algorithm=serialization.NoEncryption()).decode(
1042 'utf-8'))
1043 fh.flush()
1044 client_ca_filename = os.path.join(tmpdir, const.CLIENT_CA_PEM)
1045 files_to_send.append(client_ca_filename)
1046 with open(os.open(client_ca_filename, os.O_CREAT | os.O_WRONLY,
1047 0o700), 'w') as fh:
1048 fh.write(cls.member_client_ca_cert.public_bytes(
1049 serialization.Encoding.PEM).decode('utf-8'))
1050 fh.flush()
1051
1052 # For security, we don't want to use a shell that can glob
1053 # the file names, so iterate over them.
1054 subprocess_args = {'stdout': subprocess.PIPE,
1055 'stderr': subprocess.STDOUT,
1056 'cwd': None}
1057 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
1058 "-o StrictHostKeyChecking=no "
1059 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1060 "-i {2} {3} {4} {5} {6}@{7}:{8}").format(
1061 CONF.load_balancer.scp_connection_timeout,
1062 CONF.load_balancer.scp_connection_attempts,
1063 ssh_key.name, cert_filename, key_filename, client_ca_filename,
1064 CONF.validation.image_ssh_user, ip_address, const.DEV_SHM_PATH)
1065 args = shlex.split(cmd)
1066 proc = subprocess.Popen(args, **subprocess_args)
1067 stdout, stderr = proc.communicate()
1068 if proc.returncode != 0:
1069 raise exceptions.CommandFailed(proc.returncode, cmd,
1070 stdout, stderr)