blob: e1daec1bc4e91f5f3928b6816ae398f1cb868740 [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
Gregory Thiemongea2c234e2021-11-02 17:08:29 +010018import re
Jude Cross986e3f52017-07-24 14:57:20 -070019import shlex
Jude Cross986e3f52017-07-24 14:57:20 -070020import string
21import subprocess
22import tempfile
23
Michael Johnsonbaf12e02020-10-27 16:10:28 -070024from cryptography.hazmat.primitives import serialization
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +010025from oslo_config import cfg
Jude Cross986e3f52017-07-24 14:57:20 -070026from 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
Michael Johnsonbaf12e02020-10-27 16:10:28 -070035from octavia_tempest_plugin.common import cert_utils
Jude Cross986e3f52017-07-24 14:57:20 -070036from octavia_tempest_plugin.common import constants as const
Michael Johnson6006de72021-02-21 01:42:39 +000037from octavia_tempest_plugin.tests import RBAC_tests
Jude Cross986e3f52017-07-24 14:57:20 -070038from octavia_tempest_plugin.tests import validators
39from octavia_tempest_plugin.tests import waiters
40
41CONF = config.CONF
42LOG = logging.getLogger(__name__)
43
Michael Johnson04dc5cb2019-01-20 11:03:50 -080044RETRY_ATTEMPTS = 15
45RETRY_INITIAL_DELAY = 1
46RETRY_BACKOFF = 1
47RETRY_MAX = 5
48
Gregory Thiemonge29d17902019-04-30 15:06:17 +020049
Michael Johnson6006de72021-02-21 01:42:39 +000050class LoadBalancerBaseTest(validators.ValidatorsMixin,
51 RBAC_tests.RBACTestsMixin, test.BaseTestCase):
Jude Cross986e3f52017-07-24 14:57:20 -070052 """Base class for load balancer tests."""
53
Gregory Thiemonge3497f6c2021-04-19 21:33:13 +020054 if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN:
55 credentials = [
56 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role],
57 ['lb_member', CONF.load_balancer.member_role],
58 ['lb_member2', CONF.load_balancer.member_role]]
Michael Johnson6dac8ff2023-03-09 00:04:37 +000059 elif CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES:
Michael Johnson6006de72021-02-21 01:42:39 +000060 credentials = [
Michael Johnson6dac8ff2023-03-09 00:04:37 +000061 'admin', 'primary',
62 ['lb_admin', CONF.load_balancer.admin_role, 'admin'],
Michael Johnson6006de72021-02-21 01:42:39 +000063 ['lb_observer', CONF.load_balancer.observer_role, 'reader'],
64 ['lb_global_observer', CONF.load_balancer.global_observer_role,
65 'reader'],
66 ['lb_member', CONF.load_balancer.member_role, 'member'],
67 ['lb_member2', CONF.load_balancer.member_role, 'member'],
68 ['lb_member_not_default_member', CONF.load_balancer.member_role]]
69 else:
70 credentials = [
71 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role],
72 ['lb_observer', CONF.load_balancer.observer_role, 'reader'],
73 ['lb_global_observer', CONF.load_balancer.global_observer_role,
74 'reader'],
Michael Johnson9e9f5262023-01-18 17:59:17 +000075 # Note: Some projects are now requiring the 'member' role by
76 # default (nova for example) so make sure our creds have this role
77 ['lb_member', CONF.load_balancer.member_role, 'member'],
78 ['lb_member2', CONF.load_balancer.member_role, 'member']]
Michael Johnson6006de72021-02-21 01:42:39 +000079
80 # If scope enforcement is enabled, add in the system scope credentials.
81 # The project scope is already handled by the above credentials.
82 if CONF.enforce_scope.octavia:
83 credentials.extend(['system_admin', 'system_reader'])
84
85 # A tuple of credentials that will be allocated by tempest using the
86 # 'credentials' list above. These are used to build RBAC test lists.
87 allocated_creds = []
88 for cred in credentials:
89 if isinstance(cred, list):
90 allocated_creds.append('os_roles_' + cred[0])
91 else:
92 allocated_creds.append('os_' + cred)
93 # Tests shall not mess with the list of allocated credentials
94 allocated_credentials = tuple(allocated_creds)
Jude Cross986e3f52017-07-24 14:57:20 -070095
Adam Harwelle029af22018-05-24 17:13:28 -070096 webserver1_response = 1
97 webserver2_response = 5
Michael Johnsondfd818a2018-08-21 20:54:54 -070098 used_ips = []
Jude Cross986e3f52017-07-24 14:57:20 -070099
Michael Johnson89bdbcd2020-03-19 15:59:19 -0700100 SRC_PORT_NUMBER_MIN = 32768
101 SRC_PORT_NUMBER_MAX = 61000
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200102 src_port_number = SRC_PORT_NUMBER_MIN
103
Jude Cross986e3f52017-07-24 14:57:20 -0700104 @classmethod
105 def skip_checks(cls):
106 """Check if we should skip all of the children tests."""
107 super(LoadBalancerBaseTest, cls).skip_checks()
108
109 service_list = {
110 'load_balancer': CONF.service_available.load_balancer,
111 }
112
113 live_service_list = {
114 'compute': CONF.service_available.nova,
115 'image': CONF.service_available.glance,
116 'neutron': CONF.service_available.neutron
117 }
118
119 if not CONF.load_balancer.test_with_noop:
120 service_list.update(live_service_list)
121
122 for service, available in service_list.items():
123 if not available:
zhangzs2a6cf672018-11-10 16:13:11 +0800124 skip_msg = ("{0} skipped as {1} service is not "
Jude Cross986e3f52017-07-24 14:57:20 -0700125 "available.".format(cls.__name__, service))
126 raise cls.skipException(skip_msg)
127
128 # We must be able to reach our VIP and instances
129 if not (CONF.network.project_networks_reachable
130 or CONF.network.public_network_id):
131 msg = ('Either project_networks_reachable must be "true", or '
132 'public_network_id must be defined.')
133 raise cls.skipException(msg)
134
135 @classmethod
136 def setup_credentials(cls):
137 """Setup test credentials and network resources."""
138 # Do not auto create network resources
139 cls.set_network_resources()
140 super(LoadBalancerBaseTest, cls).setup_credentials()
141
Bas de Bruijne530a88a2022-12-15 11:12:45 -0400142 if not CONF.load_balancer.log_user_roles:
143 return
144
Michael Johnson6006de72021-02-21 01:42:39 +0000145 # Log the user roles for this test run
146 role_name_cache = {}
147 for cred in cls.credentials:
148 user_roles = []
149 if isinstance(cred, list):
150 user_name = cred[0]
151 cred_obj = getattr(cls, 'os_roles_' + cred[0])
152 else:
153 user_name = cred
154 cred_obj = getattr(cls, 'os_' + cred)
155 params = {'user.id': cred_obj.credentials.user_id,
156 'project.id': cred_obj.credentials.project_id}
157 roles = cls.os_admin.role_assignments_client.list_role_assignments(
158 **params)['role_assignments']
159 for role in roles:
160 role_id = role['role']['id']
161 try:
162 role_name = role_name_cache[role_id]
163 except KeyError:
164 role_name = cls.os_admin.roles_v3_client.show_role(
165 role_id)['role']['name']
166 role_name_cache[role_id] = role_name
167 user_roles.append([role_name, role['scope']])
168 LOG.info("User %s has roles: %s", user_name, user_roles)
169
Jude Cross986e3f52017-07-24 14:57:20 -0700170 @classmethod
171 def setup_clients(cls):
172 """Setup client aliases."""
173 super(LoadBalancerBaseTest, cls).setup_clients()
Michael Johnson29d8e612021-06-23 16:16:12 +0000174 lb_admin_prefix = cls.os_roles_lb_admin.load_balancer_v2
Jude Cross986e3f52017-07-24 14:57:20 -0700175 cls.lb_mem_float_ip_client = cls.os_roles_lb_member.floating_ips_client
176 cls.lb_mem_keypairs_client = cls.os_roles_lb_member.keypairs_client
177 cls.lb_mem_net_client = cls.os_roles_lb_member.networks_client
178 cls.lb_mem_ports_client = cls.os_roles_lb_member.ports_client
179 cls.lb_mem_routers_client = cls.os_roles_lb_member.routers_client
180 cls.lb_mem_SG_client = cls.os_roles_lb_member.security_groups_client
181 cls.lb_mem_SGr_client = (
182 cls.os_roles_lb_member.security_group_rules_client)
183 cls.lb_mem_servers_client = cls.os_roles_lb_member.servers_client
184 cls.lb_mem_subnet_client = cls.os_roles_lb_member.subnets_client
Michael Johnson29d8e612021-06-23 16:16:12 +0000185 cls.mem_lb_client = (
186 cls.os_roles_lb_member.load_balancer_v2.LoadbalancerClient())
187 cls.mem_listener_client = (
188 cls.os_roles_lb_member.load_balancer_v2.ListenerClient())
189 cls.mem_pool_client = (
190 cls.os_roles_lb_member.load_balancer_v2.PoolClient())
191 cls.mem_member_client = (
192 cls.os_roles_lb_member.load_balancer_v2.MemberClient())
Adam Harwell60ed9d92018-05-10 13:23:13 -0700193 cls.mem_healthmonitor_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000194 cls.os_roles_lb_member.load_balancer_v2.HealthMonitorClient())
195 cls.mem_l7policy_client = (
196 cls.os_roles_lb_member.load_balancer_v2.L7PolicyClient())
197 cls.mem_l7rule_client = (
198 cls.os_roles_lb_member.load_balancer_v2.L7RuleClient())
199 cls.lb_admin_amphora_client = lb_admin_prefix.AmphoraClient()
Michael Johnsonaff2e862019-01-11 16:38:00 -0800200 cls.lb_admin_flavor_profile_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000201 lb_admin_prefix.FlavorProfileClient())
202 cls.lb_admin_flavor_client = lb_admin_prefix.FlavorClient()
203 cls.mem_flavor_client = (
204 cls.os_roles_lb_member.load_balancer_v2.FlavorClient())
205 cls.mem_provider_client = (
206 cls.os_roles_lb_member.load_balancer_v2.ProviderClient())
Carlos Goncalvesc2e12162019-02-14 23:57:44 +0100207 cls.os_admin_servers_client = cls.os_admin.servers_client
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100208 cls.os_admin_routers_client = cls.os_admin.routers_client
209 cls.os_admin_subnetpools_client = cls.os_admin.subnetpools_client
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800210 cls.lb_admin_flavor_capabilities_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000211 lb_admin_prefix.FlavorCapabilitiesClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800212 cls.lb_admin_availability_zone_capabilities_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000213 lb_admin_prefix.AvailabilityZoneCapabilitiesClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800214 cls.lb_admin_availability_zone_profile_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000215 lb_admin_prefix.AvailabilityZoneProfileClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800216 cls.lb_admin_availability_zone_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000217 lb_admin_prefix.AvailabilityZoneClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800218 cls.mem_availability_zone_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000219 cls.os_roles_lb_member.load_balancer_v2.AvailabilityZoneClient())
Jude Cross986e3f52017-07-24 14:57:20 -0700220
221 @classmethod
222 def resource_setup(cls):
223 """Setup resources needed by the tests."""
224 super(LoadBalancerBaseTest, cls).resource_setup()
225
226 conf_lb = CONF.load_balancer
227
Michael Johnsondfd818a2018-08-21 20:54:54 -0700228 cls.api_version = cls.mem_lb_client.get_max_api_version()
229
Jude Cross986e3f52017-07-24 14:57:20 -0700230 if conf_lb.test_subnet_override and not conf_lb.test_network_override:
231 raise exceptions.InvalidConfiguration(
232 "Configuration value test_network_override must be "
233 "specified if test_subnet_override is used.")
234
Michael Johnson6a9236a2020-08-04 23:54:54 +0000235 # TODO(johnsom) Remove this
Maciej Józefczykb6df5f82019-12-10 10:12:30 +0000236 # Get loadbalancing algorithms supported by provider driver.
237 try:
238 algorithms = const.SUPPORTED_LB_ALGORITHMS[
239 CONF.load_balancer.provider]
240 except KeyError:
241 algorithms = const.SUPPORTED_LB_ALGORITHMS['default']
242 # Set default algorithm as first from the list.
243 cls.lb_algorithm = algorithms[0]
244
Jude Cross986e3f52017-07-24 14:57:20 -0700245 show_subnet = cls.lb_mem_subnet_client.show_subnet
246 if CONF.load_balancer.test_with_noop:
247 cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()}
248 cls.lb_member_vip_subnet = {'id': uuidutils.generate_uuid()}
249 cls.lb_member_1_net = {'id': uuidutils.generate_uuid()}
250 cls.lb_member_1_subnet = {'id': uuidutils.generate_uuid()}
251 cls.lb_member_2_net = {'id': uuidutils.generate_uuid()}
252 cls.lb_member_2_subnet = {'id': uuidutils.generate_uuid()}
253 if CONF.load_balancer.test_with_ipv6:
Michael Johnson5a16ad32018-10-18 14:49:11 -0700254 cls.lb_member_vip_ipv6_net = {'id': uuidutils.generate_uuid()}
Jude Cross986e3f52017-07-24 14:57:20 -0700255 cls.lb_member_vip_ipv6_subnet = {'id':
256 uuidutils.generate_uuid()}
257 cls.lb_member_1_ipv6_subnet = {'id': uuidutils.generate_uuid()}
258 cls.lb_member_2_ipv6_subnet = {'id': uuidutils.generate_uuid()}
Michael Johnson590fbe12019-07-03 14:30:01 -0700259 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700260 return
261 elif CONF.load_balancer.test_network_override:
262 if conf_lb.test_subnet_override:
263 override_subnet = show_subnet(conf_lb.test_subnet_override)
264 else:
265 override_subnet = None
266
267 show_net = cls.lb_mem_net_client.show_network
268 override_network = show_net(conf_lb.test_network_override)
269 override_network = override_network.get('network')
270
271 cls.lb_member_vip_net = override_network
272 cls.lb_member_vip_subnet = override_subnet
273 cls.lb_member_1_net = override_network
274 cls.lb_member_1_subnet = override_subnet
275 cls.lb_member_2_net = override_network
276 cls.lb_member_2_subnet = override_subnet
277
278 if (CONF.load_balancer.test_with_ipv6 and
279 conf_lb.test_IPv6_subnet_override):
280 override_ipv6_subnet = show_subnet(
281 conf_lb.test_IPv6_subnet_override)
282 cls.lb_member_vip_ipv6_subnet = override_ipv6_subnet
283 cls.lb_member_1_ipv6_subnet = override_ipv6_subnet
284 cls.lb_member_2_ipv6_subnet = override_ipv6_subnet
Michael Johnson590fbe12019-07-03 14:30:01 -0700285 cls.lb_member_vip_ipv6_subnet_stateful = False
286 if (override_ipv6_subnet[0]['ipv6_address_mode'] ==
287 'dhcpv6-stateful'):
288 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700289 else:
290 cls.lb_member_vip_ipv6_subnet = None
291 cls.lb_member_1_ipv6_subnet = None
292 cls.lb_member_2_ipv6_subnet = None
293 else:
294 cls._create_networks()
295
296 LOG.debug('Octavia Setup: lb_member_vip_net = {}'.format(
297 cls.lb_member_vip_net[const.ID]))
298 if cls.lb_member_vip_subnet:
299 LOG.debug('Octavia Setup: lb_member_vip_subnet = {}'.format(
300 cls.lb_member_vip_subnet[const.ID]))
301 LOG.debug('Octavia Setup: lb_member_1_net = {}'.format(
302 cls.lb_member_1_net[const.ID]))
303 if cls.lb_member_1_subnet:
304 LOG.debug('Octavia Setup: lb_member_1_subnet = {}'.format(
305 cls.lb_member_1_subnet[const.ID]))
306 LOG.debug('Octavia Setup: lb_member_2_net = {}'.format(
307 cls.lb_member_2_net[const.ID]))
308 if cls.lb_member_2_subnet:
309 LOG.debug('Octavia Setup: lb_member_2_subnet = {}'.format(
310 cls.lb_member_2_subnet[const.ID]))
Michael Johnson124ba8b2018-08-30 16:06:05 -0700311 if CONF.load_balancer.test_with_ipv6:
312 if cls.lb_member_vip_ipv6_subnet:
313 LOG.debug('Octavia Setup: lb_member_vip_ipv6_subnet = '
314 '{}'.format(cls.lb_member_vip_ipv6_subnet[const.ID]))
315 if cls.lb_member_1_ipv6_subnet:
316 LOG.debug('Octavia Setup: lb_member_1_ipv6_subnet = {}'.format(
317 cls.lb_member_1_ipv6_subnet[const.ID]))
318 if cls.lb_member_2_ipv6_subnet:
319 LOG.debug('Octavia Setup: lb_member_2_ipv6_subnet = {}'.format(
320 cls.lb_member_2_ipv6_subnet[const.ID]))
Jude Cross986e3f52017-07-24 14:57:20 -0700321
Jude Cross986e3f52017-07-24 14:57:20 -0700322 @classmethod
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800323 # Neutron can be slow to clean up ports from the subnets/networks.
324 # Retry this delete a few times if we get a "Conflict" error to give
325 # neutron time to fully cleanup the ports.
326 @tenacity.retry(
327 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
328 wait=tenacity.wait_incrementing(
329 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
330 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
331 def _logging_delete_network(cls, net_id):
332 try:
333 cls.lb_mem_net_client.delete_network(net_id)
334 except Exception:
335 LOG.error('Unable to delete network {}. Active ports:'.format(
336 net_id))
337 LOG.error(cls.lb_mem_ports_client.list_ports())
338 raise
339
340 @classmethod
341 # Neutron can be slow to clean up ports from the subnets/networks.
342 # Retry this delete a few times if we get a "Conflict" error to give
343 # neutron time to fully cleanup the ports.
344 @tenacity.retry(
345 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
346 wait=tenacity.wait_incrementing(
347 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
348 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
349 def _logging_delete_subnet(cls, subnet_id):
350 try:
351 cls.lb_mem_subnet_client.delete_subnet(subnet_id)
352 except Exception:
353 LOG.error('Unable to delete subnet {}. Active ports:'.format(
354 subnet_id))
355 LOG.error(cls.lb_mem_ports_client.list_ports())
356 raise
357
358 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -0700359 def _create_networks(cls):
360 """Creates networks, subnets, and routers used in tests.
361
362 The following are expected to be defined and available to the tests:
363 cls.lb_member_vip_net
364 cls.lb_member_vip_subnet
365 cls.lb_member_vip_ipv6_subnet (optional)
366 cls.lb_member_1_net
367 cls.lb_member_1_subnet
368 cls.lb_member_1_ipv6_subnet (optional)
369 cls.lb_member_2_net
370 cls.lb_member_2_subnet
371 cls.lb_member_2_ipv6_subnet (optional)
372 """
373
374 # Create tenant VIP network
375 network_kwargs = {
376 'name': data_utils.rand_name("lb_member_vip_network")}
377 if CONF.network_feature_enabled.port_security:
Andreas Jaeger4215b702020-03-28 20:13:46 +0100378 # Note: Allowed Address Pairs requires port security
379 network_kwargs['port_security_enabled'] = True
Jude Cross986e3f52017-07-24 14:57:20 -0700380 result = cls.lb_mem_net_client.create_network(**network_kwargs)
381 cls.lb_member_vip_net = result['network']
382 LOG.info('lb_member_vip_net: {}'.format(cls.lb_member_vip_net))
383 cls.addClassResourceCleanup(
384 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800385 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700386 cls.lb_mem_net_client.show_network,
387 cls.lb_member_vip_net['id'])
388
389 # Create tenant VIP subnet
390 subnet_kwargs = {
391 'name': data_utils.rand_name("lb_member_vip_subnet"),
392 'network_id': cls.lb_member_vip_net['id'],
393 'cidr': CONF.load_balancer.vip_subnet_cidr,
394 'ip_version': 4}
395 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
396 cls.lb_member_vip_subnet = result['subnet']
397 LOG.info('lb_member_vip_subnet: {}'.format(cls.lb_member_vip_subnet))
398 cls.addClassResourceCleanup(
399 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800400 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700401 cls.lb_mem_subnet_client.show_subnet,
402 cls.lb_member_vip_subnet['id'])
403
404 # Create tenant VIP IPv6 subnet
405 if CONF.load_balancer.test_with_ipv6:
Michael Johnson590fbe12019-07-03 14:30:01 -0700406 cls.lb_member_vip_ipv6_subnet_stateful = False
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100407 cls.lb_member_vip_ipv6_subnet_use_subnetpool = False
408 subnet_kwargs = {
409 'name': data_utils.rand_name("lb_member_vip_ipv6_subnet"),
410 'network_id': cls.lb_member_vip_net['id'],
411 'ip_version': 6}
412
413 # Use a CIDR from devstack's default IPv6 subnetpool if it exists,
414 # the subnetpool's cidr is routable from the devstack node
415 # through the default router
416 subnetpool_name = CONF.load_balancer.default_ipv6_subnetpool
417 if subnetpool_name:
418 subnetpool = cls.os_admin_subnetpools_client.list_subnetpools(
419 name=subnetpool_name)['subnetpools']
420 if len(subnetpool) == 1:
421 subnetpool = subnetpool[0]
422 subnet_kwargs['subnetpool_id'] = subnetpool['id']
423 cls.lb_member_vip_ipv6_subnet_use_subnetpool = True
424
425 if 'subnetpool_id' not in subnet_kwargs:
426 subnet_kwargs['cidr'] = (
427 CONF.load_balancer.vip_ipv6_subnet_cidr)
428
429 result = cls.lb_mem_subnet_client.create_subnet(
430 **subnet_kwargs)
431 cls.lb_member_vip_ipv6_net = cls.lb_member_vip_net
432 cls.lb_member_vip_ipv6_subnet = result['subnet']
433 cls.addClassResourceCleanup(
434 waiters.wait_for_not_found,
435 cls._logging_delete_subnet,
436 cls.lb_mem_subnet_client.show_subnet,
437 cls.lb_member_vip_ipv6_subnet['id'])
Carlos Goncalves84af48c2019-07-25 15:51:30 +0200438
Jude Cross986e3f52017-07-24 14:57:20 -0700439 LOG.info('lb_member_vip_ipv6_subnet: {}'.format(
440 cls.lb_member_vip_ipv6_subnet))
Jude Cross986e3f52017-07-24 14:57:20 -0700441
442 # Create tenant member 1 network
443 network_kwargs = {
444 'name': data_utils.rand_name("lb_member_1_network")}
445 if CONF.network_feature_enabled.port_security:
446 if CONF.load_balancer.enable_security_groups:
447 network_kwargs['port_security_enabled'] = True
448 else:
449 network_kwargs['port_security_enabled'] = False
450 result = cls.lb_mem_net_client.create_network(**network_kwargs)
451 cls.lb_member_1_net = result['network']
452 LOG.info('lb_member_1_net: {}'.format(cls.lb_member_1_net))
453 cls.addClassResourceCleanup(
454 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800455 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700456 cls.lb_mem_net_client.show_network,
457 cls.lb_member_1_net['id'])
458
459 # Create tenant member 1 subnet
460 subnet_kwargs = {
461 'name': data_utils.rand_name("lb_member_1_subnet"),
462 'network_id': cls.lb_member_1_net['id'],
463 'cidr': CONF.load_balancer.member_1_ipv4_subnet_cidr,
464 'ip_version': 4}
465 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
466 cls.lb_member_1_subnet = result['subnet']
467 LOG.info('lb_member_1_subnet: {}'.format(cls.lb_member_1_subnet))
468 cls.addClassResourceCleanup(
469 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800470 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700471 cls.lb_mem_subnet_client.show_subnet,
472 cls.lb_member_1_subnet['id'])
473
474 # Create tenant member 1 ipv6 subnet
475 if CONF.load_balancer.test_with_ipv6:
476 subnet_kwargs = {
477 'name': data_utils.rand_name("lb_member_1_ipv6_subnet"),
478 'network_id': cls.lb_member_1_net['id'],
479 'cidr': CONF.load_balancer.member_1_ipv6_subnet_cidr,
480 'ip_version': 6}
481 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700482 cls.lb_member_1_subnet_prefix = (
483 CONF.load_balancer.member_1_ipv6_subnet_cidr.rpartition('/')[2]
484 )
485 assert(cls.lb_member_1_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700486 cls.lb_member_1_ipv6_subnet = result['subnet']
487 LOG.info('lb_member_1_ipv6_subnet: {}'.format(
488 cls.lb_member_1_ipv6_subnet))
489 cls.addClassResourceCleanup(
490 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800491 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700492 cls.lb_mem_subnet_client.show_subnet,
493 cls.lb_member_1_ipv6_subnet['id'])
494
495 # Create tenant member 2 network
496 network_kwargs = {
497 'name': data_utils.rand_name("lb_member_2_network")}
498 if CONF.network_feature_enabled.port_security:
499 if CONF.load_balancer.enable_security_groups:
500 network_kwargs['port_security_enabled'] = True
501 else:
502 network_kwargs['port_security_enabled'] = False
503 result = cls.lb_mem_net_client.create_network(**network_kwargs)
504 cls.lb_member_2_net = result['network']
505 LOG.info('lb_member_2_net: {}'.format(cls.lb_member_2_net))
506 cls.addClassResourceCleanup(
507 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800508 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700509 cls.lb_mem_net_client.show_network,
510 cls.lb_member_2_net['id'])
511
512 # Create tenant member 2 subnet
513 subnet_kwargs = {
514 'name': data_utils.rand_name("lb_member_2_subnet"),
515 'network_id': cls.lb_member_2_net['id'],
516 'cidr': CONF.load_balancer.member_2_ipv4_subnet_cidr,
517 'ip_version': 4}
518 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
519 cls.lb_member_2_subnet = result['subnet']
520 LOG.info('lb_member_2_subnet: {}'.format(cls.lb_member_2_subnet))
521 cls.addClassResourceCleanup(
522 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800523 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700524 cls.lb_mem_subnet_client.show_subnet,
525 cls.lb_member_2_subnet['id'])
526
527 # Create tenant member 2 ipv6 subnet
528 if CONF.load_balancer.test_with_ipv6:
529 subnet_kwargs = {
530 'name': data_utils.rand_name("lb_member_2_ipv6_subnet"),
531 'network_id': cls.lb_member_2_net['id'],
532 'cidr': CONF.load_balancer.member_2_ipv6_subnet_cidr,
533 'ip_version': 6}
534 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700535 cls.lb_member_2_subnet_prefix = (
536 CONF.load_balancer.member_2_ipv6_subnet_cidr.rpartition('/')[2]
537 )
538 assert(cls.lb_member_2_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700539 cls.lb_member_2_ipv6_subnet = result['subnet']
540 LOG.info('lb_member_2_ipv6_subnet: {}'.format(
541 cls.lb_member_2_ipv6_subnet))
542 cls.addClassResourceCleanup(
543 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800544 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700545 cls.lb_mem_subnet_client.show_subnet,
546 cls.lb_member_2_ipv6_subnet['id'])
547
Adam Harwellcd72b562018-05-07 11:37:22 -0700548 @classmethod
Michael Johnson07c9a632018-06-07 13:27:42 -0700549 def _setup_lb_network_kwargs(cls, lb_kwargs, ip_version=None,
550 use_fixed_ip=False):
Adam Harwell60ed9d92018-05-10 13:23:13 -0700551 if not ip_version:
552 ip_version = 6 if CONF.load_balancer.test_with_ipv6 else 4
Michael Johnson5a16ad32018-10-18 14:49:11 -0700553 if cls.lb_member_vip_subnet or cls.lb_member_vip_ipv6_subnet:
Adam Harwellcd72b562018-05-07 11:37:22 -0700554 ip_index = data_utils.rand_int_id(start=10, end=100)
Michael Johnsondfd818a2018-08-21 20:54:54 -0700555 while ip_index in cls.used_ips:
556 ip_index = data_utils.rand_int_id(start=10, end=100)
557 cls.used_ips.append(ip_index)
Adam Harwellcd72b562018-05-07 11:37:22 -0700558 if ip_version == 4:
Adam Harwellcd72b562018-05-07 11:37:22 -0700559 subnet_id = cls.lb_member_vip_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700560 if CONF.load_balancer.test_with_noop:
561 lb_vip_address = '198.18.33.33'
562 else:
563 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
564 network = ipaddress.IPv4Network(subnet['subnet']['cidr'])
565 lb_vip_address = str(network[ip_index])
Adam Harwellcd72b562018-05-07 11:37:22 -0700566 else:
Adam Harwellcd72b562018-05-07 11:37:22 -0700567 subnet_id = cls.lb_member_vip_ipv6_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700568 if CONF.load_balancer.test_with_noop:
569 lb_vip_address = '2001:db8:33:33:33:33:33:33'
570 else:
571 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
572 network = ipaddress.IPv6Network(subnet['subnet']['cidr'])
573 lb_vip_address = str(network[ip_index])
Michael Johnson590fbe12019-07-03 14:30:01 -0700574 # If the subnet is IPv6 slaac or dhcpv6-stateless
575 # neutron does not allow a fixed IP
576 if not cls.lb_member_vip_ipv6_subnet_stateful:
577 use_fixed_ip = False
Adam Harwellcd72b562018-05-07 11:37:22 -0700578 lb_kwargs[const.VIP_SUBNET_ID] = subnet_id
Michael Johnson07c9a632018-06-07 13:27:42 -0700579 if use_fixed_ip:
580 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700581 if CONF.load_balancer.test_with_noop:
582 lb_kwargs[const.VIP_NETWORK_ID] = (
583 cls.lb_member_vip_net[const.ID])
Carlos Goncalvesbb238552020-01-15 10:10:55 +0000584 if ip_version == 6:
585 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700586 else:
587 lb_kwargs[const.VIP_NETWORK_ID] = cls.lb_member_vip_net[const.ID]
588 lb_kwargs[const.VIP_SUBNET_ID] = None
589
590
591class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest):
592 @classmethod
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +0100593 def remote_client_args(cls):
594 # In case we're using octavia-tempest-plugin with old tempest releases
595 # (for instance on stable/train) that don't support ssh_key_type, catch
596 # the exception and don't pass any argument
597 args = {}
598 try:
599 args['ssh_key_type'] = CONF.validation.ssh_key_type
600 except cfg.NoSuchOptError:
601 pass
602 return args
603
604 @classmethod
Adam Harwellcd72b562018-05-07 11:37:22 -0700605 def resource_setup(cls):
606 super(LoadBalancerBaseTestWithCompute, cls).resource_setup()
607 # If validation is disabled in this cloud, we won't be able to
608 # start the webservers, so don't even boot them.
609 if not CONF.validation.run_validation:
610 return
611
612 # Create a keypair for the webservers
613 keypair_name = data_utils.rand_name('lb_member_keypair')
614 result = cls.lb_mem_keypairs_client.create_keypair(
615 name=keypair_name)
616 cls.lb_member_keypair = result['keypair']
617 LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair))
618 cls.addClassResourceCleanup(
619 waiters.wait_for_not_found,
620 cls.lb_mem_keypairs_client.delete_keypair,
621 cls.lb_mem_keypairs_client.show_keypair,
622 keypair_name)
623
624 if (CONF.load_balancer.enable_security_groups and
625 CONF.network_feature_enabled.port_security):
626 # Set up the security group for the webservers
627 SG_name = data_utils.rand_name('lb_member_SG')
628 cls.lb_member_sec_group = (
629 cls.lb_mem_SG_client.create_security_group(
630 name=SG_name)['security_group'])
631 cls.addClassResourceCleanup(
632 waiters.wait_for_not_found,
633 cls.lb_mem_SG_client.delete_security_group,
634 cls.lb_mem_SG_client.show_security_group,
635 cls.lb_member_sec_group['id'])
636
637 # Create a security group rule to allow 80-81 (test webservers)
638 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
639 direction='ingress',
640 security_group_id=cls.lb_member_sec_group['id'],
641 protocol='tcp',
642 ethertype='IPv4',
643 port_range_min=80,
644 port_range_max=81)['security_group_rule']
645 cls.addClassResourceCleanup(
646 waiters.wait_for_not_found,
647 cls.lb_mem_SGr_client.delete_security_group_rule,
648 cls.lb_mem_SGr_client.show_security_group_rule,
649 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200650 # Create a security group rule to allow UDP 80-81 (test webservers)
651 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
652 direction='ingress',
653 security_group_id=cls.lb_member_sec_group['id'],
654 protocol='udp',
655 ethertype='IPv4',
656 port_range_min=80,
657 port_range_max=81)['security_group_rule']
658 cls.addClassResourceCleanup(
659 waiters.wait_for_not_found,
660 cls.lb_mem_SGr_client.delete_security_group_rule,
661 cls.lb_mem_SGr_client.show_security_group_rule,
662 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700663 # Create a security group rule to allow 443 (test webservers)
664 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
665 direction='ingress',
666 security_group_id=cls.lb_member_sec_group['id'],
667 protocol='tcp',
668 ethertype='IPv4',
669 port_range_min=443,
670 port_range_max=443)['security_group_rule']
671 cls.addClassResourceCleanup(
672 waiters.wait_for_not_found,
673 cls.lb_mem_SGr_client.delete_security_group_rule,
674 cls.lb_mem_SGr_client.show_security_group_rule,
675 SGr['id'])
Michael Johnson031ecca2020-10-29 16:45:32 -0700676 # Create a security group rule to allow 9443 (test webservers)
677 # Used in the pool backend encryption client authentication tests
678 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
679 direction='ingress',
680 security_group_id=cls.lb_member_sec_group['id'],
681 protocol='tcp',
682 ethertype='IPv4',
683 port_range_min=9443,
684 port_range_max=9443)['security_group_rule']
685 cls.addClassResourceCleanup(
686 waiters.wait_for_not_found,
687 cls.lb_mem_SGr_client.delete_security_group_rule,
688 cls.lb_mem_SGr_client.show_security_group_rule,
689 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200690 # Create a security group rule to allow UDP 9999 (test webservers)
691 # Port 9999 is used to illustrate health monitor ERRORs on closed
692 # ports.
693 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
694 direction='ingress',
695 security_group_id=cls.lb_member_sec_group['id'],
696 protocol='udp',
697 ethertype='IPv4',
698 port_range_min=9999,
699 port_range_max=9999)['security_group_rule']
700 cls.addClassResourceCleanup(
701 waiters.wait_for_not_found,
702 cls.lb_mem_SGr_client.delete_security_group_rule,
703 cls.lb_mem_SGr_client.show_security_group_rule,
704 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700705 # Create a security group rule to allow 22 (ssh)
706 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
707 direction='ingress',
708 security_group_id=cls.lb_member_sec_group['id'],
709 protocol='tcp',
710 ethertype='IPv4',
711 port_range_min=22,
712 port_range_max=22)['security_group_rule']
713 cls.addClassResourceCleanup(
714 waiters.wait_for_not_found,
715 cls.lb_mem_SGr_client.delete_security_group_rule,
716 cls.lb_mem_SGr_client.show_security_group_rule,
717 SGr['id'])
718 if CONF.load_balancer.test_with_ipv6:
719 # Create a security group rule to allow 80-81 (test webservers)
720 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
721 direction='ingress',
722 security_group_id=cls.lb_member_sec_group['id'],
723 protocol='tcp',
724 ethertype='IPv6',
725 port_range_min=80,
726 port_range_max=81)['security_group_rule']
727 cls.addClassResourceCleanup(
728 waiters.wait_for_not_found,
729 cls.lb_mem_SGr_client.delete_security_group_rule,
730 cls.lb_mem_SGr_client.show_security_group_rule,
731 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200732 # Create a security group rule to allow UDP 80-81 (test
733 # webservers)
734 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
735 direction='ingress',
736 security_group_id=cls.lb_member_sec_group['id'],
737 protocol='udp',
738 ethertype='IPv6',
739 port_range_min=80,
740 port_range_max=81)['security_group_rule']
741 cls.addClassResourceCleanup(
742 waiters.wait_for_not_found,
743 cls.lb_mem_SGr_client.delete_security_group_rule,
744 cls.lb_mem_SGr_client.show_security_group_rule,
745 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700746 # Create a security group rule to allow 443 (test webservers)
747 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
748 direction='ingress',
749 security_group_id=cls.lb_member_sec_group['id'],
750 protocol='tcp',
751 ethertype='IPv6',
752 port_range_min=443,
753 port_range_max=443)['security_group_rule']
754 cls.addClassResourceCleanup(
755 waiters.wait_for_not_found,
756 cls.lb_mem_SGr_client.delete_security_group_rule,
757 cls.lb_mem_SGr_client.show_security_group_rule,
758 SGr['id'])
Michael Johnson031ecca2020-10-29 16:45:32 -0700759 # Create a security group rule to allow 9443 (test webservers)
760 # Used in the pool encryption client authentication tests
761 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
762 direction='ingress',
763 security_group_id=cls.lb_member_sec_group['id'],
764 protocol='tcp',
765 ethertype='IPv6',
766 port_range_min=9443,
767 port_range_max=9443)['security_group_rule']
768 cls.addClassResourceCleanup(
769 waiters.wait_for_not_found,
770 cls.lb_mem_SGr_client.delete_security_group_rule,
771 cls.lb_mem_SGr_client.show_security_group_rule,
772 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700773 # Create a security group rule to allow 22 (ssh)
774 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
775 direction='ingress',
776 security_group_id=cls.lb_member_sec_group['id'],
777 protocol='tcp',
778 ethertype='IPv6',
779 port_range_min=22,
780 port_range_max=22)['security_group_rule']
781 cls.addClassResourceCleanup(
782 waiters.wait_for_not_found,
783 cls.lb_mem_SGr_client.delete_security_group_rule,
784 cls.lb_mem_SGr_client.show_security_group_rule,
785 SGr['id'])
786
787 LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group))
788
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700789 # Setup backend member reencryption PKI
790 cls._create_backend_reencryption_pki()
791
Adam Harwellcd72b562018-05-07 11:37:22 -0700792 # Create webserver 1 instance
793 server_details = cls._create_webserver('lb_member_webserver1',
794 cls.lb_member_1_net)
795
796 cls.lb_member_webserver1 = server_details['server']
797 cls.webserver1_ip = server_details.get('ipv4_address')
798 cls.webserver1_ipv6 = server_details.get('ipv6_address')
799 cls.webserver1_public_ip = server_details['public_ipv4_address']
800
801 LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format(
802 cls.lb_member_webserver1[const.ID]))
803 LOG.debug('Octavia Setup: webserver1_ip = {}'.format(
804 cls.webserver1_ip))
805 LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format(
806 cls.webserver1_ipv6))
807 LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format(
808 cls.webserver1_public_ip))
809
810 # Create webserver 2 instance
811 server_details = cls._create_webserver('lb_member_webserver2',
812 cls.lb_member_2_net)
813
814 cls.lb_member_webserver2 = server_details['server']
815 cls.webserver2_ip = server_details.get('ipv4_address')
816 cls.webserver2_ipv6 = server_details.get('ipv6_address')
817 cls.webserver2_public_ip = server_details['public_ipv4_address']
818
819 LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format(
820 cls.lb_member_webserver2[const.ID]))
821 LOG.debug('Octavia Setup: webserver2_ip = {}'.format(
822 cls.webserver2_ip))
823 LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format(
824 cls.webserver2_ipv6))
825 LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format(
826 cls.webserver2_public_ip))
827
Michael Johnsonbf916df2018-10-17 10:59:28 -0700828 if CONF.load_balancer.test_with_ipv6:
829 # Enable the IPv6 nic in webserver 1
830 cls._enable_ipv6_nic_webserver(
831 cls.webserver1_public_ip, cls.lb_member_keypair['private_key'],
832 cls.webserver1_ipv6, cls.lb_member_1_subnet_prefix)
833
834 # Enable the IPv6 nic in webserver 2
835 cls._enable_ipv6_nic_webserver(
836 cls.webserver2_public_ip, cls.lb_member_keypair['private_key'],
837 cls.webserver2_ipv6, cls.lb_member_2_subnet_prefix)
838
Adam Harwellcd72b562018-05-07 11:37:22 -0700839 # Set up serving on webserver 1
840 cls._install_start_webserver(cls.webserver1_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700841 cls.lb_member_keypair['private_key'],
842 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700843
844 # Validate webserver 1
Adam Harwelle029af22018-05-24 17:13:28 -0700845 cls._validate_webserver(cls.webserver1_public_ip,
846 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700847
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200848 # Validate udp server 1
849 cls._validate_udp_server(cls.webserver1_public_ip,
850 cls.webserver1_response)
851
Adam Harwellcd72b562018-05-07 11:37:22 -0700852 # Set up serving on webserver 2
853 cls._install_start_webserver(cls.webserver2_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700854 cls.lb_member_keypair['private_key'],
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700855 cls.webserver2_response, revoke_cert=True)
Adam Harwellcd72b562018-05-07 11:37:22 -0700856
857 # Validate webserver 2
Adam Harwelle029af22018-05-24 17:13:28 -0700858 cls._validate_webserver(cls.webserver2_public_ip,
859 cls.webserver2_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700860
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200861 # Validate udp server 2
862 cls._validate_udp_server(cls.webserver2_public_ip,
863 cls.webserver2_response)
864
Adam Harwellcd72b562018-05-07 11:37:22 -0700865 @classmethod
866 def _create_networks(cls):
867 super(LoadBalancerBaseTestWithCompute, cls)._create_networks()
Jude Cross986e3f52017-07-24 14:57:20 -0700868 # Create a router for the subnets (required for the floating IP)
869 router_name = data_utils.rand_name("lb_member_router")
870 result = cls.lb_mem_routers_client.create_router(
871 name=router_name, admin_state_up=True,
872 external_gateway_info=dict(
873 network_id=CONF.network.public_network_id))
874 cls.lb_member_router = result['router']
875 LOG.info('lb_member_router: {}'.format(cls.lb_member_router))
876 cls.addClassResourceCleanup(
877 waiters.wait_for_not_found,
878 cls.lb_mem_routers_client.delete_router,
879 cls.lb_mem_routers_client.show_router,
880 cls.lb_member_router['id'])
881
882 # Add VIP subnet to router
883 cls.lb_mem_routers_client.add_router_interface(
884 cls.lb_member_router['id'],
885 subnet_id=cls.lb_member_vip_subnet['id'])
886 cls.addClassResourceCleanup(
887 waiters.wait_for_not_found,
888 cls.lb_mem_routers_client.remove_router_interface,
889 cls.lb_mem_routers_client.remove_router_interface,
890 cls.lb_member_router['id'],
891 subnet_id=cls.lb_member_vip_subnet['id'])
892
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100893 if (CONF.load_balancer.test_with_ipv6 and
894 CONF.load_balancer.default_router and
895 cls.lb_member_vip_ipv6_subnet_use_subnetpool):
896
897 router_name = CONF.load_balancer.default_router
898 # if lb_member_vip_ipv6_subnet uses devstack's subnetpool,
899 # plug the subnet into the default router
900 router = cls.os_admin.routers_client.list_routers(
901 name=router_name)['routers']
902
903 if len(router) == 1:
904 router = router[0]
905
906 # Add IPv6 VIP subnet to router1
907 cls.os_admin_routers_client.add_router_interface(
908 router['id'],
909 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
910 cls.addClassResourceCleanup(
911 waiters.wait_for_not_found,
912 cls.os_admin_routers_client.remove_router_interface,
913 cls.os_admin_routers_client.remove_router_interface,
914 router['id'],
915 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
916
Jude Cross986e3f52017-07-24 14:57:20 -0700917 # Add member subnet 1 to router
918 cls.lb_mem_routers_client.add_router_interface(
919 cls.lb_member_router['id'],
920 subnet_id=cls.lb_member_1_subnet['id'])
921 cls.addClassResourceCleanup(
922 waiters.wait_for_not_found,
Jude Cross986e3f52017-07-24 14:57:20 -0700923 cls.lb_mem_routers_client.remove_router_interface,
924 cls.lb_mem_routers_client.remove_router_interface,
925 cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id'])
926
927 # Add member subnet 2 to router
928 cls.lb_mem_routers_client.add_router_interface(
929 cls.lb_member_router['id'],
930 subnet_id=cls.lb_member_2_subnet['id'])
931 cls.addClassResourceCleanup(
932 waiters.wait_for_not_found,
933 cls.lb_mem_routers_client.remove_router_interface,
934 cls.lb_mem_routers_client.remove_router_interface,
935 cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id'])
936
937 @classmethod
938 def _create_webserver(cls, name, network):
939 """Creates a webserver with two ports.
940
941 webserver_details dictionary contains:
942 server - The compute server object
943 ipv4_address - The IPv4 address for the server (optional)
944 ipv6_address - The IPv6 address for the server (optional)
945 public_ipv4_address - The publicly accessible IPv4 address for the
946 server, this may be a floating IP (optional)
947
948 :param name: The name of the server to create.
949 :param network: The network to boot the server on.
950 :returns: webserver_details dictionary.
951 """
952 server_kwargs = {
953 'name': data_utils.rand_name(name),
954 'flavorRef': CONF.compute.flavor_ref,
955 'imageRef': CONF.compute.image_ref,
956 'key_name': cls.lb_member_keypair['name']}
957 if (CONF.load_balancer.enable_security_groups and
958 CONF.network_feature_enabled.port_security):
959 server_kwargs['security_groups'] = [
960 {'name': cls.lb_member_sec_group['name']}]
961 if not CONF.load_balancer.disable_boot_network:
962 server_kwargs['networks'] = [{'uuid': network['id']}]
963
964 # Replace the name for clouds that have limitations
965 if CONF.load_balancer.random_server_name_length:
966 r = random.SystemRandom()
967 server_kwargs['name'] = "m{}".format("".join(
968 [r.choice(string.ascii_uppercase + string.digits)
969 for _ in range(
970 CONF.load_balancer.random_server_name_length - 1)]
971 ))
972 if CONF.load_balancer.availability_zone:
973 server_kwargs['availability_zone'] = (
974 CONF.load_balancer.availability_zone)
975
976 server = cls.lb_mem_servers_client.create_server(
977 **server_kwargs)['server']
978 cls.addClassResourceCleanup(
979 waiters.wait_for_not_found,
980 cls.lb_mem_servers_client.delete_server,
981 cls.lb_mem_servers_client.show_server,
982 server['id'])
983 server = waiters.wait_for_status(
984 cls.lb_mem_servers_client.show_server,
985 server['id'], 'status', 'ACTIVE',
986 CONF.load_balancer.build_interval,
987 CONF.load_balancer.build_timeout,
988 root_tag='server')
989 webserver_details = {'server': server}
990 LOG.info('Created server: {}'.format(server))
991
992 addresses = server['addresses']
993 if CONF.load_balancer.disable_boot_network:
994 instance_network = addresses.values()[0]
995 else:
996 instance_network = addresses[network['name']]
997 for addr in instance_network:
998 if addr['version'] == 4:
999 webserver_details['ipv4_address'] = addr['addr']
1000 if addr['version'] == 6:
1001 webserver_details['ipv6_address'] = addr['addr']
1002
1003 if CONF.validation.connect_method == 'floating':
1004 result = cls.lb_mem_ports_client.list_ports(
1005 network_id=network['id'],
1006 mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr'])
1007 port_id = result['ports'][0]['id']
1008 result = cls.lb_mem_float_ip_client.create_floatingip(
1009 floating_network_id=CONF.network.public_network_id,
1010 port_id=port_id)
1011 floating_ip = result['floatingip']
1012 LOG.info('webserver1_floating_ip: {}'.format(floating_ip))
1013 cls.addClassResourceCleanup(
1014 waiters.wait_for_not_found,
1015 cls.lb_mem_float_ip_client.delete_floatingip,
1016 cls.lb_mem_float_ip_client.show_floatingip,
1017 floatingip_id=floating_ip['id'])
1018 webserver_details['public_ipv4_address'] = (
1019 floating_ip['floating_ip_address'])
1020 else:
1021 webserver_details['public_ipv4_address'] = (
1022 instance_network[0]['addr'])
1023
1024 return webserver_details
1025
1026 @classmethod
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001027 def _get_openssh_version(cls):
1028 p = subprocess.Popen(["ssh", "-V"],
1029 stdout=subprocess.PIPE,
1030 stderr=subprocess.PIPE)
1031 output = p.communicate()[1]
1032
1033 try:
1034 m = re.match(r"OpenSSH_(\d+)\.(\d+)", output.decode('utf-8'))
1035 version_maj = int(m.group(1))
1036 version_min = int(m.group(2))
1037 return version_maj, version_min
1038 except Exception:
1039 return None, None
1040
1041 @classmethod
1042 def _need_scp_protocol(cls):
1043 # When using scp >= 8.7, force the use of the SCP protocol,
1044 # the new default (SFTP protocol) doesn't work with
1045 # cirros VMs.
1046 ssh_version = cls._get_openssh_version()
1047 LOG.debug("ssh_version = {}".format(ssh_version))
1048 return (ssh_version[0] > 8 or
1049 (ssh_version[0] == 8 and ssh_version[1] >= 7))
1050
1051 @classmethod
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001052 def _install_start_webserver(cls, ip_address, ssh_key, start_id,
1053 revoke_cert=False):
Michael Johnson27357352020-11-13 13:55:09 -08001054 local_file = CONF.load_balancer.test_server_path
Adam Harwellcd72b562018-05-07 11:37:22 -07001055
1056 linux_client = remote_client.RemoteClient(
Ade Leed0ea4062021-09-06 15:33:27 -04001057 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key,
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +01001058 **cls.remote_client_args())
Adam Harwellcd72b562018-05-07 11:37:22 -07001059 linux_client.validate_authentication()
1060
1061 with tempfile.NamedTemporaryFile() as key:
1062 key.write(ssh_key.encode('utf-8'))
1063 key.flush()
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001064 ssh_extra_args = (
1065 "-o PubkeyAcceptedKeyTypes=+ssh-rsa")
1066 if cls._need_scp_protocol():
1067 ssh_extra_args += " -O"
Adam Harwellcd72b562018-05-07 11:37:22 -07001068 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001069 "{7} "
Adam Harwellcd72b562018-05-07 11:37:22 -07001070 "-o StrictHostKeyChecking=no "
1071 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1072 "-i {2} {3} {4}@{5}:{6}").format(
1073 CONF.load_balancer.scp_connection_timeout,
1074 CONF.load_balancer.scp_connection_attempts,
1075 key.name, local_file, CONF.validation.image_ssh_user,
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001076 ip_address, const.TEST_SERVER_BINARY,
1077 ssh_extra_args)
Adam Harwellcd72b562018-05-07 11:37:22 -07001078 args = shlex.split(cmd)
1079 subprocess_args = {'stdout': subprocess.PIPE,
1080 'stderr': subprocess.STDOUT,
1081 'cwd': None}
1082 proc = subprocess.Popen(args, **subprocess_args)
1083 stdout, stderr = proc.communicate()
1084 if proc.returncode != 0:
1085 raise exceptions.CommandFailed(proc.returncode, cmd,
1086 stdout, stderr)
Gregory Thiemongef72a8862019-08-06 17:25:42 +02001087
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001088 cls._load_member_pki_content(ip_address, key,
1089 revoke_cert=revoke_cert)
1090
Gregory Thiemongef72a8862019-08-06 17:25:42 +02001091 # Enabling memory overcommit allows to run golang static binaries
1092 # compiled with a recent golang toolchain (>=1.11). Those binaries
1093 # allocate a large amount of virtual memory at init time, and this
1094 # allocation fails in tempest's nano flavor (64MB of RAM)
1095 # (golang issue reported in https://github.com/golang/go/issues/28114,
1096 # follow-up: https://github.com/golang/go/issues/28081)
1097 # TODO(gthiemonge): Remove this call when golang issue is resolved.
1098 linux_client.exec_command('sudo sh -c "echo 1 > '
1099 '/proc/sys/vm/overcommit_memory"')
1100
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001101 # The initial process also supports HTTPS and HTTPS with client auth
1102 linux_client.exec_command(
1103 'sudo screen -d -m {0} -port 80 -id {1} -https_port 443 -cert {2} '
1104 '-key {3} -https_client_auth_port 9443 -client_ca {4}'.format(
1105 const.TEST_SERVER_BINARY, start_id, const.TEST_SERVER_CERT,
1106 const.TEST_SERVER_KEY, const.TEST_SERVER_CLIENT_CA))
1107
Adam Harwellcd72b562018-05-07 11:37:22 -07001108 linux_client.exec_command('sudo screen -d -m {0} -port 81 '
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001109 '-id {1}'.format(const.TEST_SERVER_BINARY,
1110 start_id + 1))
Adam Harwellcd72b562018-05-07 11:37:22 -07001111
Michael Johnsonbf916df2018-10-17 10:59:28 -07001112 # Cirros does not configure the assigned IPv6 address by default
1113 # so enable it manually like tempest does here:
1114 # tempest/scenario/test_netowrk_v6.py turn_nic6_on()
1115 @classmethod
1116 def _enable_ipv6_nic_webserver(cls, ip_address, ssh_key,
1117 ipv6_address, ipv6_prefix):
1118 linux_client = remote_client.RemoteClient(
Ade Leed0ea4062021-09-06 15:33:27 -04001119 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key,
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +01001120 **cls.remote_client_args())
Michael Johnsonbf916df2018-10-17 10:59:28 -07001121 linux_client.validate_authentication()
1122
1123 linux_client.exec_command('sudo ip address add {0}/{1} dev '
1124 'eth0'.format(ipv6_address, ipv6_prefix))
1125
Adam Harwellcd72b562018-05-07 11:37:22 -07001126 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -07001127 def _validate_webserver(cls, ip_address, start_id):
1128 URL = 'http://{0}'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001129 cls.validate_URL_response(URL, expected_body=str(start_id))
Jude Cross986e3f52017-07-24 14:57:20 -07001130 URL = 'http://{0}:81'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001131 cls.validate_URL_response(URL, expected_body=str(start_id + 1))
Jude Cross986e3f52017-07-24 14:57:20 -07001132
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001133 @classmethod
1134 def _validate_udp_server(cls, ip_address, start_id):
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001135 res = cls.make_udp_request(ip_address, 80)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001136 if res != str(start_id):
1137 raise Exception("Response from test server doesn't match the "
1138 "expected value ({0} != {1}).".format(
1139 res, str(start_id)))
1140
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001141 res = cls.make_udp_request(ip_address, 81)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001142 if res != str(start_id + 1):
1143 raise Exception("Response from test server doesn't match the "
1144 "expected value ({0} != {1}).".format(
1145 res, str(start_id + 1)))
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001146
1147 @classmethod
1148 def _create_backend_reencryption_pki(cls):
1149 # Create a CA self-signed cert and key for the member test servers
1150 cls.member_ca_cert, cls.member_ca_key = (
1151 cert_utils.generate_ca_cert_and_key())
1152
1153 LOG.debug('Member CA Cert: %s', cls.member_ca_cert.public_bytes(
1154 serialization.Encoding.PEM))
1155 LOG.debug('Member CA private Key: %s', cls.member_ca_key.private_bytes(
1156 encoding=serialization.Encoding.PEM,
1157 format=serialization.PrivateFormat.TraditionalOpenSSL,
1158 encryption_algorithm=serialization.NoEncryption()))
1159 LOG.debug('Member CA public Key: %s',
1160 cls.member_ca_key.public_key().public_bytes(
1161 encoding=serialization.Encoding.PEM,
1162 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1163
1164 # Create the member client authentication CA
1165 cls.member_client_ca_cert, member_client_ca_key = (
1166 cert_utils.generate_ca_cert_and_key())
1167
1168 # Create client cert and key
1169 cls.member_client_cn = uuidutils.generate_uuid()
1170 cls.member_client_cert, cls.member_client_key = (
1171 cert_utils.generate_client_cert_and_key(
1172 cls.member_client_ca_cert, member_client_ca_key,
1173 cls.member_client_cn))
1174 # Note: We are not revoking a client cert here as we don't need to
1175 # test the backend web server CRL checking.
1176
1177 @classmethod
1178 def _load_member_pki_content(cls, ip_address, ssh_key, revoke_cert=False):
1179 # Create webserver certificate and key
1180 cert, key = cert_utils.generate_server_cert_and_key(
1181 cls.member_ca_cert, cls.member_ca_key, ip_address)
1182
1183 LOG.debug('%s Cert: %s', ip_address, cert.public_bytes(
1184 serialization.Encoding.PEM))
1185 LOG.debug('%s private Key: %s', ip_address, key.private_bytes(
1186 encoding=serialization.Encoding.PEM,
1187 format=serialization.PrivateFormat.TraditionalOpenSSL,
1188 encryption_algorithm=serialization.NoEncryption()))
1189 public_key = key.public_key()
1190 LOG.debug('%s public Key: %s', ip_address, public_key.public_bytes(
1191 encoding=serialization.Encoding.PEM,
1192 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1193
1194 # Create a CRL with a revoked certificate
1195 if revoke_cert:
1196 # Create a CRL with webserver 2 revoked
1197 cls.member_crl = cert_utils.generate_certificate_revocation_list(
1198 cls.member_ca_cert, cls.member_ca_key, cert)
1199
1200 # Load the certificate, key, and client CA certificate into the
1201 # test server.
1202 with tempfile.TemporaryDirectory() as tmpdir:
1203 os.umask(0)
1204 files_to_send = []
1205 cert_filename = os.path.join(tmpdir, const.CERT_PEM)
1206 files_to_send.append(cert_filename)
1207 with open(os.open(cert_filename, os.O_CREAT | os.O_WRONLY,
1208 0o700), 'w') as fh:
1209 fh.write(cert.public_bytes(
1210 serialization.Encoding.PEM).decode('utf-8'))
1211 fh.flush()
1212 key_filename = os.path.join(tmpdir, const.KEY_PEM)
1213 files_to_send.append(key_filename)
1214 with open(os.open(key_filename, os.O_CREAT | os.O_WRONLY,
1215 0o700), 'w') as fh:
1216 fh.write(key.private_bytes(
1217 encoding=serialization.Encoding.PEM,
1218 format=serialization.PrivateFormat.TraditionalOpenSSL,
1219 encryption_algorithm=serialization.NoEncryption()).decode(
1220 'utf-8'))
1221 fh.flush()
1222 client_ca_filename = os.path.join(tmpdir, const.CLIENT_CA_PEM)
1223 files_to_send.append(client_ca_filename)
1224 with open(os.open(client_ca_filename, os.O_CREAT | os.O_WRONLY,
1225 0o700), 'w') as fh:
1226 fh.write(cls.member_client_ca_cert.public_bytes(
1227 serialization.Encoding.PEM).decode('utf-8'))
1228 fh.flush()
1229
1230 # For security, we don't want to use a shell that can glob
1231 # the file names, so iterate over them.
1232 subprocess_args = {'stdout': subprocess.PIPE,
1233 'stderr': subprocess.STDOUT,
1234 'cwd': None}
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001235 ssh_extra_args = (
1236 "-o PubkeyAcceptedKeyTypes=+ssh-rsa")
1237 if cls._need_scp_protocol():
1238 ssh_extra_args += " -O"
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001239 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001240 "{9} "
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001241 "-o StrictHostKeyChecking=no "
1242 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1243 "-i {2} {3} {4} {5} {6}@{7}:{8}").format(
1244 CONF.load_balancer.scp_connection_timeout,
1245 CONF.load_balancer.scp_connection_attempts,
1246 ssh_key.name, cert_filename, key_filename, client_ca_filename,
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001247 CONF.validation.image_ssh_user, ip_address, const.DEV_SHM_PATH,
1248 ssh_extra_args)
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001249 args = shlex.split(cmd)
1250 proc = subprocess.Popen(args, **subprocess_args)
1251 stdout, stderr = proc.communicate()
1252 if proc.returncode != 0:
1253 raise exceptions.CommandFailed(proc.returncode, cmd,
1254 stdout, stderr)