blob: 5592571118e6cfb16dc9d46393d9bf1ed0a9c39d [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]]
59 elif CONF.load_balancer.enforce_new_defaults:
Michael Johnson6006de72021-02-21 01:42:39 +000060 credentials = [
61 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role],
62 ['lb_observer', CONF.load_balancer.observer_role, 'reader'],
63 ['lb_global_observer', CONF.load_balancer.global_observer_role,
64 'reader'],
65 ['lb_member', CONF.load_balancer.member_role, 'member'],
66 ['lb_member2', CONF.load_balancer.member_role, 'member'],
67 ['lb_member_not_default_member', CONF.load_balancer.member_role]]
68 else:
69 credentials = [
70 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role],
71 ['lb_observer', CONF.load_balancer.observer_role, 'reader'],
72 ['lb_global_observer', CONF.load_balancer.global_observer_role,
73 'reader'],
74 ['lb_member', CONF.load_balancer.member_role],
75 ['lb_member2', CONF.load_balancer.member_role]]
76
77 # If scope enforcement is enabled, add in the system scope credentials.
78 # The project scope is already handled by the above credentials.
79 if CONF.enforce_scope.octavia:
80 credentials.extend(['system_admin', 'system_reader'])
81
82 # A tuple of credentials that will be allocated by tempest using the
83 # 'credentials' list above. These are used to build RBAC test lists.
84 allocated_creds = []
85 for cred in credentials:
86 if isinstance(cred, list):
87 allocated_creds.append('os_roles_' + cred[0])
88 else:
89 allocated_creds.append('os_' + cred)
90 # Tests shall not mess with the list of allocated credentials
91 allocated_credentials = tuple(allocated_creds)
Jude Cross986e3f52017-07-24 14:57:20 -070092
Adam Harwelle029af22018-05-24 17:13:28 -070093 webserver1_response = 1
94 webserver2_response = 5
Michael Johnsondfd818a2018-08-21 20:54:54 -070095 used_ips = []
Jude Cross986e3f52017-07-24 14:57:20 -070096
Michael Johnson89bdbcd2020-03-19 15:59:19 -070097 SRC_PORT_NUMBER_MIN = 32768
98 SRC_PORT_NUMBER_MAX = 61000
Gregory Thiemonge29d17902019-04-30 15:06:17 +020099 src_port_number = SRC_PORT_NUMBER_MIN
100
Jude Cross986e3f52017-07-24 14:57:20 -0700101 @classmethod
102 def skip_checks(cls):
103 """Check if we should skip all of the children tests."""
104 super(LoadBalancerBaseTest, cls).skip_checks()
105
106 service_list = {
107 'load_balancer': CONF.service_available.load_balancer,
108 }
109
110 live_service_list = {
111 'compute': CONF.service_available.nova,
112 'image': CONF.service_available.glance,
113 'neutron': CONF.service_available.neutron
114 }
115
116 if not CONF.load_balancer.test_with_noop:
117 service_list.update(live_service_list)
118
119 for service, available in service_list.items():
120 if not available:
zhangzs2a6cf672018-11-10 16:13:11 +0800121 skip_msg = ("{0} skipped as {1} service is not "
Jude Cross986e3f52017-07-24 14:57:20 -0700122 "available.".format(cls.__name__, service))
123 raise cls.skipException(skip_msg)
124
125 # We must be able to reach our VIP and instances
126 if not (CONF.network.project_networks_reachable
127 or CONF.network.public_network_id):
128 msg = ('Either project_networks_reachable must be "true", or '
129 'public_network_id must be defined.')
130 raise cls.skipException(msg)
131
132 @classmethod
133 def setup_credentials(cls):
134 """Setup test credentials and network resources."""
135 # Do not auto create network resources
136 cls.set_network_resources()
137 super(LoadBalancerBaseTest, cls).setup_credentials()
138
Michael Johnson6006de72021-02-21 01:42:39 +0000139 # Log the user roles for this test run
140 role_name_cache = {}
141 for cred in cls.credentials:
142 user_roles = []
143 if isinstance(cred, list):
144 user_name = cred[0]
145 cred_obj = getattr(cls, 'os_roles_' + cred[0])
146 else:
147 user_name = cred
148 cred_obj = getattr(cls, 'os_' + cred)
149 params = {'user.id': cred_obj.credentials.user_id,
150 'project.id': cred_obj.credentials.project_id}
151 roles = cls.os_admin.role_assignments_client.list_role_assignments(
152 **params)['role_assignments']
153 for role in roles:
154 role_id = role['role']['id']
155 try:
156 role_name = role_name_cache[role_id]
157 except KeyError:
158 role_name = cls.os_admin.roles_v3_client.show_role(
159 role_id)['role']['name']
160 role_name_cache[role_id] = role_name
161 user_roles.append([role_name, role['scope']])
162 LOG.info("User %s has roles: %s", user_name, user_roles)
163
Jude Cross986e3f52017-07-24 14:57:20 -0700164 @classmethod
165 def setup_clients(cls):
166 """Setup client aliases."""
167 super(LoadBalancerBaseTest, cls).setup_clients()
Michael Johnson29d8e612021-06-23 16:16:12 +0000168 lb_admin_prefix = cls.os_roles_lb_admin.load_balancer_v2
Jude Cross986e3f52017-07-24 14:57:20 -0700169 cls.lb_mem_float_ip_client = cls.os_roles_lb_member.floating_ips_client
170 cls.lb_mem_keypairs_client = cls.os_roles_lb_member.keypairs_client
171 cls.lb_mem_net_client = cls.os_roles_lb_member.networks_client
172 cls.lb_mem_ports_client = cls.os_roles_lb_member.ports_client
173 cls.lb_mem_routers_client = cls.os_roles_lb_member.routers_client
174 cls.lb_mem_SG_client = cls.os_roles_lb_member.security_groups_client
175 cls.lb_mem_SGr_client = (
176 cls.os_roles_lb_member.security_group_rules_client)
177 cls.lb_mem_servers_client = cls.os_roles_lb_member.servers_client
178 cls.lb_mem_subnet_client = cls.os_roles_lb_member.subnets_client
Michael Johnson29d8e612021-06-23 16:16:12 +0000179 cls.mem_lb_client = (
180 cls.os_roles_lb_member.load_balancer_v2.LoadbalancerClient())
181 cls.mem_listener_client = (
182 cls.os_roles_lb_member.load_balancer_v2.ListenerClient())
183 cls.mem_pool_client = (
184 cls.os_roles_lb_member.load_balancer_v2.PoolClient())
185 cls.mem_member_client = (
186 cls.os_roles_lb_member.load_balancer_v2.MemberClient())
Adam Harwell60ed9d92018-05-10 13:23:13 -0700187 cls.mem_healthmonitor_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000188 cls.os_roles_lb_member.load_balancer_v2.HealthMonitorClient())
189 cls.mem_l7policy_client = (
190 cls.os_roles_lb_member.load_balancer_v2.L7PolicyClient())
191 cls.mem_l7rule_client = (
192 cls.os_roles_lb_member.load_balancer_v2.L7RuleClient())
193 cls.lb_admin_amphora_client = lb_admin_prefix.AmphoraClient()
Michael Johnsonaff2e862019-01-11 16:38:00 -0800194 cls.lb_admin_flavor_profile_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000195 lb_admin_prefix.FlavorProfileClient())
196 cls.lb_admin_flavor_client = lb_admin_prefix.FlavorClient()
197 cls.mem_flavor_client = (
198 cls.os_roles_lb_member.load_balancer_v2.FlavorClient())
199 cls.mem_provider_client = (
200 cls.os_roles_lb_member.load_balancer_v2.ProviderClient())
Carlos Goncalvesc2e12162019-02-14 23:57:44 +0100201 cls.os_admin_servers_client = cls.os_admin.servers_client
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100202 cls.os_admin_routers_client = cls.os_admin.routers_client
203 cls.os_admin_subnetpools_client = cls.os_admin.subnetpools_client
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800204 cls.lb_admin_flavor_capabilities_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000205 lb_admin_prefix.FlavorCapabilitiesClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800206 cls.lb_admin_availability_zone_capabilities_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000207 lb_admin_prefix.AvailabilityZoneCapabilitiesClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800208 cls.lb_admin_availability_zone_profile_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000209 lb_admin_prefix.AvailabilityZoneProfileClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800210 cls.lb_admin_availability_zone_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000211 lb_admin_prefix.AvailabilityZoneClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800212 cls.mem_availability_zone_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000213 cls.os_roles_lb_member.load_balancer_v2.AvailabilityZoneClient())
Jude Cross986e3f52017-07-24 14:57:20 -0700214
215 @classmethod
216 def resource_setup(cls):
217 """Setup resources needed by the tests."""
218 super(LoadBalancerBaseTest, cls).resource_setup()
219
220 conf_lb = CONF.load_balancer
221
Michael Johnsondfd818a2018-08-21 20:54:54 -0700222 cls.api_version = cls.mem_lb_client.get_max_api_version()
223
Jude Cross986e3f52017-07-24 14:57:20 -0700224 if conf_lb.test_subnet_override and not conf_lb.test_network_override:
225 raise exceptions.InvalidConfiguration(
226 "Configuration value test_network_override must be "
227 "specified if test_subnet_override is used.")
228
Michael Johnson6a9236a2020-08-04 23:54:54 +0000229 # TODO(johnsom) Remove this
Maciej Józefczykb6df5f82019-12-10 10:12:30 +0000230 # Get loadbalancing algorithms supported by provider driver.
231 try:
232 algorithms = const.SUPPORTED_LB_ALGORITHMS[
233 CONF.load_balancer.provider]
234 except KeyError:
235 algorithms = const.SUPPORTED_LB_ALGORITHMS['default']
236 # Set default algorithm as first from the list.
237 cls.lb_algorithm = algorithms[0]
238
Jude Cross986e3f52017-07-24 14:57:20 -0700239 show_subnet = cls.lb_mem_subnet_client.show_subnet
240 if CONF.load_balancer.test_with_noop:
241 cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()}
242 cls.lb_member_vip_subnet = {'id': uuidutils.generate_uuid()}
243 cls.lb_member_1_net = {'id': uuidutils.generate_uuid()}
244 cls.lb_member_1_subnet = {'id': uuidutils.generate_uuid()}
245 cls.lb_member_2_net = {'id': uuidutils.generate_uuid()}
246 cls.lb_member_2_subnet = {'id': uuidutils.generate_uuid()}
247 if CONF.load_balancer.test_with_ipv6:
Michael Johnson5a16ad32018-10-18 14:49:11 -0700248 cls.lb_member_vip_ipv6_net = {'id': uuidutils.generate_uuid()}
Jude Cross986e3f52017-07-24 14:57:20 -0700249 cls.lb_member_vip_ipv6_subnet = {'id':
250 uuidutils.generate_uuid()}
251 cls.lb_member_1_ipv6_subnet = {'id': uuidutils.generate_uuid()}
252 cls.lb_member_2_ipv6_subnet = {'id': uuidutils.generate_uuid()}
Michael Johnson590fbe12019-07-03 14:30:01 -0700253 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700254 return
255 elif CONF.load_balancer.test_network_override:
256 if conf_lb.test_subnet_override:
257 override_subnet = show_subnet(conf_lb.test_subnet_override)
258 else:
259 override_subnet = None
260
261 show_net = cls.lb_mem_net_client.show_network
262 override_network = show_net(conf_lb.test_network_override)
263 override_network = override_network.get('network')
264
265 cls.lb_member_vip_net = override_network
266 cls.lb_member_vip_subnet = override_subnet
267 cls.lb_member_1_net = override_network
268 cls.lb_member_1_subnet = override_subnet
269 cls.lb_member_2_net = override_network
270 cls.lb_member_2_subnet = override_subnet
271
272 if (CONF.load_balancer.test_with_ipv6 and
273 conf_lb.test_IPv6_subnet_override):
274 override_ipv6_subnet = show_subnet(
275 conf_lb.test_IPv6_subnet_override)
276 cls.lb_member_vip_ipv6_subnet = override_ipv6_subnet
277 cls.lb_member_1_ipv6_subnet = override_ipv6_subnet
278 cls.lb_member_2_ipv6_subnet = override_ipv6_subnet
Michael Johnson590fbe12019-07-03 14:30:01 -0700279 cls.lb_member_vip_ipv6_subnet_stateful = False
280 if (override_ipv6_subnet[0]['ipv6_address_mode'] ==
281 'dhcpv6-stateful'):
282 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700283 else:
284 cls.lb_member_vip_ipv6_subnet = None
285 cls.lb_member_1_ipv6_subnet = None
286 cls.lb_member_2_ipv6_subnet = None
287 else:
288 cls._create_networks()
289
290 LOG.debug('Octavia Setup: lb_member_vip_net = {}'.format(
291 cls.lb_member_vip_net[const.ID]))
292 if cls.lb_member_vip_subnet:
293 LOG.debug('Octavia Setup: lb_member_vip_subnet = {}'.format(
294 cls.lb_member_vip_subnet[const.ID]))
295 LOG.debug('Octavia Setup: lb_member_1_net = {}'.format(
296 cls.lb_member_1_net[const.ID]))
297 if cls.lb_member_1_subnet:
298 LOG.debug('Octavia Setup: lb_member_1_subnet = {}'.format(
299 cls.lb_member_1_subnet[const.ID]))
300 LOG.debug('Octavia Setup: lb_member_2_net = {}'.format(
301 cls.lb_member_2_net[const.ID]))
302 if cls.lb_member_2_subnet:
303 LOG.debug('Octavia Setup: lb_member_2_subnet = {}'.format(
304 cls.lb_member_2_subnet[const.ID]))
Michael Johnson124ba8b2018-08-30 16:06:05 -0700305 if CONF.load_balancer.test_with_ipv6:
306 if cls.lb_member_vip_ipv6_subnet:
307 LOG.debug('Octavia Setup: lb_member_vip_ipv6_subnet = '
308 '{}'.format(cls.lb_member_vip_ipv6_subnet[const.ID]))
309 if cls.lb_member_1_ipv6_subnet:
310 LOG.debug('Octavia Setup: lb_member_1_ipv6_subnet = {}'.format(
311 cls.lb_member_1_ipv6_subnet[const.ID]))
312 if cls.lb_member_2_ipv6_subnet:
313 LOG.debug('Octavia Setup: lb_member_2_ipv6_subnet = {}'.format(
314 cls.lb_member_2_ipv6_subnet[const.ID]))
Jude Cross986e3f52017-07-24 14:57:20 -0700315
Jude Cross986e3f52017-07-24 14:57:20 -0700316 @classmethod
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800317 # Neutron can be slow to clean up ports from the subnets/networks.
318 # Retry this delete a few times if we get a "Conflict" error to give
319 # neutron time to fully cleanup the ports.
320 @tenacity.retry(
321 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
322 wait=tenacity.wait_incrementing(
323 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
324 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
325 def _logging_delete_network(cls, net_id):
326 try:
327 cls.lb_mem_net_client.delete_network(net_id)
328 except Exception:
329 LOG.error('Unable to delete network {}. Active ports:'.format(
330 net_id))
331 LOG.error(cls.lb_mem_ports_client.list_ports())
332 raise
333
334 @classmethod
335 # Neutron can be slow to clean up ports from the subnets/networks.
336 # Retry this delete a few times if we get a "Conflict" error to give
337 # neutron time to fully cleanup the ports.
338 @tenacity.retry(
339 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
340 wait=tenacity.wait_incrementing(
341 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
342 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
343 def _logging_delete_subnet(cls, subnet_id):
344 try:
345 cls.lb_mem_subnet_client.delete_subnet(subnet_id)
346 except Exception:
347 LOG.error('Unable to delete subnet {}. Active ports:'.format(
348 subnet_id))
349 LOG.error(cls.lb_mem_ports_client.list_ports())
350 raise
351
352 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -0700353 def _create_networks(cls):
354 """Creates networks, subnets, and routers used in tests.
355
356 The following are expected to be defined and available to the tests:
357 cls.lb_member_vip_net
358 cls.lb_member_vip_subnet
359 cls.lb_member_vip_ipv6_subnet (optional)
360 cls.lb_member_1_net
361 cls.lb_member_1_subnet
362 cls.lb_member_1_ipv6_subnet (optional)
363 cls.lb_member_2_net
364 cls.lb_member_2_subnet
365 cls.lb_member_2_ipv6_subnet (optional)
366 """
367
368 # Create tenant VIP network
369 network_kwargs = {
370 'name': data_utils.rand_name("lb_member_vip_network")}
371 if CONF.network_feature_enabled.port_security:
Andreas Jaeger4215b702020-03-28 20:13:46 +0100372 # Note: Allowed Address Pairs requires port security
373 network_kwargs['port_security_enabled'] = True
Jude Cross986e3f52017-07-24 14:57:20 -0700374 result = cls.lb_mem_net_client.create_network(**network_kwargs)
375 cls.lb_member_vip_net = result['network']
376 LOG.info('lb_member_vip_net: {}'.format(cls.lb_member_vip_net))
377 cls.addClassResourceCleanup(
378 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800379 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700380 cls.lb_mem_net_client.show_network,
381 cls.lb_member_vip_net['id'])
382
383 # Create tenant VIP subnet
384 subnet_kwargs = {
385 'name': data_utils.rand_name("lb_member_vip_subnet"),
386 'network_id': cls.lb_member_vip_net['id'],
387 'cidr': CONF.load_balancer.vip_subnet_cidr,
388 'ip_version': 4}
389 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
390 cls.lb_member_vip_subnet = result['subnet']
391 LOG.info('lb_member_vip_subnet: {}'.format(cls.lb_member_vip_subnet))
392 cls.addClassResourceCleanup(
393 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800394 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700395 cls.lb_mem_subnet_client.show_subnet,
396 cls.lb_member_vip_subnet['id'])
397
398 # Create tenant VIP IPv6 subnet
399 if CONF.load_balancer.test_with_ipv6:
Michael Johnson590fbe12019-07-03 14:30:01 -0700400 cls.lb_member_vip_ipv6_subnet_stateful = False
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100401 cls.lb_member_vip_ipv6_subnet_use_subnetpool = False
402 subnet_kwargs = {
403 'name': data_utils.rand_name("lb_member_vip_ipv6_subnet"),
404 'network_id': cls.lb_member_vip_net['id'],
405 'ip_version': 6}
406
407 # Use a CIDR from devstack's default IPv6 subnetpool if it exists,
408 # the subnetpool's cidr is routable from the devstack node
409 # through the default router
410 subnetpool_name = CONF.load_balancer.default_ipv6_subnetpool
411 if subnetpool_name:
412 subnetpool = cls.os_admin_subnetpools_client.list_subnetpools(
413 name=subnetpool_name)['subnetpools']
414 if len(subnetpool) == 1:
415 subnetpool = subnetpool[0]
416 subnet_kwargs['subnetpool_id'] = subnetpool['id']
417 cls.lb_member_vip_ipv6_subnet_use_subnetpool = True
418
419 if 'subnetpool_id' not in subnet_kwargs:
420 subnet_kwargs['cidr'] = (
421 CONF.load_balancer.vip_ipv6_subnet_cidr)
422
423 result = cls.lb_mem_subnet_client.create_subnet(
424 **subnet_kwargs)
425 cls.lb_member_vip_ipv6_net = cls.lb_member_vip_net
426 cls.lb_member_vip_ipv6_subnet = result['subnet']
427 cls.addClassResourceCleanup(
428 waiters.wait_for_not_found,
429 cls._logging_delete_subnet,
430 cls.lb_mem_subnet_client.show_subnet,
431 cls.lb_member_vip_ipv6_subnet['id'])
Carlos Goncalves84af48c2019-07-25 15:51:30 +0200432
Jude Cross986e3f52017-07-24 14:57:20 -0700433 LOG.info('lb_member_vip_ipv6_subnet: {}'.format(
434 cls.lb_member_vip_ipv6_subnet))
Jude Cross986e3f52017-07-24 14:57:20 -0700435
436 # Create tenant member 1 network
437 network_kwargs = {
438 'name': data_utils.rand_name("lb_member_1_network")}
439 if CONF.network_feature_enabled.port_security:
440 if CONF.load_balancer.enable_security_groups:
441 network_kwargs['port_security_enabled'] = True
442 else:
443 network_kwargs['port_security_enabled'] = False
444 result = cls.lb_mem_net_client.create_network(**network_kwargs)
445 cls.lb_member_1_net = result['network']
446 LOG.info('lb_member_1_net: {}'.format(cls.lb_member_1_net))
447 cls.addClassResourceCleanup(
448 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800449 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700450 cls.lb_mem_net_client.show_network,
451 cls.lb_member_1_net['id'])
452
453 # Create tenant member 1 subnet
454 subnet_kwargs = {
455 'name': data_utils.rand_name("lb_member_1_subnet"),
456 'network_id': cls.lb_member_1_net['id'],
457 'cidr': CONF.load_balancer.member_1_ipv4_subnet_cidr,
458 'ip_version': 4}
459 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
460 cls.lb_member_1_subnet = result['subnet']
461 LOG.info('lb_member_1_subnet: {}'.format(cls.lb_member_1_subnet))
462 cls.addClassResourceCleanup(
463 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800464 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700465 cls.lb_mem_subnet_client.show_subnet,
466 cls.lb_member_1_subnet['id'])
467
468 # Create tenant member 1 ipv6 subnet
469 if CONF.load_balancer.test_with_ipv6:
470 subnet_kwargs = {
471 'name': data_utils.rand_name("lb_member_1_ipv6_subnet"),
472 'network_id': cls.lb_member_1_net['id'],
473 'cidr': CONF.load_balancer.member_1_ipv6_subnet_cidr,
474 'ip_version': 6}
475 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700476 cls.lb_member_1_subnet_prefix = (
477 CONF.load_balancer.member_1_ipv6_subnet_cidr.rpartition('/')[2]
478 )
479 assert(cls.lb_member_1_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700480 cls.lb_member_1_ipv6_subnet = result['subnet']
481 LOG.info('lb_member_1_ipv6_subnet: {}'.format(
482 cls.lb_member_1_ipv6_subnet))
483 cls.addClassResourceCleanup(
484 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800485 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700486 cls.lb_mem_subnet_client.show_subnet,
487 cls.lb_member_1_ipv6_subnet['id'])
488
489 # Create tenant member 2 network
490 network_kwargs = {
491 'name': data_utils.rand_name("lb_member_2_network")}
492 if CONF.network_feature_enabled.port_security:
493 if CONF.load_balancer.enable_security_groups:
494 network_kwargs['port_security_enabled'] = True
495 else:
496 network_kwargs['port_security_enabled'] = False
497 result = cls.lb_mem_net_client.create_network(**network_kwargs)
498 cls.lb_member_2_net = result['network']
499 LOG.info('lb_member_2_net: {}'.format(cls.lb_member_2_net))
500 cls.addClassResourceCleanup(
501 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800502 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700503 cls.lb_mem_net_client.show_network,
504 cls.lb_member_2_net['id'])
505
506 # Create tenant member 2 subnet
507 subnet_kwargs = {
508 'name': data_utils.rand_name("lb_member_2_subnet"),
509 'network_id': cls.lb_member_2_net['id'],
510 'cidr': CONF.load_balancer.member_2_ipv4_subnet_cidr,
511 'ip_version': 4}
512 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
513 cls.lb_member_2_subnet = result['subnet']
514 LOG.info('lb_member_2_subnet: {}'.format(cls.lb_member_2_subnet))
515 cls.addClassResourceCleanup(
516 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800517 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700518 cls.lb_mem_subnet_client.show_subnet,
519 cls.lb_member_2_subnet['id'])
520
521 # Create tenant member 2 ipv6 subnet
522 if CONF.load_balancer.test_with_ipv6:
523 subnet_kwargs = {
524 'name': data_utils.rand_name("lb_member_2_ipv6_subnet"),
525 'network_id': cls.lb_member_2_net['id'],
526 'cidr': CONF.load_balancer.member_2_ipv6_subnet_cidr,
527 'ip_version': 6}
528 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700529 cls.lb_member_2_subnet_prefix = (
530 CONF.load_balancer.member_2_ipv6_subnet_cidr.rpartition('/')[2]
531 )
532 assert(cls.lb_member_2_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700533 cls.lb_member_2_ipv6_subnet = result['subnet']
534 LOG.info('lb_member_2_ipv6_subnet: {}'.format(
535 cls.lb_member_2_ipv6_subnet))
536 cls.addClassResourceCleanup(
537 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800538 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700539 cls.lb_mem_subnet_client.show_subnet,
540 cls.lb_member_2_ipv6_subnet['id'])
541
Adam Harwellcd72b562018-05-07 11:37:22 -0700542 @classmethod
Michael Johnson07c9a632018-06-07 13:27:42 -0700543 def _setup_lb_network_kwargs(cls, lb_kwargs, ip_version=None,
544 use_fixed_ip=False):
Adam Harwell60ed9d92018-05-10 13:23:13 -0700545 if not ip_version:
546 ip_version = 6 if CONF.load_balancer.test_with_ipv6 else 4
Michael Johnson5a16ad32018-10-18 14:49:11 -0700547 if cls.lb_member_vip_subnet or cls.lb_member_vip_ipv6_subnet:
Adam Harwellcd72b562018-05-07 11:37:22 -0700548 ip_index = data_utils.rand_int_id(start=10, end=100)
Michael Johnsondfd818a2018-08-21 20:54:54 -0700549 while ip_index in cls.used_ips:
550 ip_index = data_utils.rand_int_id(start=10, end=100)
551 cls.used_ips.append(ip_index)
Adam Harwellcd72b562018-05-07 11:37:22 -0700552 if ip_version == 4:
Adam Harwellcd72b562018-05-07 11:37:22 -0700553 subnet_id = cls.lb_member_vip_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700554 if CONF.load_balancer.test_with_noop:
555 lb_vip_address = '198.18.33.33'
556 else:
557 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
558 network = ipaddress.IPv4Network(subnet['subnet']['cidr'])
559 lb_vip_address = str(network[ip_index])
Adam Harwellcd72b562018-05-07 11:37:22 -0700560 else:
Adam Harwellcd72b562018-05-07 11:37:22 -0700561 subnet_id = cls.lb_member_vip_ipv6_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700562 if CONF.load_balancer.test_with_noop:
563 lb_vip_address = '2001:db8:33:33:33:33:33:33'
564 else:
565 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
566 network = ipaddress.IPv6Network(subnet['subnet']['cidr'])
567 lb_vip_address = str(network[ip_index])
Michael Johnson590fbe12019-07-03 14:30:01 -0700568 # If the subnet is IPv6 slaac or dhcpv6-stateless
569 # neutron does not allow a fixed IP
570 if not cls.lb_member_vip_ipv6_subnet_stateful:
571 use_fixed_ip = False
Adam Harwellcd72b562018-05-07 11:37:22 -0700572 lb_kwargs[const.VIP_SUBNET_ID] = subnet_id
Michael Johnson07c9a632018-06-07 13:27:42 -0700573 if use_fixed_ip:
574 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700575 if CONF.load_balancer.test_with_noop:
576 lb_kwargs[const.VIP_NETWORK_ID] = (
577 cls.lb_member_vip_net[const.ID])
Carlos Goncalvesbb238552020-01-15 10:10:55 +0000578 if ip_version == 6:
579 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700580 else:
581 lb_kwargs[const.VIP_NETWORK_ID] = cls.lb_member_vip_net[const.ID]
582 lb_kwargs[const.VIP_SUBNET_ID] = None
583
584
585class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest):
586 @classmethod
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +0100587 def remote_client_args(cls):
588 # In case we're using octavia-tempest-plugin with old tempest releases
589 # (for instance on stable/train) that don't support ssh_key_type, catch
590 # the exception and don't pass any argument
591 args = {}
592 try:
593 args['ssh_key_type'] = CONF.validation.ssh_key_type
594 except cfg.NoSuchOptError:
595 pass
596 return args
597
598 @classmethod
Adam Harwellcd72b562018-05-07 11:37:22 -0700599 def resource_setup(cls):
600 super(LoadBalancerBaseTestWithCompute, cls).resource_setup()
601 # If validation is disabled in this cloud, we won't be able to
602 # start the webservers, so don't even boot them.
603 if not CONF.validation.run_validation:
604 return
605
606 # Create a keypair for the webservers
607 keypair_name = data_utils.rand_name('lb_member_keypair')
608 result = cls.lb_mem_keypairs_client.create_keypair(
609 name=keypair_name)
610 cls.lb_member_keypair = result['keypair']
611 LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair))
612 cls.addClassResourceCleanup(
613 waiters.wait_for_not_found,
614 cls.lb_mem_keypairs_client.delete_keypair,
615 cls.lb_mem_keypairs_client.show_keypair,
616 keypair_name)
617
618 if (CONF.load_balancer.enable_security_groups and
619 CONF.network_feature_enabled.port_security):
620 # Set up the security group for the webservers
621 SG_name = data_utils.rand_name('lb_member_SG')
622 cls.lb_member_sec_group = (
623 cls.lb_mem_SG_client.create_security_group(
624 name=SG_name)['security_group'])
625 cls.addClassResourceCleanup(
626 waiters.wait_for_not_found,
627 cls.lb_mem_SG_client.delete_security_group,
628 cls.lb_mem_SG_client.show_security_group,
629 cls.lb_member_sec_group['id'])
630
631 # Create a security group rule to allow 80-81 (test webservers)
632 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
633 direction='ingress',
634 security_group_id=cls.lb_member_sec_group['id'],
635 protocol='tcp',
636 ethertype='IPv4',
637 port_range_min=80,
638 port_range_max=81)['security_group_rule']
639 cls.addClassResourceCleanup(
640 waiters.wait_for_not_found,
641 cls.lb_mem_SGr_client.delete_security_group_rule,
642 cls.lb_mem_SGr_client.show_security_group_rule,
643 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200644 # Create a security group rule to allow UDP 80-81 (test webservers)
645 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
646 direction='ingress',
647 security_group_id=cls.lb_member_sec_group['id'],
648 protocol='udp',
649 ethertype='IPv4',
650 port_range_min=80,
651 port_range_max=81)['security_group_rule']
652 cls.addClassResourceCleanup(
653 waiters.wait_for_not_found,
654 cls.lb_mem_SGr_client.delete_security_group_rule,
655 cls.lb_mem_SGr_client.show_security_group_rule,
656 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700657 # Create a security group rule to allow 443 (test webservers)
658 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
659 direction='ingress',
660 security_group_id=cls.lb_member_sec_group['id'],
661 protocol='tcp',
662 ethertype='IPv4',
663 port_range_min=443,
664 port_range_max=443)['security_group_rule']
665 cls.addClassResourceCleanup(
666 waiters.wait_for_not_found,
667 cls.lb_mem_SGr_client.delete_security_group_rule,
668 cls.lb_mem_SGr_client.show_security_group_rule,
669 SGr['id'])
Michael Johnson031ecca2020-10-29 16:45:32 -0700670 # Create a security group rule to allow 9443 (test webservers)
671 # Used in the pool backend encryption client authentication tests
672 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
673 direction='ingress',
674 security_group_id=cls.lb_member_sec_group['id'],
675 protocol='tcp',
676 ethertype='IPv4',
677 port_range_min=9443,
678 port_range_max=9443)['security_group_rule']
679 cls.addClassResourceCleanup(
680 waiters.wait_for_not_found,
681 cls.lb_mem_SGr_client.delete_security_group_rule,
682 cls.lb_mem_SGr_client.show_security_group_rule,
683 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200684 # Create a security group rule to allow UDP 9999 (test webservers)
685 # Port 9999 is used to illustrate health monitor ERRORs on closed
686 # ports.
687 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
688 direction='ingress',
689 security_group_id=cls.lb_member_sec_group['id'],
690 protocol='udp',
691 ethertype='IPv4',
692 port_range_min=9999,
693 port_range_max=9999)['security_group_rule']
694 cls.addClassResourceCleanup(
695 waiters.wait_for_not_found,
696 cls.lb_mem_SGr_client.delete_security_group_rule,
697 cls.lb_mem_SGr_client.show_security_group_rule,
698 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700699 # Create a security group rule to allow 22 (ssh)
700 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
701 direction='ingress',
702 security_group_id=cls.lb_member_sec_group['id'],
703 protocol='tcp',
704 ethertype='IPv4',
705 port_range_min=22,
706 port_range_max=22)['security_group_rule']
707 cls.addClassResourceCleanup(
708 waiters.wait_for_not_found,
709 cls.lb_mem_SGr_client.delete_security_group_rule,
710 cls.lb_mem_SGr_client.show_security_group_rule,
711 SGr['id'])
712 if CONF.load_balancer.test_with_ipv6:
713 # Create a security group rule to allow 80-81 (test webservers)
714 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
715 direction='ingress',
716 security_group_id=cls.lb_member_sec_group['id'],
717 protocol='tcp',
718 ethertype='IPv6',
719 port_range_min=80,
720 port_range_max=81)['security_group_rule']
721 cls.addClassResourceCleanup(
722 waiters.wait_for_not_found,
723 cls.lb_mem_SGr_client.delete_security_group_rule,
724 cls.lb_mem_SGr_client.show_security_group_rule,
725 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200726 # Create a security group rule to allow UDP 80-81 (test
727 # webservers)
728 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
729 direction='ingress',
730 security_group_id=cls.lb_member_sec_group['id'],
731 protocol='udp',
732 ethertype='IPv6',
733 port_range_min=80,
734 port_range_max=81)['security_group_rule']
735 cls.addClassResourceCleanup(
736 waiters.wait_for_not_found,
737 cls.lb_mem_SGr_client.delete_security_group_rule,
738 cls.lb_mem_SGr_client.show_security_group_rule,
739 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700740 # Create a security group rule to allow 443 (test webservers)
741 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
742 direction='ingress',
743 security_group_id=cls.lb_member_sec_group['id'],
744 protocol='tcp',
745 ethertype='IPv6',
746 port_range_min=443,
747 port_range_max=443)['security_group_rule']
748 cls.addClassResourceCleanup(
749 waiters.wait_for_not_found,
750 cls.lb_mem_SGr_client.delete_security_group_rule,
751 cls.lb_mem_SGr_client.show_security_group_rule,
752 SGr['id'])
Michael Johnson031ecca2020-10-29 16:45:32 -0700753 # Create a security group rule to allow 9443 (test webservers)
754 # Used in the pool encryption client authentication tests
755 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
756 direction='ingress',
757 security_group_id=cls.lb_member_sec_group['id'],
758 protocol='tcp',
759 ethertype='IPv6',
760 port_range_min=9443,
761 port_range_max=9443)['security_group_rule']
762 cls.addClassResourceCleanup(
763 waiters.wait_for_not_found,
764 cls.lb_mem_SGr_client.delete_security_group_rule,
765 cls.lb_mem_SGr_client.show_security_group_rule,
766 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700767 # Create a security group rule to allow 22 (ssh)
768 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
769 direction='ingress',
770 security_group_id=cls.lb_member_sec_group['id'],
771 protocol='tcp',
772 ethertype='IPv6',
773 port_range_min=22,
774 port_range_max=22)['security_group_rule']
775 cls.addClassResourceCleanup(
776 waiters.wait_for_not_found,
777 cls.lb_mem_SGr_client.delete_security_group_rule,
778 cls.lb_mem_SGr_client.show_security_group_rule,
779 SGr['id'])
780
781 LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group))
782
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700783 # Setup backend member reencryption PKI
784 cls._create_backend_reencryption_pki()
785
Adam Harwellcd72b562018-05-07 11:37:22 -0700786 # Create webserver 1 instance
787 server_details = cls._create_webserver('lb_member_webserver1',
788 cls.lb_member_1_net)
789
790 cls.lb_member_webserver1 = server_details['server']
791 cls.webserver1_ip = server_details.get('ipv4_address')
792 cls.webserver1_ipv6 = server_details.get('ipv6_address')
793 cls.webserver1_public_ip = server_details['public_ipv4_address']
794
795 LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format(
796 cls.lb_member_webserver1[const.ID]))
797 LOG.debug('Octavia Setup: webserver1_ip = {}'.format(
798 cls.webserver1_ip))
799 LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format(
800 cls.webserver1_ipv6))
801 LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format(
802 cls.webserver1_public_ip))
803
804 # Create webserver 2 instance
805 server_details = cls._create_webserver('lb_member_webserver2',
806 cls.lb_member_2_net)
807
808 cls.lb_member_webserver2 = server_details['server']
809 cls.webserver2_ip = server_details.get('ipv4_address')
810 cls.webserver2_ipv6 = server_details.get('ipv6_address')
811 cls.webserver2_public_ip = server_details['public_ipv4_address']
812
813 LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format(
814 cls.lb_member_webserver2[const.ID]))
815 LOG.debug('Octavia Setup: webserver2_ip = {}'.format(
816 cls.webserver2_ip))
817 LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format(
818 cls.webserver2_ipv6))
819 LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format(
820 cls.webserver2_public_ip))
821
Michael Johnsonbf916df2018-10-17 10:59:28 -0700822 if CONF.load_balancer.test_with_ipv6:
823 # Enable the IPv6 nic in webserver 1
824 cls._enable_ipv6_nic_webserver(
825 cls.webserver1_public_ip, cls.lb_member_keypair['private_key'],
826 cls.webserver1_ipv6, cls.lb_member_1_subnet_prefix)
827
828 # Enable the IPv6 nic in webserver 2
829 cls._enable_ipv6_nic_webserver(
830 cls.webserver2_public_ip, cls.lb_member_keypair['private_key'],
831 cls.webserver2_ipv6, cls.lb_member_2_subnet_prefix)
832
Adam Harwellcd72b562018-05-07 11:37:22 -0700833 # Set up serving on webserver 1
834 cls._install_start_webserver(cls.webserver1_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700835 cls.lb_member_keypair['private_key'],
836 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700837
838 # Validate webserver 1
Adam Harwelle029af22018-05-24 17:13:28 -0700839 cls._validate_webserver(cls.webserver1_public_ip,
840 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700841
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200842 # Validate udp server 1
843 cls._validate_udp_server(cls.webserver1_public_ip,
844 cls.webserver1_response)
845
Adam Harwellcd72b562018-05-07 11:37:22 -0700846 # Set up serving on webserver 2
847 cls._install_start_webserver(cls.webserver2_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700848 cls.lb_member_keypair['private_key'],
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700849 cls.webserver2_response, revoke_cert=True)
Adam Harwellcd72b562018-05-07 11:37:22 -0700850
851 # Validate webserver 2
Adam Harwelle029af22018-05-24 17:13:28 -0700852 cls._validate_webserver(cls.webserver2_public_ip,
853 cls.webserver2_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700854
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200855 # Validate udp server 2
856 cls._validate_udp_server(cls.webserver2_public_ip,
857 cls.webserver2_response)
858
Adam Harwellcd72b562018-05-07 11:37:22 -0700859 @classmethod
860 def _create_networks(cls):
861 super(LoadBalancerBaseTestWithCompute, cls)._create_networks()
Jude Cross986e3f52017-07-24 14:57:20 -0700862 # Create a router for the subnets (required for the floating IP)
863 router_name = data_utils.rand_name("lb_member_router")
864 result = cls.lb_mem_routers_client.create_router(
865 name=router_name, admin_state_up=True,
866 external_gateway_info=dict(
867 network_id=CONF.network.public_network_id))
868 cls.lb_member_router = result['router']
869 LOG.info('lb_member_router: {}'.format(cls.lb_member_router))
870 cls.addClassResourceCleanup(
871 waiters.wait_for_not_found,
872 cls.lb_mem_routers_client.delete_router,
873 cls.lb_mem_routers_client.show_router,
874 cls.lb_member_router['id'])
875
876 # Add VIP subnet to router
877 cls.lb_mem_routers_client.add_router_interface(
878 cls.lb_member_router['id'],
879 subnet_id=cls.lb_member_vip_subnet['id'])
880 cls.addClassResourceCleanup(
881 waiters.wait_for_not_found,
882 cls.lb_mem_routers_client.remove_router_interface,
883 cls.lb_mem_routers_client.remove_router_interface,
884 cls.lb_member_router['id'],
885 subnet_id=cls.lb_member_vip_subnet['id'])
886
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100887 if (CONF.load_balancer.test_with_ipv6 and
888 CONF.load_balancer.default_router and
889 cls.lb_member_vip_ipv6_subnet_use_subnetpool):
890
891 router_name = CONF.load_balancer.default_router
892 # if lb_member_vip_ipv6_subnet uses devstack's subnetpool,
893 # plug the subnet into the default router
894 router = cls.os_admin.routers_client.list_routers(
895 name=router_name)['routers']
896
897 if len(router) == 1:
898 router = router[0]
899
900 # Add IPv6 VIP subnet to router1
901 cls.os_admin_routers_client.add_router_interface(
902 router['id'],
903 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
904 cls.addClassResourceCleanup(
905 waiters.wait_for_not_found,
906 cls.os_admin_routers_client.remove_router_interface,
907 cls.os_admin_routers_client.remove_router_interface,
908 router['id'],
909 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
910
Jude Cross986e3f52017-07-24 14:57:20 -0700911 # Add member subnet 1 to router
912 cls.lb_mem_routers_client.add_router_interface(
913 cls.lb_member_router['id'],
914 subnet_id=cls.lb_member_1_subnet['id'])
915 cls.addClassResourceCleanup(
916 waiters.wait_for_not_found,
Jude Cross986e3f52017-07-24 14:57:20 -0700917 cls.lb_mem_routers_client.remove_router_interface,
918 cls.lb_mem_routers_client.remove_router_interface,
919 cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id'])
920
921 # Add member subnet 2 to router
922 cls.lb_mem_routers_client.add_router_interface(
923 cls.lb_member_router['id'],
924 subnet_id=cls.lb_member_2_subnet['id'])
925 cls.addClassResourceCleanup(
926 waiters.wait_for_not_found,
927 cls.lb_mem_routers_client.remove_router_interface,
928 cls.lb_mem_routers_client.remove_router_interface,
929 cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id'])
930
931 @classmethod
932 def _create_webserver(cls, name, network):
933 """Creates a webserver with two ports.
934
935 webserver_details dictionary contains:
936 server - The compute server object
937 ipv4_address - The IPv4 address for the server (optional)
938 ipv6_address - The IPv6 address for the server (optional)
939 public_ipv4_address - The publicly accessible IPv4 address for the
940 server, this may be a floating IP (optional)
941
942 :param name: The name of the server to create.
943 :param network: The network to boot the server on.
944 :returns: webserver_details dictionary.
945 """
946 server_kwargs = {
947 'name': data_utils.rand_name(name),
948 'flavorRef': CONF.compute.flavor_ref,
949 'imageRef': CONF.compute.image_ref,
950 'key_name': cls.lb_member_keypair['name']}
951 if (CONF.load_balancer.enable_security_groups and
952 CONF.network_feature_enabled.port_security):
953 server_kwargs['security_groups'] = [
954 {'name': cls.lb_member_sec_group['name']}]
955 if not CONF.load_balancer.disable_boot_network:
956 server_kwargs['networks'] = [{'uuid': network['id']}]
957
958 # Replace the name for clouds that have limitations
959 if CONF.load_balancer.random_server_name_length:
960 r = random.SystemRandom()
961 server_kwargs['name'] = "m{}".format("".join(
962 [r.choice(string.ascii_uppercase + string.digits)
963 for _ in range(
964 CONF.load_balancer.random_server_name_length - 1)]
965 ))
966 if CONF.load_balancer.availability_zone:
967 server_kwargs['availability_zone'] = (
968 CONF.load_balancer.availability_zone)
969
970 server = cls.lb_mem_servers_client.create_server(
971 **server_kwargs)['server']
972 cls.addClassResourceCleanup(
973 waiters.wait_for_not_found,
974 cls.lb_mem_servers_client.delete_server,
975 cls.lb_mem_servers_client.show_server,
976 server['id'])
977 server = waiters.wait_for_status(
978 cls.lb_mem_servers_client.show_server,
979 server['id'], 'status', 'ACTIVE',
980 CONF.load_balancer.build_interval,
981 CONF.load_balancer.build_timeout,
982 root_tag='server')
983 webserver_details = {'server': server}
984 LOG.info('Created server: {}'.format(server))
985
986 addresses = server['addresses']
987 if CONF.load_balancer.disable_boot_network:
988 instance_network = addresses.values()[0]
989 else:
990 instance_network = addresses[network['name']]
991 for addr in instance_network:
992 if addr['version'] == 4:
993 webserver_details['ipv4_address'] = addr['addr']
994 if addr['version'] == 6:
995 webserver_details['ipv6_address'] = addr['addr']
996
997 if CONF.validation.connect_method == 'floating':
998 result = cls.lb_mem_ports_client.list_ports(
999 network_id=network['id'],
1000 mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr'])
1001 port_id = result['ports'][0]['id']
1002 result = cls.lb_mem_float_ip_client.create_floatingip(
1003 floating_network_id=CONF.network.public_network_id,
1004 port_id=port_id)
1005 floating_ip = result['floatingip']
1006 LOG.info('webserver1_floating_ip: {}'.format(floating_ip))
1007 cls.addClassResourceCleanup(
1008 waiters.wait_for_not_found,
1009 cls.lb_mem_float_ip_client.delete_floatingip,
1010 cls.lb_mem_float_ip_client.show_floatingip,
1011 floatingip_id=floating_ip['id'])
1012 webserver_details['public_ipv4_address'] = (
1013 floating_ip['floating_ip_address'])
1014 else:
1015 webserver_details['public_ipv4_address'] = (
1016 instance_network[0]['addr'])
1017
1018 return webserver_details
1019
1020 @classmethod
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001021 def _get_openssh_version(cls):
1022 p = subprocess.Popen(["ssh", "-V"],
1023 stdout=subprocess.PIPE,
1024 stderr=subprocess.PIPE)
1025 output = p.communicate()[1]
1026
1027 try:
1028 m = re.match(r"OpenSSH_(\d+)\.(\d+)", output.decode('utf-8'))
1029 version_maj = int(m.group(1))
1030 version_min = int(m.group(2))
1031 return version_maj, version_min
1032 except Exception:
1033 return None, None
1034
1035 @classmethod
1036 def _need_scp_protocol(cls):
1037 # When using scp >= 8.7, force the use of the SCP protocol,
1038 # the new default (SFTP protocol) doesn't work with
1039 # cirros VMs.
1040 ssh_version = cls._get_openssh_version()
1041 LOG.debug("ssh_version = {}".format(ssh_version))
1042 return (ssh_version[0] > 8 or
1043 (ssh_version[0] == 8 and ssh_version[1] >= 7))
1044
1045 @classmethod
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001046 def _install_start_webserver(cls, ip_address, ssh_key, start_id,
1047 revoke_cert=False):
Michael Johnson27357352020-11-13 13:55:09 -08001048 local_file = CONF.load_balancer.test_server_path
Adam Harwellcd72b562018-05-07 11:37:22 -07001049
1050 linux_client = remote_client.RemoteClient(
Ade Leed0ea4062021-09-06 15:33:27 -04001051 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key,
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +01001052 **cls.remote_client_args())
Adam Harwellcd72b562018-05-07 11:37:22 -07001053 linux_client.validate_authentication()
1054
1055 with tempfile.NamedTemporaryFile() as key:
1056 key.write(ssh_key.encode('utf-8'))
1057 key.flush()
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001058 ssh_extra_args = (
1059 "-o PubkeyAcceptedKeyTypes=+ssh-rsa")
1060 if cls._need_scp_protocol():
1061 ssh_extra_args += " -O"
Adam Harwellcd72b562018-05-07 11:37:22 -07001062 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001063 "{7} "
Adam Harwellcd72b562018-05-07 11:37:22 -07001064 "-o StrictHostKeyChecking=no "
1065 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1066 "-i {2} {3} {4}@{5}:{6}").format(
1067 CONF.load_balancer.scp_connection_timeout,
1068 CONF.load_balancer.scp_connection_attempts,
1069 key.name, local_file, CONF.validation.image_ssh_user,
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001070 ip_address, const.TEST_SERVER_BINARY,
1071 ssh_extra_args)
Adam Harwellcd72b562018-05-07 11:37:22 -07001072 args = shlex.split(cmd)
1073 subprocess_args = {'stdout': subprocess.PIPE,
1074 'stderr': subprocess.STDOUT,
1075 'cwd': None}
1076 proc = subprocess.Popen(args, **subprocess_args)
1077 stdout, stderr = proc.communicate()
1078 if proc.returncode != 0:
1079 raise exceptions.CommandFailed(proc.returncode, cmd,
1080 stdout, stderr)
Gregory Thiemongef72a8862019-08-06 17:25:42 +02001081
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001082 cls._load_member_pki_content(ip_address, key,
1083 revoke_cert=revoke_cert)
1084
Gregory Thiemongef72a8862019-08-06 17:25:42 +02001085 # Enabling memory overcommit allows to run golang static binaries
1086 # compiled with a recent golang toolchain (>=1.11). Those binaries
1087 # allocate a large amount of virtual memory at init time, and this
1088 # allocation fails in tempest's nano flavor (64MB of RAM)
1089 # (golang issue reported in https://github.com/golang/go/issues/28114,
1090 # follow-up: https://github.com/golang/go/issues/28081)
1091 # TODO(gthiemonge): Remove this call when golang issue is resolved.
1092 linux_client.exec_command('sudo sh -c "echo 1 > '
1093 '/proc/sys/vm/overcommit_memory"')
1094
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001095 # The initial process also supports HTTPS and HTTPS with client auth
1096 linux_client.exec_command(
1097 'sudo screen -d -m {0} -port 80 -id {1} -https_port 443 -cert {2} '
1098 '-key {3} -https_client_auth_port 9443 -client_ca {4}'.format(
1099 const.TEST_SERVER_BINARY, start_id, const.TEST_SERVER_CERT,
1100 const.TEST_SERVER_KEY, const.TEST_SERVER_CLIENT_CA))
1101
Adam Harwellcd72b562018-05-07 11:37:22 -07001102 linux_client.exec_command('sudo screen -d -m {0} -port 81 '
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001103 '-id {1}'.format(const.TEST_SERVER_BINARY,
1104 start_id + 1))
Adam Harwellcd72b562018-05-07 11:37:22 -07001105
Michael Johnsonbf916df2018-10-17 10:59:28 -07001106 # Cirros does not configure the assigned IPv6 address by default
1107 # so enable it manually like tempest does here:
1108 # tempest/scenario/test_netowrk_v6.py turn_nic6_on()
1109 @classmethod
1110 def _enable_ipv6_nic_webserver(cls, ip_address, ssh_key,
1111 ipv6_address, ipv6_prefix):
1112 linux_client = remote_client.RemoteClient(
Ade Leed0ea4062021-09-06 15:33:27 -04001113 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key,
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +01001114 **cls.remote_client_args())
Michael Johnsonbf916df2018-10-17 10:59:28 -07001115 linux_client.validate_authentication()
1116
1117 linux_client.exec_command('sudo ip address add {0}/{1} dev '
1118 'eth0'.format(ipv6_address, ipv6_prefix))
1119
Adam Harwellcd72b562018-05-07 11:37:22 -07001120 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -07001121 def _validate_webserver(cls, ip_address, start_id):
1122 URL = 'http://{0}'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001123 cls.validate_URL_response(URL, expected_body=str(start_id))
Jude Cross986e3f52017-07-24 14:57:20 -07001124 URL = 'http://{0}:81'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001125 cls.validate_URL_response(URL, expected_body=str(start_id + 1))
Jude Cross986e3f52017-07-24 14:57:20 -07001126
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001127 @classmethod
1128 def _validate_udp_server(cls, ip_address, start_id):
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001129 res = cls.make_udp_request(ip_address, 80)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001130 if res != str(start_id):
1131 raise Exception("Response from test server doesn't match the "
1132 "expected value ({0} != {1}).".format(
1133 res, str(start_id)))
1134
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001135 res = cls.make_udp_request(ip_address, 81)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001136 if res != str(start_id + 1):
1137 raise Exception("Response from test server doesn't match the "
1138 "expected value ({0} != {1}).".format(
1139 res, str(start_id + 1)))
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001140
1141 @classmethod
1142 def _create_backend_reencryption_pki(cls):
1143 # Create a CA self-signed cert and key for the member test servers
1144 cls.member_ca_cert, cls.member_ca_key = (
1145 cert_utils.generate_ca_cert_and_key())
1146
1147 LOG.debug('Member CA Cert: %s', cls.member_ca_cert.public_bytes(
1148 serialization.Encoding.PEM))
1149 LOG.debug('Member CA private Key: %s', cls.member_ca_key.private_bytes(
1150 encoding=serialization.Encoding.PEM,
1151 format=serialization.PrivateFormat.TraditionalOpenSSL,
1152 encryption_algorithm=serialization.NoEncryption()))
1153 LOG.debug('Member CA public Key: %s',
1154 cls.member_ca_key.public_key().public_bytes(
1155 encoding=serialization.Encoding.PEM,
1156 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1157
1158 # Create the member client authentication CA
1159 cls.member_client_ca_cert, member_client_ca_key = (
1160 cert_utils.generate_ca_cert_and_key())
1161
1162 # Create client cert and key
1163 cls.member_client_cn = uuidutils.generate_uuid()
1164 cls.member_client_cert, cls.member_client_key = (
1165 cert_utils.generate_client_cert_and_key(
1166 cls.member_client_ca_cert, member_client_ca_key,
1167 cls.member_client_cn))
1168 # Note: We are not revoking a client cert here as we don't need to
1169 # test the backend web server CRL checking.
1170
1171 @classmethod
1172 def _load_member_pki_content(cls, ip_address, ssh_key, revoke_cert=False):
1173 # Create webserver certificate and key
1174 cert, key = cert_utils.generate_server_cert_and_key(
1175 cls.member_ca_cert, cls.member_ca_key, ip_address)
1176
1177 LOG.debug('%s Cert: %s', ip_address, cert.public_bytes(
1178 serialization.Encoding.PEM))
1179 LOG.debug('%s private Key: %s', ip_address, key.private_bytes(
1180 encoding=serialization.Encoding.PEM,
1181 format=serialization.PrivateFormat.TraditionalOpenSSL,
1182 encryption_algorithm=serialization.NoEncryption()))
1183 public_key = key.public_key()
1184 LOG.debug('%s public Key: %s', ip_address, public_key.public_bytes(
1185 encoding=serialization.Encoding.PEM,
1186 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1187
1188 # Create a CRL with a revoked certificate
1189 if revoke_cert:
1190 # Create a CRL with webserver 2 revoked
1191 cls.member_crl = cert_utils.generate_certificate_revocation_list(
1192 cls.member_ca_cert, cls.member_ca_key, cert)
1193
1194 # Load the certificate, key, and client CA certificate into the
1195 # test server.
1196 with tempfile.TemporaryDirectory() as tmpdir:
1197 os.umask(0)
1198 files_to_send = []
1199 cert_filename = os.path.join(tmpdir, const.CERT_PEM)
1200 files_to_send.append(cert_filename)
1201 with open(os.open(cert_filename, os.O_CREAT | os.O_WRONLY,
1202 0o700), 'w') as fh:
1203 fh.write(cert.public_bytes(
1204 serialization.Encoding.PEM).decode('utf-8'))
1205 fh.flush()
1206 key_filename = os.path.join(tmpdir, const.KEY_PEM)
1207 files_to_send.append(key_filename)
1208 with open(os.open(key_filename, os.O_CREAT | os.O_WRONLY,
1209 0o700), 'w') as fh:
1210 fh.write(key.private_bytes(
1211 encoding=serialization.Encoding.PEM,
1212 format=serialization.PrivateFormat.TraditionalOpenSSL,
1213 encryption_algorithm=serialization.NoEncryption()).decode(
1214 'utf-8'))
1215 fh.flush()
1216 client_ca_filename = os.path.join(tmpdir, const.CLIENT_CA_PEM)
1217 files_to_send.append(client_ca_filename)
1218 with open(os.open(client_ca_filename, os.O_CREAT | os.O_WRONLY,
1219 0o700), 'w') as fh:
1220 fh.write(cls.member_client_ca_cert.public_bytes(
1221 serialization.Encoding.PEM).decode('utf-8'))
1222 fh.flush()
1223
1224 # For security, we don't want to use a shell that can glob
1225 # the file names, so iterate over them.
1226 subprocess_args = {'stdout': subprocess.PIPE,
1227 'stderr': subprocess.STDOUT,
1228 'cwd': None}
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001229 ssh_extra_args = (
1230 "-o PubkeyAcceptedKeyTypes=+ssh-rsa")
1231 if cls._need_scp_protocol():
1232 ssh_extra_args += " -O"
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001233 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001234 "{9} "
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001235 "-o StrictHostKeyChecking=no "
1236 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1237 "-i {2} {3} {4} {5} {6}@{7}:{8}").format(
1238 CONF.load_balancer.scp_connection_timeout,
1239 CONF.load_balancer.scp_connection_attempts,
1240 ssh_key.name, cert_filename, key_filename, client_ca_filename,
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001241 CONF.validation.image_ssh_user, ip_address, const.DEV_SHM_PATH,
1242 ssh_extra_args)
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001243 args = shlex.split(cmd)
1244 proc = subprocess.Popen(args, **subprocess_args)
1245 stdout, stderr = proc.communicate()
1246 if proc.returncode != 0:
1247 raise exceptions.CommandFailed(proc.returncode, cmd,
1248 stdout, stderr)