blob: 7d9a3e5bb55f36713890fef0a16b4754543b8435 [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
Gregory Thiemonge29d17902019-04-30 15:06:17 +020044
Michael Johnson6006de72021-02-21 01:42:39 +000045class LoadBalancerBaseTest(validators.ValidatorsMixin,
46 RBAC_tests.RBACTestsMixin, test.BaseTestCase):
Jude Cross986e3f52017-07-24 14:57:20 -070047 """Base class for load balancer tests."""
48
Gregory Thiemonge3497f6c2021-04-19 21:33:13 +020049 if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN:
50 credentials = [
51 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role],
52 ['lb_member', CONF.load_balancer.member_role],
53 ['lb_member2', CONF.load_balancer.member_role]]
Michael Johnson6dac8ff2023-03-09 00:04:37 +000054 elif CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES:
Michael Johnson6006de72021-02-21 01:42:39 +000055 credentials = [
Michael Johnson6dac8ff2023-03-09 00:04:37 +000056 'admin', 'primary',
57 ['lb_admin', CONF.load_balancer.admin_role, 'admin'],
Michael Johnson6006de72021-02-21 01:42:39 +000058 ['lb_observer', CONF.load_balancer.observer_role, 'reader'],
59 ['lb_global_observer', CONF.load_balancer.global_observer_role,
60 'reader'],
61 ['lb_member', CONF.load_balancer.member_role, 'member'],
62 ['lb_member2', CONF.load_balancer.member_role, 'member'],
63 ['lb_member_not_default_member', CONF.load_balancer.member_role]]
64 else:
65 credentials = [
66 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role],
67 ['lb_observer', CONF.load_balancer.observer_role, 'reader'],
68 ['lb_global_observer', CONF.load_balancer.global_observer_role,
69 'reader'],
Michael Johnson9e9f5262023-01-18 17:59:17 +000070 # Note: Some projects are now requiring the 'member' role by
71 # default (nova for example) so make sure our creds have this role
72 ['lb_member', CONF.load_balancer.member_role, 'member'],
73 ['lb_member2', CONF.load_balancer.member_role, 'member']]
Michael Johnson6006de72021-02-21 01:42:39 +000074
75 # If scope enforcement is enabled, add in the system scope credentials.
76 # The project scope is already handled by the above credentials.
77 if CONF.enforce_scope.octavia:
78 credentials.extend(['system_admin', 'system_reader'])
79
80 # A tuple of credentials that will be allocated by tempest using the
81 # 'credentials' list above. These are used to build RBAC test lists.
82 allocated_creds = []
83 for cred in credentials:
84 if isinstance(cred, list):
85 allocated_creds.append('os_roles_' + cred[0])
86 else:
87 allocated_creds.append('os_' + cred)
88 # Tests shall not mess with the list of allocated credentials
89 allocated_credentials = tuple(allocated_creds)
Jude Cross986e3f52017-07-24 14:57:20 -070090
Adam Harwelle029af22018-05-24 17:13:28 -070091 webserver1_response = 1
92 webserver2_response = 5
Michael Johnsondfd818a2018-08-21 20:54:54 -070093 used_ips = []
Jude Cross986e3f52017-07-24 14:57:20 -070094
Michael Johnson89bdbcd2020-03-19 15:59:19 -070095 SRC_PORT_NUMBER_MIN = 32768
96 SRC_PORT_NUMBER_MAX = 61000
Gregory Thiemonge29d17902019-04-30 15:06:17 +020097 src_port_number = SRC_PORT_NUMBER_MIN
98
Jude Cross986e3f52017-07-24 14:57:20 -070099 @classmethod
100 def skip_checks(cls):
101 """Check if we should skip all of the children tests."""
102 super(LoadBalancerBaseTest, cls).skip_checks()
103
104 service_list = {
105 'load_balancer': CONF.service_available.load_balancer,
106 }
107
108 live_service_list = {
109 'compute': CONF.service_available.nova,
110 'image': CONF.service_available.glance,
111 'neutron': CONF.service_available.neutron
112 }
113
114 if not CONF.load_balancer.test_with_noop:
115 service_list.update(live_service_list)
116
117 for service, available in service_list.items():
118 if not available:
zhangzs2a6cf672018-11-10 16:13:11 +0800119 skip_msg = ("{0} skipped as {1} service is not "
Jude Cross986e3f52017-07-24 14:57:20 -0700120 "available.".format(cls.__name__, service))
121 raise cls.skipException(skip_msg)
122
123 # We must be able to reach our VIP and instances
124 if not (CONF.network.project_networks_reachable
125 or CONF.network.public_network_id):
126 msg = ('Either project_networks_reachable must be "true", or '
127 'public_network_id must be defined.')
128 raise cls.skipException(msg)
129
130 @classmethod
131 def setup_credentials(cls):
132 """Setup test credentials and network resources."""
133 # Do not auto create network resources
134 cls.set_network_resources()
135 super(LoadBalancerBaseTest, cls).setup_credentials()
136
Bas de Bruijne530a88a2022-12-15 11:12:45 -0400137 if not CONF.load_balancer.log_user_roles:
138 return
139
Michael Johnson6006de72021-02-21 01:42:39 +0000140 # Log the user roles for this test run
141 role_name_cache = {}
142 for cred in cls.credentials:
143 user_roles = []
144 if isinstance(cred, list):
145 user_name = cred[0]
146 cred_obj = getattr(cls, 'os_roles_' + cred[0])
147 else:
148 user_name = cred
149 cred_obj = getattr(cls, 'os_' + cred)
150 params = {'user.id': cred_obj.credentials.user_id,
151 'project.id': cred_obj.credentials.project_id}
152 roles = cls.os_admin.role_assignments_client.list_role_assignments(
153 **params)['role_assignments']
154 for role in roles:
155 role_id = role['role']['id']
156 try:
157 role_name = role_name_cache[role_id]
158 except KeyError:
159 role_name = cls.os_admin.roles_v3_client.show_role(
160 role_id)['role']['name']
161 role_name_cache[role_id] = role_name
162 user_roles.append([role_name, role['scope']])
163 LOG.info("User %s has roles: %s", user_name, user_roles)
164
Jude Cross986e3f52017-07-24 14:57:20 -0700165 @classmethod
166 def setup_clients(cls):
167 """Setup client aliases."""
168 super(LoadBalancerBaseTest, cls).setup_clients()
Michael Johnson29d8e612021-06-23 16:16:12 +0000169 lb_admin_prefix = cls.os_roles_lb_admin.load_balancer_v2
Jude Cross986e3f52017-07-24 14:57:20 -0700170 cls.lb_mem_float_ip_client = cls.os_roles_lb_member.floating_ips_client
171 cls.lb_mem_keypairs_client = cls.os_roles_lb_member.keypairs_client
172 cls.lb_mem_net_client = cls.os_roles_lb_member.networks_client
173 cls.lb_mem_ports_client = cls.os_roles_lb_member.ports_client
174 cls.lb_mem_routers_client = cls.os_roles_lb_member.routers_client
175 cls.lb_mem_SG_client = cls.os_roles_lb_member.security_groups_client
176 cls.lb_mem_SGr_client = (
177 cls.os_roles_lb_member.security_group_rules_client)
178 cls.lb_mem_servers_client = cls.os_roles_lb_member.servers_client
179 cls.lb_mem_subnet_client = cls.os_roles_lb_member.subnets_client
Michael Johnson29d8e612021-06-23 16:16:12 +0000180 cls.mem_lb_client = (
181 cls.os_roles_lb_member.load_balancer_v2.LoadbalancerClient())
182 cls.mem_listener_client = (
183 cls.os_roles_lb_member.load_balancer_v2.ListenerClient())
184 cls.mem_pool_client = (
185 cls.os_roles_lb_member.load_balancer_v2.PoolClient())
186 cls.mem_member_client = (
187 cls.os_roles_lb_member.load_balancer_v2.MemberClient())
Adam Harwell60ed9d92018-05-10 13:23:13 -0700188 cls.mem_healthmonitor_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000189 cls.os_roles_lb_member.load_balancer_v2.HealthMonitorClient())
190 cls.mem_l7policy_client = (
191 cls.os_roles_lb_member.load_balancer_v2.L7PolicyClient())
192 cls.mem_l7rule_client = (
193 cls.os_roles_lb_member.load_balancer_v2.L7RuleClient())
194 cls.lb_admin_amphora_client = lb_admin_prefix.AmphoraClient()
Michael Johnsonaff2e862019-01-11 16:38:00 -0800195 cls.lb_admin_flavor_profile_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000196 lb_admin_prefix.FlavorProfileClient())
197 cls.lb_admin_flavor_client = lb_admin_prefix.FlavorClient()
198 cls.mem_flavor_client = (
199 cls.os_roles_lb_member.load_balancer_v2.FlavorClient())
200 cls.mem_provider_client = (
201 cls.os_roles_lb_member.load_balancer_v2.ProviderClient())
Carlos Goncalvesc2e12162019-02-14 23:57:44 +0100202 cls.os_admin_servers_client = cls.os_admin.servers_client
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100203 cls.os_admin_routers_client = cls.os_admin.routers_client
204 cls.os_admin_subnetpools_client = cls.os_admin.subnetpools_client
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800205 cls.lb_admin_flavor_capabilities_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000206 lb_admin_prefix.FlavorCapabilitiesClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800207 cls.lb_admin_availability_zone_capabilities_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000208 lb_admin_prefix.AvailabilityZoneCapabilitiesClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800209 cls.lb_admin_availability_zone_profile_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000210 lb_admin_prefix.AvailabilityZoneProfileClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800211 cls.lb_admin_availability_zone_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000212 lb_admin_prefix.AvailabilityZoneClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800213 cls.mem_availability_zone_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000214 cls.os_roles_lb_member.load_balancer_v2.AvailabilityZoneClient())
Jude Cross986e3f52017-07-24 14:57:20 -0700215
216 @classmethod
217 def resource_setup(cls):
218 """Setup resources needed by the tests."""
219 super(LoadBalancerBaseTest, cls).resource_setup()
220
221 conf_lb = CONF.load_balancer
222
Michael Johnsondfd818a2018-08-21 20:54:54 -0700223 cls.api_version = cls.mem_lb_client.get_max_api_version()
224
Jude Cross986e3f52017-07-24 14:57:20 -0700225 if conf_lb.test_subnet_override and not conf_lb.test_network_override:
226 raise exceptions.InvalidConfiguration(
227 "Configuration value test_network_override must be "
228 "specified if test_subnet_override is used.")
229
Michael Johnson6a9236a2020-08-04 23:54:54 +0000230 # TODO(johnsom) Remove this
Maciej Józefczykb6df5f82019-12-10 10:12:30 +0000231 # Get loadbalancing algorithms supported by provider driver.
232 try:
233 algorithms = const.SUPPORTED_LB_ALGORITHMS[
234 CONF.load_balancer.provider]
235 except KeyError:
236 algorithms = const.SUPPORTED_LB_ALGORITHMS['default']
237 # Set default algorithm as first from the list.
238 cls.lb_algorithm = algorithms[0]
239
Jude Cross986e3f52017-07-24 14:57:20 -0700240 show_subnet = cls.lb_mem_subnet_client.show_subnet
241 if CONF.load_balancer.test_with_noop:
242 cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()}
243 cls.lb_member_vip_subnet = {'id': uuidutils.generate_uuid()}
244 cls.lb_member_1_net = {'id': uuidutils.generate_uuid()}
245 cls.lb_member_1_subnet = {'id': uuidutils.generate_uuid()}
246 cls.lb_member_2_net = {'id': uuidutils.generate_uuid()}
247 cls.lb_member_2_subnet = {'id': uuidutils.generate_uuid()}
248 if CONF.load_balancer.test_with_ipv6:
Michael Johnson5a16ad32018-10-18 14:49:11 -0700249 cls.lb_member_vip_ipv6_net = {'id': uuidutils.generate_uuid()}
Jude Cross986e3f52017-07-24 14:57:20 -0700250 cls.lb_member_vip_ipv6_subnet = {'id':
251 uuidutils.generate_uuid()}
252 cls.lb_member_1_ipv6_subnet = {'id': uuidutils.generate_uuid()}
253 cls.lb_member_2_ipv6_subnet = {'id': uuidutils.generate_uuid()}
Michael Johnson590fbe12019-07-03 14:30:01 -0700254 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700255 return
256 elif CONF.load_balancer.test_network_override:
257 if conf_lb.test_subnet_override:
258 override_subnet = show_subnet(conf_lb.test_subnet_override)
259 else:
260 override_subnet = None
261
262 show_net = cls.lb_mem_net_client.show_network
263 override_network = show_net(conf_lb.test_network_override)
264 override_network = override_network.get('network')
265
266 cls.lb_member_vip_net = override_network
267 cls.lb_member_vip_subnet = override_subnet
268 cls.lb_member_1_net = override_network
269 cls.lb_member_1_subnet = override_subnet
270 cls.lb_member_2_net = override_network
271 cls.lb_member_2_subnet = override_subnet
272
273 if (CONF.load_balancer.test_with_ipv6 and
274 conf_lb.test_IPv6_subnet_override):
275 override_ipv6_subnet = show_subnet(
276 conf_lb.test_IPv6_subnet_override)
277 cls.lb_member_vip_ipv6_subnet = override_ipv6_subnet
278 cls.lb_member_1_ipv6_subnet = override_ipv6_subnet
279 cls.lb_member_2_ipv6_subnet = override_ipv6_subnet
Michael Johnson590fbe12019-07-03 14:30:01 -0700280 cls.lb_member_vip_ipv6_subnet_stateful = False
281 if (override_ipv6_subnet[0]['ipv6_address_mode'] ==
282 'dhcpv6-stateful'):
283 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700284 else:
285 cls.lb_member_vip_ipv6_subnet = None
286 cls.lb_member_1_ipv6_subnet = None
287 cls.lb_member_2_ipv6_subnet = None
288 else:
289 cls._create_networks()
290
291 LOG.debug('Octavia Setup: lb_member_vip_net = {}'.format(
292 cls.lb_member_vip_net[const.ID]))
293 if cls.lb_member_vip_subnet:
294 LOG.debug('Octavia Setup: lb_member_vip_subnet = {}'.format(
295 cls.lb_member_vip_subnet[const.ID]))
296 LOG.debug('Octavia Setup: lb_member_1_net = {}'.format(
297 cls.lb_member_1_net[const.ID]))
298 if cls.lb_member_1_subnet:
299 LOG.debug('Octavia Setup: lb_member_1_subnet = {}'.format(
300 cls.lb_member_1_subnet[const.ID]))
301 LOG.debug('Octavia Setup: lb_member_2_net = {}'.format(
302 cls.lb_member_2_net[const.ID]))
303 if cls.lb_member_2_subnet:
304 LOG.debug('Octavia Setup: lb_member_2_subnet = {}'.format(
305 cls.lb_member_2_subnet[const.ID]))
Michael Johnson124ba8b2018-08-30 16:06:05 -0700306 if CONF.load_balancer.test_with_ipv6:
307 if cls.lb_member_vip_ipv6_subnet:
308 LOG.debug('Octavia Setup: lb_member_vip_ipv6_subnet = '
309 '{}'.format(cls.lb_member_vip_ipv6_subnet[const.ID]))
310 if cls.lb_member_1_ipv6_subnet:
311 LOG.debug('Octavia Setup: lb_member_1_ipv6_subnet = {}'.format(
312 cls.lb_member_1_ipv6_subnet[const.ID]))
313 if cls.lb_member_2_ipv6_subnet:
314 LOG.debug('Octavia Setup: lb_member_2_ipv6_subnet = {}'.format(
315 cls.lb_member_2_ipv6_subnet[const.ID]))
Jude Cross986e3f52017-07-24 14:57:20 -0700316
Jude Cross986e3f52017-07-24 14:57:20 -0700317 @classmethod
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800318 # Neutron can be slow to clean up ports from the subnets/networks.
319 # Retry this delete a few times if we get a "Conflict" error to give
320 # neutron time to fully cleanup the ports.
321 @tenacity.retry(
322 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
323 wait=tenacity.wait_incrementing(
Vasyl Saienko0d5a4f42021-05-12 16:30:26 +0300324 const.RETRY_INITIAL_DELAY, const.RETRY_BACKOFF, const.RETRY_MAX),
325 stop=tenacity.stop_after_attempt(const.RETRY_ATTEMPTS))
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800326 def _logging_delete_network(cls, net_id):
327 try:
328 cls.lb_mem_net_client.delete_network(net_id)
329 except Exception:
330 LOG.error('Unable to delete network {}. Active ports:'.format(
331 net_id))
332 LOG.error(cls.lb_mem_ports_client.list_ports())
333 raise
334
335 @classmethod
336 # Neutron can be slow to clean up ports from the subnets/networks.
337 # Retry this delete a few times if we get a "Conflict" error to give
338 # neutron time to fully cleanup the ports.
339 @tenacity.retry(
340 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
341 wait=tenacity.wait_incrementing(
Vasyl Saienko0d5a4f42021-05-12 16:30:26 +0300342 const.RETRY_INITIAL_DELAY, const.RETRY_BACKOFF, const.RETRY_MAX),
343 stop=tenacity.stop_after_attempt(const.RETRY_ATTEMPTS))
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800344 def _logging_delete_subnet(cls, subnet_id):
345 try:
346 cls.lb_mem_subnet_client.delete_subnet(subnet_id)
347 except Exception:
348 LOG.error('Unable to delete subnet {}. Active ports:'.format(
349 subnet_id))
350 LOG.error(cls.lb_mem_ports_client.list_ports())
351 raise
352
353 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -0700354 def _create_networks(cls):
355 """Creates networks, subnets, and routers used in tests.
356
357 The following are expected to be defined and available to the tests:
358 cls.lb_member_vip_net
359 cls.lb_member_vip_subnet
360 cls.lb_member_vip_ipv6_subnet (optional)
361 cls.lb_member_1_net
362 cls.lb_member_1_subnet
363 cls.lb_member_1_ipv6_subnet (optional)
364 cls.lb_member_2_net
365 cls.lb_member_2_subnet
366 cls.lb_member_2_ipv6_subnet (optional)
367 """
368
369 # Create tenant VIP network
370 network_kwargs = {
371 'name': data_utils.rand_name("lb_member_vip_network")}
372 if CONF.network_feature_enabled.port_security:
Andreas Jaeger4215b702020-03-28 20:13:46 +0100373 # Note: Allowed Address Pairs requires port security
374 network_kwargs['port_security_enabled'] = True
Jude Cross986e3f52017-07-24 14:57:20 -0700375 result = cls.lb_mem_net_client.create_network(**network_kwargs)
376 cls.lb_member_vip_net = result['network']
377 LOG.info('lb_member_vip_net: {}'.format(cls.lb_member_vip_net))
378 cls.addClassResourceCleanup(
379 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800380 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700381 cls.lb_mem_net_client.show_network,
382 cls.lb_member_vip_net['id'])
383
384 # Create tenant VIP subnet
385 subnet_kwargs = {
386 'name': data_utils.rand_name("lb_member_vip_subnet"),
387 'network_id': cls.lb_member_vip_net['id'],
388 'cidr': CONF.load_balancer.vip_subnet_cidr,
389 'ip_version': 4}
390 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
391 cls.lb_member_vip_subnet = result['subnet']
392 LOG.info('lb_member_vip_subnet: {}'.format(cls.lb_member_vip_subnet))
393 cls.addClassResourceCleanup(
394 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800395 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700396 cls.lb_mem_subnet_client.show_subnet,
397 cls.lb_member_vip_subnet['id'])
398
399 # Create tenant VIP IPv6 subnet
400 if CONF.load_balancer.test_with_ipv6:
Michael Johnson590fbe12019-07-03 14:30:01 -0700401 cls.lb_member_vip_ipv6_subnet_stateful = False
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100402 cls.lb_member_vip_ipv6_subnet_use_subnetpool = False
403 subnet_kwargs = {
404 'name': data_utils.rand_name("lb_member_vip_ipv6_subnet"),
405 'network_id': cls.lb_member_vip_net['id'],
406 'ip_version': 6}
407
408 # Use a CIDR from devstack's default IPv6 subnetpool if it exists,
409 # the subnetpool's cidr is routable from the devstack node
410 # through the default router
411 subnetpool_name = CONF.load_balancer.default_ipv6_subnetpool
412 if subnetpool_name:
413 subnetpool = cls.os_admin_subnetpools_client.list_subnetpools(
414 name=subnetpool_name)['subnetpools']
415 if len(subnetpool) == 1:
416 subnetpool = subnetpool[0]
417 subnet_kwargs['subnetpool_id'] = subnetpool['id']
418 cls.lb_member_vip_ipv6_subnet_use_subnetpool = True
419
420 if 'subnetpool_id' not in subnet_kwargs:
421 subnet_kwargs['cidr'] = (
422 CONF.load_balancer.vip_ipv6_subnet_cidr)
423
424 result = cls.lb_mem_subnet_client.create_subnet(
425 **subnet_kwargs)
426 cls.lb_member_vip_ipv6_net = cls.lb_member_vip_net
427 cls.lb_member_vip_ipv6_subnet = result['subnet']
428 cls.addClassResourceCleanup(
429 waiters.wait_for_not_found,
430 cls._logging_delete_subnet,
431 cls.lb_mem_subnet_client.show_subnet,
432 cls.lb_member_vip_ipv6_subnet['id'])
Carlos Goncalves84af48c2019-07-25 15:51:30 +0200433
Jude Cross986e3f52017-07-24 14:57:20 -0700434 LOG.info('lb_member_vip_ipv6_subnet: {}'.format(
435 cls.lb_member_vip_ipv6_subnet))
Jude Cross986e3f52017-07-24 14:57:20 -0700436
437 # Create tenant member 1 network
438 network_kwargs = {
439 'name': data_utils.rand_name("lb_member_1_network")}
440 if CONF.network_feature_enabled.port_security:
441 if CONF.load_balancer.enable_security_groups:
442 network_kwargs['port_security_enabled'] = True
443 else:
444 network_kwargs['port_security_enabled'] = False
445 result = cls.lb_mem_net_client.create_network(**network_kwargs)
446 cls.lb_member_1_net = result['network']
447 LOG.info('lb_member_1_net: {}'.format(cls.lb_member_1_net))
448 cls.addClassResourceCleanup(
449 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800450 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700451 cls.lb_mem_net_client.show_network,
452 cls.lb_member_1_net['id'])
453
454 # Create tenant member 1 subnet
455 subnet_kwargs = {
456 'name': data_utils.rand_name("lb_member_1_subnet"),
457 'network_id': cls.lb_member_1_net['id'],
458 'cidr': CONF.load_balancer.member_1_ipv4_subnet_cidr,
459 'ip_version': 4}
460 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
461 cls.lb_member_1_subnet = result['subnet']
462 LOG.info('lb_member_1_subnet: {}'.format(cls.lb_member_1_subnet))
463 cls.addClassResourceCleanup(
464 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800465 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700466 cls.lb_mem_subnet_client.show_subnet,
467 cls.lb_member_1_subnet['id'])
468
469 # Create tenant member 1 ipv6 subnet
470 if CONF.load_balancer.test_with_ipv6:
471 subnet_kwargs = {
472 'name': data_utils.rand_name("lb_member_1_ipv6_subnet"),
473 'network_id': cls.lb_member_1_net['id'],
474 'cidr': CONF.load_balancer.member_1_ipv6_subnet_cidr,
475 'ip_version': 6}
476 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700477 cls.lb_member_1_subnet_prefix = (
478 CONF.load_balancer.member_1_ipv6_subnet_cidr.rpartition('/')[2]
479 )
480 assert(cls.lb_member_1_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700481 cls.lb_member_1_ipv6_subnet = result['subnet']
482 LOG.info('lb_member_1_ipv6_subnet: {}'.format(
483 cls.lb_member_1_ipv6_subnet))
484 cls.addClassResourceCleanup(
485 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800486 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700487 cls.lb_mem_subnet_client.show_subnet,
488 cls.lb_member_1_ipv6_subnet['id'])
489
490 # Create tenant member 2 network
491 network_kwargs = {
492 'name': data_utils.rand_name("lb_member_2_network")}
493 if CONF.network_feature_enabled.port_security:
494 if CONF.load_balancer.enable_security_groups:
495 network_kwargs['port_security_enabled'] = True
496 else:
497 network_kwargs['port_security_enabled'] = False
498 result = cls.lb_mem_net_client.create_network(**network_kwargs)
499 cls.lb_member_2_net = result['network']
500 LOG.info('lb_member_2_net: {}'.format(cls.lb_member_2_net))
501 cls.addClassResourceCleanup(
502 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800503 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700504 cls.lb_mem_net_client.show_network,
505 cls.lb_member_2_net['id'])
506
507 # Create tenant member 2 subnet
508 subnet_kwargs = {
509 'name': data_utils.rand_name("lb_member_2_subnet"),
510 'network_id': cls.lb_member_2_net['id'],
511 'cidr': CONF.load_balancer.member_2_ipv4_subnet_cidr,
512 'ip_version': 4}
513 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
514 cls.lb_member_2_subnet = result['subnet']
515 LOG.info('lb_member_2_subnet: {}'.format(cls.lb_member_2_subnet))
516 cls.addClassResourceCleanup(
517 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800518 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700519 cls.lb_mem_subnet_client.show_subnet,
520 cls.lb_member_2_subnet['id'])
521
522 # Create tenant member 2 ipv6 subnet
523 if CONF.load_balancer.test_with_ipv6:
524 subnet_kwargs = {
525 'name': data_utils.rand_name("lb_member_2_ipv6_subnet"),
526 'network_id': cls.lb_member_2_net['id'],
527 'cidr': CONF.load_balancer.member_2_ipv6_subnet_cidr,
528 'ip_version': 6}
529 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700530 cls.lb_member_2_subnet_prefix = (
531 CONF.load_balancer.member_2_ipv6_subnet_cidr.rpartition('/')[2]
532 )
533 assert(cls.lb_member_2_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700534 cls.lb_member_2_ipv6_subnet = result['subnet']
535 LOG.info('lb_member_2_ipv6_subnet: {}'.format(
536 cls.lb_member_2_ipv6_subnet))
537 cls.addClassResourceCleanup(
538 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800539 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700540 cls.lb_mem_subnet_client.show_subnet,
541 cls.lb_member_2_ipv6_subnet['id'])
542
Adam Harwellcd72b562018-05-07 11:37:22 -0700543 @classmethod
Michael Johnson07c9a632018-06-07 13:27:42 -0700544 def _setup_lb_network_kwargs(cls, lb_kwargs, ip_version=None,
545 use_fixed_ip=False):
Adam Harwell60ed9d92018-05-10 13:23:13 -0700546 if not ip_version:
547 ip_version = 6 if CONF.load_balancer.test_with_ipv6 else 4
Michael Johnson5a16ad32018-10-18 14:49:11 -0700548 if cls.lb_member_vip_subnet or cls.lb_member_vip_ipv6_subnet:
Adam Harwellcd72b562018-05-07 11:37:22 -0700549 ip_index = data_utils.rand_int_id(start=10, end=100)
Michael Johnsondfd818a2018-08-21 20:54:54 -0700550 while ip_index in cls.used_ips:
551 ip_index = data_utils.rand_int_id(start=10, end=100)
552 cls.used_ips.append(ip_index)
Adam Harwellcd72b562018-05-07 11:37:22 -0700553 if ip_version == 4:
Adam Harwellcd72b562018-05-07 11:37:22 -0700554 subnet_id = cls.lb_member_vip_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700555 if CONF.load_balancer.test_with_noop:
556 lb_vip_address = '198.18.33.33'
557 else:
558 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
559 network = ipaddress.IPv4Network(subnet['subnet']['cidr'])
560 lb_vip_address = str(network[ip_index])
Adam Harwellcd72b562018-05-07 11:37:22 -0700561 else:
Adam Harwellcd72b562018-05-07 11:37:22 -0700562 subnet_id = cls.lb_member_vip_ipv6_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700563 if CONF.load_balancer.test_with_noop:
564 lb_vip_address = '2001:db8:33:33:33:33:33:33'
565 else:
566 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
567 network = ipaddress.IPv6Network(subnet['subnet']['cidr'])
568 lb_vip_address = str(network[ip_index])
Michael Johnson590fbe12019-07-03 14:30:01 -0700569 # If the subnet is IPv6 slaac or dhcpv6-stateless
570 # neutron does not allow a fixed IP
571 if not cls.lb_member_vip_ipv6_subnet_stateful:
572 use_fixed_ip = False
Adam Harwellcd72b562018-05-07 11:37:22 -0700573 lb_kwargs[const.VIP_SUBNET_ID] = subnet_id
Michael Johnson07c9a632018-06-07 13:27:42 -0700574 if use_fixed_ip:
575 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700576 if CONF.load_balancer.test_with_noop:
577 lb_kwargs[const.VIP_NETWORK_ID] = (
578 cls.lb_member_vip_net[const.ID])
Carlos Goncalvesbb238552020-01-15 10:10:55 +0000579 if ip_version == 6:
580 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700581 else:
582 lb_kwargs[const.VIP_NETWORK_ID] = cls.lb_member_vip_net[const.ID]
583 lb_kwargs[const.VIP_SUBNET_ID] = None
584
Gregory Thiemongeece5ab42020-10-29 08:46:05 +0100585 def _validate_listener_protocol(self, protocol, raise_if_unsupported=True):
586 if (protocol == const.SCTP and
587 not self.mem_listener_client.is_version_supported(
588 self.api_version, '2.23')):
589 if raise_if_unsupported:
590 raise self.skipException('SCTP listener protocol '
591 'is only available on Octavia '
592 'API version 2.23 or newer.')
593 return False
594 return True
595
Adam Harwellcd72b562018-05-07 11:37:22 -0700596
597class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest):
598 @classmethod
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +0100599 def remote_client_args(cls):
600 # In case we're using octavia-tempest-plugin with old tempest releases
601 # (for instance on stable/train) that don't support ssh_key_type, catch
602 # the exception and don't pass any argument
603 args = {}
604 try:
605 args['ssh_key_type'] = CONF.validation.ssh_key_type
606 except cfg.NoSuchOptError:
607 pass
608 return args
609
610 @classmethod
Adam Harwellcd72b562018-05-07 11:37:22 -0700611 def resource_setup(cls):
612 super(LoadBalancerBaseTestWithCompute, cls).resource_setup()
613 # If validation is disabled in this cloud, we won't be able to
614 # start the webservers, so don't even boot them.
615 if not CONF.validation.run_validation:
616 return
617
618 # Create a keypair for the webservers
619 keypair_name = data_utils.rand_name('lb_member_keypair')
620 result = cls.lb_mem_keypairs_client.create_keypair(
621 name=keypair_name)
622 cls.lb_member_keypair = result['keypair']
623 LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair))
624 cls.addClassResourceCleanup(
625 waiters.wait_for_not_found,
626 cls.lb_mem_keypairs_client.delete_keypair,
627 cls.lb_mem_keypairs_client.show_keypair,
628 keypair_name)
629
630 if (CONF.load_balancer.enable_security_groups and
631 CONF.network_feature_enabled.port_security):
632 # Set up the security group for the webservers
633 SG_name = data_utils.rand_name('lb_member_SG')
634 cls.lb_member_sec_group = (
635 cls.lb_mem_SG_client.create_security_group(
636 name=SG_name)['security_group'])
637 cls.addClassResourceCleanup(
638 waiters.wait_for_not_found,
639 cls.lb_mem_SG_client.delete_security_group,
640 cls.lb_mem_SG_client.show_security_group,
641 cls.lb_member_sec_group['id'])
642
643 # Create a security group rule to allow 80-81 (test webservers)
644 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
645 direction='ingress',
646 security_group_id=cls.lb_member_sec_group['id'],
647 protocol='tcp',
648 ethertype='IPv4',
649 port_range_min=80,
650 port_range_max=81)['security_group_rule']
651 cls.addClassResourceCleanup(
652 waiters.wait_for_not_found,
653 cls.lb_mem_SGr_client.delete_security_group_rule,
654 cls.lb_mem_SGr_client.show_security_group_rule,
655 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200656 # Create a security group rule to allow UDP 80-81 (test webservers)
657 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
658 direction='ingress',
659 security_group_id=cls.lb_member_sec_group['id'],
660 protocol='udp',
661 ethertype='IPv4',
662 port_range_min=80,
663 port_range_max=81)['security_group_rule']
664 cls.addClassResourceCleanup(
665 waiters.wait_for_not_found,
666 cls.lb_mem_SGr_client.delete_security_group_rule,
667 cls.lb_mem_SGr_client.show_security_group_rule,
668 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700669 # Create a security group rule to allow 443 (test webservers)
670 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
671 direction='ingress',
672 security_group_id=cls.lb_member_sec_group['id'],
673 protocol='tcp',
674 ethertype='IPv4',
675 port_range_min=443,
676 port_range_max=443)['security_group_rule']
677 cls.addClassResourceCleanup(
678 waiters.wait_for_not_found,
679 cls.lb_mem_SGr_client.delete_security_group_rule,
680 cls.lb_mem_SGr_client.show_security_group_rule,
681 SGr['id'])
Michael Johnson031ecca2020-10-29 16:45:32 -0700682 # Create a security group rule to allow 9443 (test webservers)
683 # Used in the pool backend encryption client authentication tests
684 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
685 direction='ingress',
686 security_group_id=cls.lb_member_sec_group['id'],
687 protocol='tcp',
688 ethertype='IPv4',
689 port_range_min=9443,
690 port_range_max=9443)['security_group_rule']
691 cls.addClassResourceCleanup(
692 waiters.wait_for_not_found,
693 cls.lb_mem_SGr_client.delete_security_group_rule,
694 cls.lb_mem_SGr_client.show_security_group_rule,
695 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200696 # Create a security group rule to allow UDP 9999 (test webservers)
697 # Port 9999 is used to illustrate health monitor ERRORs on closed
698 # ports.
699 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
700 direction='ingress',
701 security_group_id=cls.lb_member_sec_group['id'],
702 protocol='udp',
703 ethertype='IPv4',
704 port_range_min=9999,
705 port_range_max=9999)['security_group_rule']
706 cls.addClassResourceCleanup(
707 waiters.wait_for_not_found,
708 cls.lb_mem_SGr_client.delete_security_group_rule,
709 cls.lb_mem_SGr_client.show_security_group_rule,
710 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700711 # Create a security group rule to allow 22 (ssh)
712 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
713 direction='ingress',
714 security_group_id=cls.lb_member_sec_group['id'],
715 protocol='tcp',
716 ethertype='IPv4',
717 port_range_min=22,
718 port_range_max=22)['security_group_rule']
719 cls.addClassResourceCleanup(
720 waiters.wait_for_not_found,
721 cls.lb_mem_SGr_client.delete_security_group_rule,
722 cls.lb_mem_SGr_client.show_security_group_rule,
723 SGr['id'])
724 if CONF.load_balancer.test_with_ipv6:
725 # Create a security group rule to allow 80-81 (test webservers)
726 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
727 direction='ingress',
728 security_group_id=cls.lb_member_sec_group['id'],
729 protocol='tcp',
730 ethertype='IPv6',
731 port_range_min=80,
732 port_range_max=81)['security_group_rule']
733 cls.addClassResourceCleanup(
734 waiters.wait_for_not_found,
735 cls.lb_mem_SGr_client.delete_security_group_rule,
736 cls.lb_mem_SGr_client.show_security_group_rule,
737 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200738 # Create a security group rule to allow UDP 80-81 (test
739 # webservers)
740 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
741 direction='ingress',
742 security_group_id=cls.lb_member_sec_group['id'],
743 protocol='udp',
744 ethertype='IPv6',
745 port_range_min=80,
746 port_range_max=81)['security_group_rule']
747 cls.addClassResourceCleanup(
748 waiters.wait_for_not_found,
749 cls.lb_mem_SGr_client.delete_security_group_rule,
750 cls.lb_mem_SGr_client.show_security_group_rule,
751 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700752 # Create a security group rule to allow 443 (test webservers)
753 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
754 direction='ingress',
755 security_group_id=cls.lb_member_sec_group['id'],
756 protocol='tcp',
757 ethertype='IPv6',
758 port_range_min=443,
759 port_range_max=443)['security_group_rule']
760 cls.addClassResourceCleanup(
761 waiters.wait_for_not_found,
762 cls.lb_mem_SGr_client.delete_security_group_rule,
763 cls.lb_mem_SGr_client.show_security_group_rule,
764 SGr['id'])
Michael Johnson031ecca2020-10-29 16:45:32 -0700765 # Create a security group rule to allow 9443 (test webservers)
766 # Used in the pool encryption client authentication tests
767 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
768 direction='ingress',
769 security_group_id=cls.lb_member_sec_group['id'],
770 protocol='tcp',
771 ethertype='IPv6',
772 port_range_min=9443,
773 port_range_max=9443)['security_group_rule']
774 cls.addClassResourceCleanup(
775 waiters.wait_for_not_found,
776 cls.lb_mem_SGr_client.delete_security_group_rule,
777 cls.lb_mem_SGr_client.show_security_group_rule,
778 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700779 # Create a security group rule to allow 22 (ssh)
780 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
781 direction='ingress',
782 security_group_id=cls.lb_member_sec_group['id'],
783 protocol='tcp',
784 ethertype='IPv6',
785 port_range_min=22,
786 port_range_max=22)['security_group_rule']
787 cls.addClassResourceCleanup(
788 waiters.wait_for_not_found,
789 cls.lb_mem_SGr_client.delete_security_group_rule,
790 cls.lb_mem_SGr_client.show_security_group_rule,
791 SGr['id'])
792
793 LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group))
794
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700795 # Setup backend member reencryption PKI
796 cls._create_backend_reencryption_pki()
797
Adam Harwellcd72b562018-05-07 11:37:22 -0700798 # Create webserver 1 instance
799 server_details = cls._create_webserver('lb_member_webserver1',
800 cls.lb_member_1_net)
801
802 cls.lb_member_webserver1 = server_details['server']
803 cls.webserver1_ip = server_details.get('ipv4_address')
804 cls.webserver1_ipv6 = server_details.get('ipv6_address')
805 cls.webserver1_public_ip = server_details['public_ipv4_address']
806
807 LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format(
808 cls.lb_member_webserver1[const.ID]))
809 LOG.debug('Octavia Setup: webserver1_ip = {}'.format(
810 cls.webserver1_ip))
811 LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format(
812 cls.webserver1_ipv6))
813 LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format(
814 cls.webserver1_public_ip))
815
816 # Create webserver 2 instance
817 server_details = cls._create_webserver('lb_member_webserver2',
818 cls.lb_member_2_net)
819
820 cls.lb_member_webserver2 = server_details['server']
821 cls.webserver2_ip = server_details.get('ipv4_address')
822 cls.webserver2_ipv6 = server_details.get('ipv6_address')
823 cls.webserver2_public_ip = server_details['public_ipv4_address']
824
825 LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format(
826 cls.lb_member_webserver2[const.ID]))
827 LOG.debug('Octavia Setup: webserver2_ip = {}'.format(
828 cls.webserver2_ip))
829 LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format(
830 cls.webserver2_ipv6))
831 LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format(
832 cls.webserver2_public_ip))
833
Michael Johnsonbf916df2018-10-17 10:59:28 -0700834 if CONF.load_balancer.test_with_ipv6:
835 # Enable the IPv6 nic in webserver 1
836 cls._enable_ipv6_nic_webserver(
837 cls.webserver1_public_ip, cls.lb_member_keypair['private_key'],
838 cls.webserver1_ipv6, cls.lb_member_1_subnet_prefix)
839
840 # Enable the IPv6 nic in webserver 2
841 cls._enable_ipv6_nic_webserver(
842 cls.webserver2_public_ip, cls.lb_member_keypair['private_key'],
843 cls.webserver2_ipv6, cls.lb_member_2_subnet_prefix)
844
Adam Harwellcd72b562018-05-07 11:37:22 -0700845 # Set up serving on webserver 1
846 cls._install_start_webserver(cls.webserver1_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700847 cls.lb_member_keypair['private_key'],
848 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700849
850 # Validate webserver 1
Adam Harwelle029af22018-05-24 17:13:28 -0700851 cls._validate_webserver(cls.webserver1_public_ip,
852 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700853
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200854 # Validate udp server 1
855 cls._validate_udp_server(cls.webserver1_public_ip,
856 cls.webserver1_response)
857
Adam Harwellcd72b562018-05-07 11:37:22 -0700858 # Set up serving on webserver 2
859 cls._install_start_webserver(cls.webserver2_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700860 cls.lb_member_keypair['private_key'],
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700861 cls.webserver2_response, revoke_cert=True)
Adam Harwellcd72b562018-05-07 11:37:22 -0700862
863 # Validate webserver 2
Adam Harwelle029af22018-05-24 17:13:28 -0700864 cls._validate_webserver(cls.webserver2_public_ip,
865 cls.webserver2_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700866
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200867 # Validate udp server 2
868 cls._validate_udp_server(cls.webserver2_public_ip,
869 cls.webserver2_response)
870
Adam Harwellcd72b562018-05-07 11:37:22 -0700871 @classmethod
872 def _create_networks(cls):
873 super(LoadBalancerBaseTestWithCompute, cls)._create_networks()
Jude Cross986e3f52017-07-24 14:57:20 -0700874 # Create a router for the subnets (required for the floating IP)
875 router_name = data_utils.rand_name("lb_member_router")
876 result = cls.lb_mem_routers_client.create_router(
877 name=router_name, admin_state_up=True,
878 external_gateway_info=dict(
879 network_id=CONF.network.public_network_id))
880 cls.lb_member_router = result['router']
881 LOG.info('lb_member_router: {}'.format(cls.lb_member_router))
882 cls.addClassResourceCleanup(
883 waiters.wait_for_not_found,
884 cls.lb_mem_routers_client.delete_router,
885 cls.lb_mem_routers_client.show_router,
886 cls.lb_member_router['id'])
887
888 # Add VIP subnet to router
889 cls.lb_mem_routers_client.add_router_interface(
890 cls.lb_member_router['id'],
891 subnet_id=cls.lb_member_vip_subnet['id'])
892 cls.addClassResourceCleanup(
893 waiters.wait_for_not_found,
894 cls.lb_mem_routers_client.remove_router_interface,
895 cls.lb_mem_routers_client.remove_router_interface,
896 cls.lb_member_router['id'],
897 subnet_id=cls.lb_member_vip_subnet['id'])
898
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100899 if (CONF.load_balancer.test_with_ipv6 and
900 CONF.load_balancer.default_router and
901 cls.lb_member_vip_ipv6_subnet_use_subnetpool):
902
903 router_name = CONF.load_balancer.default_router
904 # if lb_member_vip_ipv6_subnet uses devstack's subnetpool,
905 # plug the subnet into the default router
906 router = cls.os_admin.routers_client.list_routers(
907 name=router_name)['routers']
908
909 if len(router) == 1:
910 router = router[0]
911
912 # Add IPv6 VIP subnet to router1
913 cls.os_admin_routers_client.add_router_interface(
914 router['id'],
915 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
916 cls.addClassResourceCleanup(
917 waiters.wait_for_not_found,
918 cls.os_admin_routers_client.remove_router_interface,
919 cls.os_admin_routers_client.remove_router_interface,
920 router['id'],
921 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
922
Jude Cross986e3f52017-07-24 14:57:20 -0700923 # Add member subnet 1 to router
924 cls.lb_mem_routers_client.add_router_interface(
925 cls.lb_member_router['id'],
926 subnet_id=cls.lb_member_1_subnet['id'])
927 cls.addClassResourceCleanup(
928 waiters.wait_for_not_found,
Jude Cross986e3f52017-07-24 14:57:20 -0700929 cls.lb_mem_routers_client.remove_router_interface,
930 cls.lb_mem_routers_client.remove_router_interface,
931 cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id'])
932
933 # Add member subnet 2 to router
934 cls.lb_mem_routers_client.add_router_interface(
935 cls.lb_member_router['id'],
936 subnet_id=cls.lb_member_2_subnet['id'])
937 cls.addClassResourceCleanup(
938 waiters.wait_for_not_found,
939 cls.lb_mem_routers_client.remove_router_interface,
940 cls.lb_mem_routers_client.remove_router_interface,
941 cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id'])
942
943 @classmethod
944 def _create_webserver(cls, name, network):
945 """Creates a webserver with two ports.
946
947 webserver_details dictionary contains:
948 server - The compute server object
949 ipv4_address - The IPv4 address for the server (optional)
950 ipv6_address - The IPv6 address for the server (optional)
951 public_ipv4_address - The publicly accessible IPv4 address for the
952 server, this may be a floating IP (optional)
953
954 :param name: The name of the server to create.
955 :param network: The network to boot the server on.
956 :returns: webserver_details dictionary.
957 """
958 server_kwargs = {
959 'name': data_utils.rand_name(name),
960 'flavorRef': CONF.compute.flavor_ref,
961 'imageRef': CONF.compute.image_ref,
962 'key_name': cls.lb_member_keypair['name']}
963 if (CONF.load_balancer.enable_security_groups and
964 CONF.network_feature_enabled.port_security):
965 server_kwargs['security_groups'] = [
966 {'name': cls.lb_member_sec_group['name']}]
967 if not CONF.load_balancer.disable_boot_network:
968 server_kwargs['networks'] = [{'uuid': network['id']}]
969
970 # Replace the name for clouds that have limitations
971 if CONF.load_balancer.random_server_name_length:
972 r = random.SystemRandom()
973 server_kwargs['name'] = "m{}".format("".join(
974 [r.choice(string.ascii_uppercase + string.digits)
975 for _ in range(
976 CONF.load_balancer.random_server_name_length - 1)]
977 ))
978 if CONF.load_balancer.availability_zone:
979 server_kwargs['availability_zone'] = (
980 CONF.load_balancer.availability_zone)
981
982 server = cls.lb_mem_servers_client.create_server(
983 **server_kwargs)['server']
984 cls.addClassResourceCleanup(
985 waiters.wait_for_not_found,
986 cls.lb_mem_servers_client.delete_server,
987 cls.lb_mem_servers_client.show_server,
988 server['id'])
989 server = waiters.wait_for_status(
990 cls.lb_mem_servers_client.show_server,
991 server['id'], 'status', 'ACTIVE',
992 CONF.load_balancer.build_interval,
993 CONF.load_balancer.build_timeout,
994 root_tag='server')
995 webserver_details = {'server': server}
996 LOG.info('Created server: {}'.format(server))
997
998 addresses = server['addresses']
999 if CONF.load_balancer.disable_boot_network:
1000 instance_network = addresses.values()[0]
1001 else:
1002 instance_network = addresses[network['name']]
1003 for addr in instance_network:
1004 if addr['version'] == 4:
1005 webserver_details['ipv4_address'] = addr['addr']
1006 if addr['version'] == 6:
1007 webserver_details['ipv6_address'] = addr['addr']
1008
1009 if CONF.validation.connect_method == 'floating':
1010 result = cls.lb_mem_ports_client.list_ports(
1011 network_id=network['id'],
1012 mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr'])
1013 port_id = result['ports'][0]['id']
1014 result = cls.lb_mem_float_ip_client.create_floatingip(
1015 floating_network_id=CONF.network.public_network_id,
1016 port_id=port_id)
1017 floating_ip = result['floatingip']
1018 LOG.info('webserver1_floating_ip: {}'.format(floating_ip))
1019 cls.addClassResourceCleanup(
1020 waiters.wait_for_not_found,
1021 cls.lb_mem_float_ip_client.delete_floatingip,
1022 cls.lb_mem_float_ip_client.show_floatingip,
1023 floatingip_id=floating_ip['id'])
1024 webserver_details['public_ipv4_address'] = (
1025 floating_ip['floating_ip_address'])
1026 else:
1027 webserver_details['public_ipv4_address'] = (
1028 instance_network[0]['addr'])
1029
1030 return webserver_details
1031
1032 @classmethod
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001033 def _get_openssh_version(cls):
1034 p = subprocess.Popen(["ssh", "-V"],
1035 stdout=subprocess.PIPE,
1036 stderr=subprocess.PIPE)
1037 output = p.communicate()[1]
1038
1039 try:
1040 m = re.match(r"OpenSSH_(\d+)\.(\d+)", output.decode('utf-8'))
1041 version_maj = int(m.group(1))
1042 version_min = int(m.group(2))
1043 return version_maj, version_min
1044 except Exception:
1045 return None, None
1046
1047 @classmethod
1048 def _need_scp_protocol(cls):
1049 # When using scp >= 8.7, force the use of the SCP protocol,
1050 # the new default (SFTP protocol) doesn't work with
1051 # cirros VMs.
1052 ssh_version = cls._get_openssh_version()
1053 LOG.debug("ssh_version = {}".format(ssh_version))
1054 return (ssh_version[0] > 8 or
1055 (ssh_version[0] == 8 and ssh_version[1] >= 7))
1056
1057 @classmethod
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001058 def _install_start_webserver(cls, ip_address, ssh_key, start_id,
1059 revoke_cert=False):
Michael Johnson27357352020-11-13 13:55:09 -08001060 local_file = CONF.load_balancer.test_server_path
Adam Harwellcd72b562018-05-07 11:37:22 -07001061
1062 linux_client = remote_client.RemoteClient(
Ade Leed0ea4062021-09-06 15:33:27 -04001063 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key,
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +01001064 **cls.remote_client_args())
Adam Harwellcd72b562018-05-07 11:37:22 -07001065 linux_client.validate_authentication()
1066
1067 with tempfile.NamedTemporaryFile() as key:
1068 key.write(ssh_key.encode('utf-8'))
1069 key.flush()
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001070 ssh_extra_args = (
1071 "-o PubkeyAcceptedKeyTypes=+ssh-rsa")
1072 if cls._need_scp_protocol():
1073 ssh_extra_args += " -O"
Adam Harwellcd72b562018-05-07 11:37:22 -07001074 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001075 "{7} "
Adam Harwellcd72b562018-05-07 11:37:22 -07001076 "-o StrictHostKeyChecking=no "
1077 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1078 "-i {2} {3} {4}@{5}:{6}").format(
1079 CONF.load_balancer.scp_connection_timeout,
1080 CONF.load_balancer.scp_connection_attempts,
1081 key.name, local_file, CONF.validation.image_ssh_user,
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001082 ip_address, const.TEST_SERVER_BINARY,
1083 ssh_extra_args)
Adam Harwellcd72b562018-05-07 11:37:22 -07001084 args = shlex.split(cmd)
1085 subprocess_args = {'stdout': subprocess.PIPE,
1086 'stderr': subprocess.STDOUT,
1087 'cwd': None}
1088 proc = subprocess.Popen(args, **subprocess_args)
1089 stdout, stderr = proc.communicate()
1090 if proc.returncode != 0:
1091 raise exceptions.CommandFailed(proc.returncode, cmd,
1092 stdout, stderr)
Gregory Thiemongef72a8862019-08-06 17:25:42 +02001093
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001094 cls._load_member_pki_content(ip_address, key,
1095 revoke_cert=revoke_cert)
1096
Gregory Thiemongef72a8862019-08-06 17:25:42 +02001097 # Enabling memory overcommit allows to run golang static binaries
1098 # compiled with a recent golang toolchain (>=1.11). Those binaries
1099 # allocate a large amount of virtual memory at init time, and this
1100 # allocation fails in tempest's nano flavor (64MB of RAM)
1101 # (golang issue reported in https://github.com/golang/go/issues/28114,
1102 # follow-up: https://github.com/golang/go/issues/28081)
1103 # TODO(gthiemonge): Remove this call when golang issue is resolved.
1104 linux_client.exec_command('sudo sh -c "echo 1 > '
1105 '/proc/sys/vm/overcommit_memory"')
1106
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001107 # The initial process also supports HTTPS and HTTPS with client auth
1108 linux_client.exec_command(
1109 'sudo screen -d -m {0} -port 80 -id {1} -https_port 443 -cert {2} '
1110 '-key {3} -https_client_auth_port 9443 -client_ca {4}'.format(
1111 const.TEST_SERVER_BINARY, start_id, const.TEST_SERVER_CERT,
1112 const.TEST_SERVER_KEY, const.TEST_SERVER_CLIENT_CA))
1113
Adam Harwellcd72b562018-05-07 11:37:22 -07001114 linux_client.exec_command('sudo screen -d -m {0} -port 81 '
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001115 '-id {1}'.format(const.TEST_SERVER_BINARY,
1116 start_id + 1))
Adam Harwellcd72b562018-05-07 11:37:22 -07001117
Michael Johnsonbf916df2018-10-17 10:59:28 -07001118 # Cirros does not configure the assigned IPv6 address by default
1119 # so enable it manually like tempest does here:
1120 # tempest/scenario/test_netowrk_v6.py turn_nic6_on()
1121 @classmethod
1122 def _enable_ipv6_nic_webserver(cls, ip_address, ssh_key,
1123 ipv6_address, ipv6_prefix):
1124 linux_client = remote_client.RemoteClient(
Ade Leed0ea4062021-09-06 15:33:27 -04001125 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key,
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +01001126 **cls.remote_client_args())
Michael Johnsonbf916df2018-10-17 10:59:28 -07001127 linux_client.validate_authentication()
1128
1129 linux_client.exec_command('sudo ip address add {0}/{1} dev '
1130 'eth0'.format(ipv6_address, ipv6_prefix))
1131
Adam Harwellcd72b562018-05-07 11:37:22 -07001132 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -07001133 def _validate_webserver(cls, ip_address, start_id):
1134 URL = 'http://{0}'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001135 cls.validate_URL_response(URL, expected_body=str(start_id))
Jude Cross986e3f52017-07-24 14:57:20 -07001136 URL = 'http://{0}:81'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001137 cls.validate_URL_response(URL, expected_body=str(start_id + 1))
Jude Cross986e3f52017-07-24 14:57:20 -07001138
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001139 @classmethod
1140 def _validate_udp_server(cls, ip_address, start_id):
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001141 res = cls.make_udp_request(ip_address, 80)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001142 if res != str(start_id):
1143 raise Exception("Response from test server doesn't match the "
1144 "expected value ({0} != {1}).".format(
1145 res, str(start_id)))
1146
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001147 res = cls.make_udp_request(ip_address, 81)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001148 if res != str(start_id + 1):
1149 raise Exception("Response from test server doesn't match the "
1150 "expected value ({0} != {1}).".format(
1151 res, str(start_id + 1)))
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001152
1153 @classmethod
1154 def _create_backend_reencryption_pki(cls):
1155 # Create a CA self-signed cert and key for the member test servers
1156 cls.member_ca_cert, cls.member_ca_key = (
1157 cert_utils.generate_ca_cert_and_key())
1158
1159 LOG.debug('Member CA Cert: %s', cls.member_ca_cert.public_bytes(
1160 serialization.Encoding.PEM))
1161 LOG.debug('Member CA private Key: %s', cls.member_ca_key.private_bytes(
1162 encoding=serialization.Encoding.PEM,
1163 format=serialization.PrivateFormat.TraditionalOpenSSL,
1164 encryption_algorithm=serialization.NoEncryption()))
1165 LOG.debug('Member CA public Key: %s',
1166 cls.member_ca_key.public_key().public_bytes(
1167 encoding=serialization.Encoding.PEM,
1168 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1169
1170 # Create the member client authentication CA
1171 cls.member_client_ca_cert, member_client_ca_key = (
1172 cert_utils.generate_ca_cert_and_key())
1173
1174 # Create client cert and key
1175 cls.member_client_cn = uuidutils.generate_uuid()
1176 cls.member_client_cert, cls.member_client_key = (
1177 cert_utils.generate_client_cert_and_key(
1178 cls.member_client_ca_cert, member_client_ca_key,
1179 cls.member_client_cn))
1180 # Note: We are not revoking a client cert here as we don't need to
1181 # test the backend web server CRL checking.
1182
1183 @classmethod
1184 def _load_member_pki_content(cls, ip_address, ssh_key, revoke_cert=False):
1185 # Create webserver certificate and key
1186 cert, key = cert_utils.generate_server_cert_and_key(
1187 cls.member_ca_cert, cls.member_ca_key, ip_address)
1188
1189 LOG.debug('%s Cert: %s', ip_address, cert.public_bytes(
1190 serialization.Encoding.PEM))
1191 LOG.debug('%s private Key: %s', ip_address, key.private_bytes(
1192 encoding=serialization.Encoding.PEM,
1193 format=serialization.PrivateFormat.TraditionalOpenSSL,
1194 encryption_algorithm=serialization.NoEncryption()))
1195 public_key = key.public_key()
1196 LOG.debug('%s public Key: %s', ip_address, public_key.public_bytes(
1197 encoding=serialization.Encoding.PEM,
1198 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1199
1200 # Create a CRL with a revoked certificate
1201 if revoke_cert:
1202 # Create a CRL with webserver 2 revoked
1203 cls.member_crl = cert_utils.generate_certificate_revocation_list(
1204 cls.member_ca_cert, cls.member_ca_key, cert)
1205
1206 # Load the certificate, key, and client CA certificate into the
1207 # test server.
1208 with tempfile.TemporaryDirectory() as tmpdir:
1209 os.umask(0)
1210 files_to_send = []
1211 cert_filename = os.path.join(tmpdir, const.CERT_PEM)
1212 files_to_send.append(cert_filename)
1213 with open(os.open(cert_filename, os.O_CREAT | os.O_WRONLY,
1214 0o700), 'w') as fh:
1215 fh.write(cert.public_bytes(
1216 serialization.Encoding.PEM).decode('utf-8'))
1217 fh.flush()
1218 key_filename = os.path.join(tmpdir, const.KEY_PEM)
1219 files_to_send.append(key_filename)
1220 with open(os.open(key_filename, os.O_CREAT | os.O_WRONLY,
1221 0o700), 'w') as fh:
1222 fh.write(key.private_bytes(
1223 encoding=serialization.Encoding.PEM,
1224 format=serialization.PrivateFormat.TraditionalOpenSSL,
1225 encryption_algorithm=serialization.NoEncryption()).decode(
1226 'utf-8'))
1227 fh.flush()
1228 client_ca_filename = os.path.join(tmpdir, const.CLIENT_CA_PEM)
1229 files_to_send.append(client_ca_filename)
1230 with open(os.open(client_ca_filename, os.O_CREAT | os.O_WRONLY,
1231 0o700), 'w') as fh:
1232 fh.write(cls.member_client_ca_cert.public_bytes(
1233 serialization.Encoding.PEM).decode('utf-8'))
1234 fh.flush()
1235
1236 # For security, we don't want to use a shell that can glob
1237 # the file names, so iterate over them.
1238 subprocess_args = {'stdout': subprocess.PIPE,
1239 'stderr': subprocess.STDOUT,
1240 'cwd': None}
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001241 ssh_extra_args = (
1242 "-o PubkeyAcceptedKeyTypes=+ssh-rsa")
1243 if cls._need_scp_protocol():
1244 ssh_extra_args += " -O"
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001245 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001246 "{9} "
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001247 "-o StrictHostKeyChecking=no "
1248 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1249 "-i {2} {3} {4} {5} {6}@{7}:{8}").format(
1250 CONF.load_balancer.scp_connection_timeout,
1251 CONF.load_balancer.scp_connection_attempts,
1252 ssh_key.name, cert_filename, key_filename, client_ca_filename,
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001253 CONF.validation.image_ssh_user, ip_address, const.DEV_SHM_PATH,
1254 ssh_extra_args)
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001255 args = shlex.split(cmd)
1256 proc = subprocess.Popen(args, **subprocess_args)
1257 stdout, stderr = proc.communicate()
1258 if proc.returncode != 0:
1259 raise exceptions.CommandFailed(proc.returncode, cmd,
1260 stdout, stderr)