blob: 70d51baca48a98eb3c2721d371c9050235086664 [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'],
Michael Johnson9e9f5262023-01-18 17:59:17 +000074 # Note: Some projects are now requiring the 'member' role by
75 # default (nova for example) so make sure our creds have this role
76 ['lb_member', CONF.load_balancer.member_role, 'member'],
77 ['lb_member2', CONF.load_balancer.member_role, 'member']]
Michael Johnson6006de72021-02-21 01:42:39 +000078
79 # If scope enforcement is enabled, add in the system scope credentials.
80 # The project scope is already handled by the above credentials.
81 if CONF.enforce_scope.octavia:
82 credentials.extend(['system_admin', 'system_reader'])
83
84 # A tuple of credentials that will be allocated by tempest using the
85 # 'credentials' list above. These are used to build RBAC test lists.
86 allocated_creds = []
87 for cred in credentials:
88 if isinstance(cred, list):
89 allocated_creds.append('os_roles_' + cred[0])
90 else:
91 allocated_creds.append('os_' + cred)
92 # Tests shall not mess with the list of allocated credentials
93 allocated_credentials = tuple(allocated_creds)
Jude Cross986e3f52017-07-24 14:57:20 -070094
Adam Harwelle029af22018-05-24 17:13:28 -070095 webserver1_response = 1
96 webserver2_response = 5
Michael Johnsondfd818a2018-08-21 20:54:54 -070097 used_ips = []
Jude Cross986e3f52017-07-24 14:57:20 -070098
Michael Johnson89bdbcd2020-03-19 15:59:19 -070099 SRC_PORT_NUMBER_MIN = 32768
100 SRC_PORT_NUMBER_MAX = 61000
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200101 src_port_number = SRC_PORT_NUMBER_MIN
102
Jude Cross986e3f52017-07-24 14:57:20 -0700103 @classmethod
104 def skip_checks(cls):
105 """Check if we should skip all of the children tests."""
106 super(LoadBalancerBaseTest, cls).skip_checks()
107
108 service_list = {
109 'load_balancer': CONF.service_available.load_balancer,
110 }
111
112 live_service_list = {
113 'compute': CONF.service_available.nova,
114 'image': CONF.service_available.glance,
115 'neutron': CONF.service_available.neutron
116 }
117
118 if not CONF.load_balancer.test_with_noop:
119 service_list.update(live_service_list)
120
121 for service, available in service_list.items():
122 if not available:
zhangzs2a6cf672018-11-10 16:13:11 +0800123 skip_msg = ("{0} skipped as {1} service is not "
Jude Cross986e3f52017-07-24 14:57:20 -0700124 "available.".format(cls.__name__, service))
125 raise cls.skipException(skip_msg)
126
127 # We must be able to reach our VIP and instances
128 if not (CONF.network.project_networks_reachable
129 or CONF.network.public_network_id):
130 msg = ('Either project_networks_reachable must be "true", or '
131 'public_network_id must be defined.')
132 raise cls.skipException(msg)
133
134 @classmethod
135 def setup_credentials(cls):
136 """Setup test credentials and network resources."""
137 # Do not auto create network resources
138 cls.set_network_resources()
139 super(LoadBalancerBaseTest, cls).setup_credentials()
140
Bas de Bruijne530a88a2022-12-15 11:12:45 -0400141 if not CONF.load_balancer.log_user_roles:
142 return
143
Michael Johnson6006de72021-02-21 01:42:39 +0000144 # Log the user roles for this test run
145 role_name_cache = {}
146 for cred in cls.credentials:
147 user_roles = []
148 if isinstance(cred, list):
149 user_name = cred[0]
150 cred_obj = getattr(cls, 'os_roles_' + cred[0])
151 else:
152 user_name = cred
153 cred_obj = getattr(cls, 'os_' + cred)
154 params = {'user.id': cred_obj.credentials.user_id,
155 'project.id': cred_obj.credentials.project_id}
156 roles = cls.os_admin.role_assignments_client.list_role_assignments(
157 **params)['role_assignments']
158 for role in roles:
159 role_id = role['role']['id']
160 try:
161 role_name = role_name_cache[role_id]
162 except KeyError:
163 role_name = cls.os_admin.roles_v3_client.show_role(
164 role_id)['role']['name']
165 role_name_cache[role_id] = role_name
166 user_roles.append([role_name, role['scope']])
167 LOG.info("User %s has roles: %s", user_name, user_roles)
168
Jude Cross986e3f52017-07-24 14:57:20 -0700169 @classmethod
170 def setup_clients(cls):
171 """Setup client aliases."""
172 super(LoadBalancerBaseTest, cls).setup_clients()
Michael Johnson29d8e612021-06-23 16:16:12 +0000173 lb_admin_prefix = cls.os_roles_lb_admin.load_balancer_v2
Jude Cross986e3f52017-07-24 14:57:20 -0700174 cls.lb_mem_float_ip_client = cls.os_roles_lb_member.floating_ips_client
175 cls.lb_mem_keypairs_client = cls.os_roles_lb_member.keypairs_client
176 cls.lb_mem_net_client = cls.os_roles_lb_member.networks_client
177 cls.lb_mem_ports_client = cls.os_roles_lb_member.ports_client
178 cls.lb_mem_routers_client = cls.os_roles_lb_member.routers_client
179 cls.lb_mem_SG_client = cls.os_roles_lb_member.security_groups_client
180 cls.lb_mem_SGr_client = (
181 cls.os_roles_lb_member.security_group_rules_client)
182 cls.lb_mem_servers_client = cls.os_roles_lb_member.servers_client
183 cls.lb_mem_subnet_client = cls.os_roles_lb_member.subnets_client
Michael Johnson29d8e612021-06-23 16:16:12 +0000184 cls.mem_lb_client = (
185 cls.os_roles_lb_member.load_balancer_v2.LoadbalancerClient())
186 cls.mem_listener_client = (
187 cls.os_roles_lb_member.load_balancer_v2.ListenerClient())
188 cls.mem_pool_client = (
189 cls.os_roles_lb_member.load_balancer_v2.PoolClient())
190 cls.mem_member_client = (
191 cls.os_roles_lb_member.load_balancer_v2.MemberClient())
Adam Harwell60ed9d92018-05-10 13:23:13 -0700192 cls.mem_healthmonitor_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000193 cls.os_roles_lb_member.load_balancer_v2.HealthMonitorClient())
194 cls.mem_l7policy_client = (
195 cls.os_roles_lb_member.load_balancer_v2.L7PolicyClient())
196 cls.mem_l7rule_client = (
197 cls.os_roles_lb_member.load_balancer_v2.L7RuleClient())
198 cls.lb_admin_amphora_client = lb_admin_prefix.AmphoraClient()
Michael Johnsonaff2e862019-01-11 16:38:00 -0800199 cls.lb_admin_flavor_profile_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000200 lb_admin_prefix.FlavorProfileClient())
201 cls.lb_admin_flavor_client = lb_admin_prefix.FlavorClient()
202 cls.mem_flavor_client = (
203 cls.os_roles_lb_member.load_balancer_v2.FlavorClient())
204 cls.mem_provider_client = (
205 cls.os_roles_lb_member.load_balancer_v2.ProviderClient())
Carlos Goncalvesc2e12162019-02-14 23:57:44 +0100206 cls.os_admin_servers_client = cls.os_admin.servers_client
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100207 cls.os_admin_routers_client = cls.os_admin.routers_client
208 cls.os_admin_subnetpools_client = cls.os_admin.subnetpools_client
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800209 cls.lb_admin_flavor_capabilities_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000210 lb_admin_prefix.FlavorCapabilitiesClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800211 cls.lb_admin_availability_zone_capabilities_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000212 lb_admin_prefix.AvailabilityZoneCapabilitiesClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800213 cls.lb_admin_availability_zone_profile_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000214 lb_admin_prefix.AvailabilityZoneProfileClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800215 cls.lb_admin_availability_zone_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000216 lb_admin_prefix.AvailabilityZoneClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800217 cls.mem_availability_zone_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000218 cls.os_roles_lb_member.load_balancer_v2.AvailabilityZoneClient())
Jude Cross986e3f52017-07-24 14:57:20 -0700219
220 @classmethod
221 def resource_setup(cls):
222 """Setup resources needed by the tests."""
223 super(LoadBalancerBaseTest, cls).resource_setup()
224
225 conf_lb = CONF.load_balancer
226
Michael Johnsondfd818a2018-08-21 20:54:54 -0700227 cls.api_version = cls.mem_lb_client.get_max_api_version()
228
Jude Cross986e3f52017-07-24 14:57:20 -0700229 if conf_lb.test_subnet_override and not conf_lb.test_network_override:
230 raise exceptions.InvalidConfiguration(
231 "Configuration value test_network_override must be "
232 "specified if test_subnet_override is used.")
233
Michael Johnson6a9236a2020-08-04 23:54:54 +0000234 # TODO(johnsom) Remove this
Maciej Józefczykb6df5f82019-12-10 10:12:30 +0000235 # Get loadbalancing algorithms supported by provider driver.
236 try:
237 algorithms = const.SUPPORTED_LB_ALGORITHMS[
238 CONF.load_balancer.provider]
239 except KeyError:
240 algorithms = const.SUPPORTED_LB_ALGORITHMS['default']
241 # Set default algorithm as first from the list.
242 cls.lb_algorithm = algorithms[0]
243
Jude Cross986e3f52017-07-24 14:57:20 -0700244 show_subnet = cls.lb_mem_subnet_client.show_subnet
245 if CONF.load_balancer.test_with_noop:
246 cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()}
247 cls.lb_member_vip_subnet = {'id': uuidutils.generate_uuid()}
248 cls.lb_member_1_net = {'id': uuidutils.generate_uuid()}
249 cls.lb_member_1_subnet = {'id': uuidutils.generate_uuid()}
250 cls.lb_member_2_net = {'id': uuidutils.generate_uuid()}
251 cls.lb_member_2_subnet = {'id': uuidutils.generate_uuid()}
252 if CONF.load_balancer.test_with_ipv6:
Michael Johnson5a16ad32018-10-18 14:49:11 -0700253 cls.lb_member_vip_ipv6_net = {'id': uuidutils.generate_uuid()}
Jude Cross986e3f52017-07-24 14:57:20 -0700254 cls.lb_member_vip_ipv6_subnet = {'id':
255 uuidutils.generate_uuid()}
256 cls.lb_member_1_ipv6_subnet = {'id': uuidutils.generate_uuid()}
257 cls.lb_member_2_ipv6_subnet = {'id': uuidutils.generate_uuid()}
Michael Johnson590fbe12019-07-03 14:30:01 -0700258 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700259 return
260 elif CONF.load_balancer.test_network_override:
261 if conf_lb.test_subnet_override:
262 override_subnet = show_subnet(conf_lb.test_subnet_override)
263 else:
264 override_subnet = None
265
266 show_net = cls.lb_mem_net_client.show_network
267 override_network = show_net(conf_lb.test_network_override)
268 override_network = override_network.get('network')
269
270 cls.lb_member_vip_net = override_network
271 cls.lb_member_vip_subnet = override_subnet
272 cls.lb_member_1_net = override_network
273 cls.lb_member_1_subnet = override_subnet
274 cls.lb_member_2_net = override_network
275 cls.lb_member_2_subnet = override_subnet
276
277 if (CONF.load_balancer.test_with_ipv6 and
278 conf_lb.test_IPv6_subnet_override):
279 override_ipv6_subnet = show_subnet(
280 conf_lb.test_IPv6_subnet_override)
281 cls.lb_member_vip_ipv6_subnet = override_ipv6_subnet
282 cls.lb_member_1_ipv6_subnet = override_ipv6_subnet
283 cls.lb_member_2_ipv6_subnet = override_ipv6_subnet
Michael Johnson590fbe12019-07-03 14:30:01 -0700284 cls.lb_member_vip_ipv6_subnet_stateful = False
285 if (override_ipv6_subnet[0]['ipv6_address_mode'] ==
286 'dhcpv6-stateful'):
287 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700288 else:
289 cls.lb_member_vip_ipv6_subnet = None
290 cls.lb_member_1_ipv6_subnet = None
291 cls.lb_member_2_ipv6_subnet = None
292 else:
293 cls._create_networks()
294
295 LOG.debug('Octavia Setup: lb_member_vip_net = {}'.format(
296 cls.lb_member_vip_net[const.ID]))
297 if cls.lb_member_vip_subnet:
298 LOG.debug('Octavia Setup: lb_member_vip_subnet = {}'.format(
299 cls.lb_member_vip_subnet[const.ID]))
300 LOG.debug('Octavia Setup: lb_member_1_net = {}'.format(
301 cls.lb_member_1_net[const.ID]))
302 if cls.lb_member_1_subnet:
303 LOG.debug('Octavia Setup: lb_member_1_subnet = {}'.format(
304 cls.lb_member_1_subnet[const.ID]))
305 LOG.debug('Octavia Setup: lb_member_2_net = {}'.format(
306 cls.lb_member_2_net[const.ID]))
307 if cls.lb_member_2_subnet:
308 LOG.debug('Octavia Setup: lb_member_2_subnet = {}'.format(
309 cls.lb_member_2_subnet[const.ID]))
Michael Johnson124ba8b2018-08-30 16:06:05 -0700310 if CONF.load_balancer.test_with_ipv6:
311 if cls.lb_member_vip_ipv6_subnet:
312 LOG.debug('Octavia Setup: lb_member_vip_ipv6_subnet = '
313 '{}'.format(cls.lb_member_vip_ipv6_subnet[const.ID]))
314 if cls.lb_member_1_ipv6_subnet:
315 LOG.debug('Octavia Setup: lb_member_1_ipv6_subnet = {}'.format(
316 cls.lb_member_1_ipv6_subnet[const.ID]))
317 if cls.lb_member_2_ipv6_subnet:
318 LOG.debug('Octavia Setup: lb_member_2_ipv6_subnet = {}'.format(
319 cls.lb_member_2_ipv6_subnet[const.ID]))
Jude Cross986e3f52017-07-24 14:57:20 -0700320
Jude Cross986e3f52017-07-24 14:57:20 -0700321 @classmethod
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800322 # Neutron can be slow to clean up ports from the subnets/networks.
323 # Retry this delete a few times if we get a "Conflict" error to give
324 # neutron time to fully cleanup the ports.
325 @tenacity.retry(
326 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
327 wait=tenacity.wait_incrementing(
328 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
329 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
330 def _logging_delete_network(cls, net_id):
331 try:
332 cls.lb_mem_net_client.delete_network(net_id)
333 except Exception:
334 LOG.error('Unable to delete network {}. Active ports:'.format(
335 net_id))
336 LOG.error(cls.lb_mem_ports_client.list_ports())
337 raise
338
339 @classmethod
340 # Neutron can be slow to clean up ports from the subnets/networks.
341 # Retry this delete a few times if we get a "Conflict" error to give
342 # neutron time to fully cleanup the ports.
343 @tenacity.retry(
344 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
345 wait=tenacity.wait_incrementing(
346 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
347 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
348 def _logging_delete_subnet(cls, subnet_id):
349 try:
350 cls.lb_mem_subnet_client.delete_subnet(subnet_id)
351 except Exception:
352 LOG.error('Unable to delete subnet {}. Active ports:'.format(
353 subnet_id))
354 LOG.error(cls.lb_mem_ports_client.list_ports())
355 raise
356
357 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -0700358 def _create_networks(cls):
359 """Creates networks, subnets, and routers used in tests.
360
361 The following are expected to be defined and available to the tests:
362 cls.lb_member_vip_net
363 cls.lb_member_vip_subnet
364 cls.lb_member_vip_ipv6_subnet (optional)
365 cls.lb_member_1_net
366 cls.lb_member_1_subnet
367 cls.lb_member_1_ipv6_subnet (optional)
368 cls.lb_member_2_net
369 cls.lb_member_2_subnet
370 cls.lb_member_2_ipv6_subnet (optional)
371 """
372
373 # Create tenant VIP network
374 network_kwargs = {
375 'name': data_utils.rand_name("lb_member_vip_network")}
376 if CONF.network_feature_enabled.port_security:
Andreas Jaeger4215b702020-03-28 20:13:46 +0100377 # Note: Allowed Address Pairs requires port security
378 network_kwargs['port_security_enabled'] = True
Jude Cross986e3f52017-07-24 14:57:20 -0700379 result = cls.lb_mem_net_client.create_network(**network_kwargs)
380 cls.lb_member_vip_net = result['network']
381 LOG.info('lb_member_vip_net: {}'.format(cls.lb_member_vip_net))
382 cls.addClassResourceCleanup(
383 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800384 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700385 cls.lb_mem_net_client.show_network,
386 cls.lb_member_vip_net['id'])
387
388 # Create tenant VIP subnet
389 subnet_kwargs = {
390 'name': data_utils.rand_name("lb_member_vip_subnet"),
391 'network_id': cls.lb_member_vip_net['id'],
392 'cidr': CONF.load_balancer.vip_subnet_cidr,
393 'ip_version': 4}
394 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
395 cls.lb_member_vip_subnet = result['subnet']
396 LOG.info('lb_member_vip_subnet: {}'.format(cls.lb_member_vip_subnet))
397 cls.addClassResourceCleanup(
398 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800399 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700400 cls.lb_mem_subnet_client.show_subnet,
401 cls.lb_member_vip_subnet['id'])
402
403 # Create tenant VIP IPv6 subnet
404 if CONF.load_balancer.test_with_ipv6:
Michael Johnson590fbe12019-07-03 14:30:01 -0700405 cls.lb_member_vip_ipv6_subnet_stateful = False
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100406 cls.lb_member_vip_ipv6_subnet_use_subnetpool = False
407 subnet_kwargs = {
408 'name': data_utils.rand_name("lb_member_vip_ipv6_subnet"),
409 'network_id': cls.lb_member_vip_net['id'],
410 'ip_version': 6}
411
412 # Use a CIDR from devstack's default IPv6 subnetpool if it exists,
413 # the subnetpool's cidr is routable from the devstack node
414 # through the default router
415 subnetpool_name = CONF.load_balancer.default_ipv6_subnetpool
416 if subnetpool_name:
417 subnetpool = cls.os_admin_subnetpools_client.list_subnetpools(
418 name=subnetpool_name)['subnetpools']
419 if len(subnetpool) == 1:
420 subnetpool = subnetpool[0]
421 subnet_kwargs['subnetpool_id'] = subnetpool['id']
422 cls.lb_member_vip_ipv6_subnet_use_subnetpool = True
423
424 if 'subnetpool_id' not in subnet_kwargs:
425 subnet_kwargs['cidr'] = (
426 CONF.load_balancer.vip_ipv6_subnet_cidr)
427
428 result = cls.lb_mem_subnet_client.create_subnet(
429 **subnet_kwargs)
430 cls.lb_member_vip_ipv6_net = cls.lb_member_vip_net
431 cls.lb_member_vip_ipv6_subnet = result['subnet']
432 cls.addClassResourceCleanup(
433 waiters.wait_for_not_found,
434 cls._logging_delete_subnet,
435 cls.lb_mem_subnet_client.show_subnet,
436 cls.lb_member_vip_ipv6_subnet['id'])
Carlos Goncalves84af48c2019-07-25 15:51:30 +0200437
Jude Cross986e3f52017-07-24 14:57:20 -0700438 LOG.info('lb_member_vip_ipv6_subnet: {}'.format(
439 cls.lb_member_vip_ipv6_subnet))
Jude Cross986e3f52017-07-24 14:57:20 -0700440
441 # Create tenant member 1 network
442 network_kwargs = {
443 'name': data_utils.rand_name("lb_member_1_network")}
444 if CONF.network_feature_enabled.port_security:
445 if CONF.load_balancer.enable_security_groups:
446 network_kwargs['port_security_enabled'] = True
447 else:
448 network_kwargs['port_security_enabled'] = False
449 result = cls.lb_mem_net_client.create_network(**network_kwargs)
450 cls.lb_member_1_net = result['network']
451 LOG.info('lb_member_1_net: {}'.format(cls.lb_member_1_net))
452 cls.addClassResourceCleanup(
453 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800454 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700455 cls.lb_mem_net_client.show_network,
456 cls.lb_member_1_net['id'])
457
458 # Create tenant member 1 subnet
459 subnet_kwargs = {
460 'name': data_utils.rand_name("lb_member_1_subnet"),
461 'network_id': cls.lb_member_1_net['id'],
462 'cidr': CONF.load_balancer.member_1_ipv4_subnet_cidr,
463 'ip_version': 4}
464 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
465 cls.lb_member_1_subnet = result['subnet']
466 LOG.info('lb_member_1_subnet: {}'.format(cls.lb_member_1_subnet))
467 cls.addClassResourceCleanup(
468 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800469 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700470 cls.lb_mem_subnet_client.show_subnet,
471 cls.lb_member_1_subnet['id'])
472
473 # Create tenant member 1 ipv6 subnet
474 if CONF.load_balancer.test_with_ipv6:
475 subnet_kwargs = {
476 'name': data_utils.rand_name("lb_member_1_ipv6_subnet"),
477 'network_id': cls.lb_member_1_net['id'],
478 'cidr': CONF.load_balancer.member_1_ipv6_subnet_cidr,
479 'ip_version': 6}
480 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700481 cls.lb_member_1_subnet_prefix = (
482 CONF.load_balancer.member_1_ipv6_subnet_cidr.rpartition('/')[2]
483 )
484 assert(cls.lb_member_1_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700485 cls.lb_member_1_ipv6_subnet = result['subnet']
486 LOG.info('lb_member_1_ipv6_subnet: {}'.format(
487 cls.lb_member_1_ipv6_subnet))
488 cls.addClassResourceCleanup(
489 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800490 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700491 cls.lb_mem_subnet_client.show_subnet,
492 cls.lb_member_1_ipv6_subnet['id'])
493
494 # Create tenant member 2 network
495 network_kwargs = {
496 'name': data_utils.rand_name("lb_member_2_network")}
497 if CONF.network_feature_enabled.port_security:
498 if CONF.load_balancer.enable_security_groups:
499 network_kwargs['port_security_enabled'] = True
500 else:
501 network_kwargs['port_security_enabled'] = False
502 result = cls.lb_mem_net_client.create_network(**network_kwargs)
503 cls.lb_member_2_net = result['network']
504 LOG.info('lb_member_2_net: {}'.format(cls.lb_member_2_net))
505 cls.addClassResourceCleanup(
506 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800507 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700508 cls.lb_mem_net_client.show_network,
509 cls.lb_member_2_net['id'])
510
511 # Create tenant member 2 subnet
512 subnet_kwargs = {
513 'name': data_utils.rand_name("lb_member_2_subnet"),
514 'network_id': cls.lb_member_2_net['id'],
515 'cidr': CONF.load_balancer.member_2_ipv4_subnet_cidr,
516 'ip_version': 4}
517 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
518 cls.lb_member_2_subnet = result['subnet']
519 LOG.info('lb_member_2_subnet: {}'.format(cls.lb_member_2_subnet))
520 cls.addClassResourceCleanup(
521 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800522 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700523 cls.lb_mem_subnet_client.show_subnet,
524 cls.lb_member_2_subnet['id'])
525
526 # Create tenant member 2 ipv6 subnet
527 if CONF.load_balancer.test_with_ipv6:
528 subnet_kwargs = {
529 'name': data_utils.rand_name("lb_member_2_ipv6_subnet"),
530 'network_id': cls.lb_member_2_net['id'],
531 'cidr': CONF.load_balancer.member_2_ipv6_subnet_cidr,
532 'ip_version': 6}
533 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700534 cls.lb_member_2_subnet_prefix = (
535 CONF.load_balancer.member_2_ipv6_subnet_cidr.rpartition('/')[2]
536 )
537 assert(cls.lb_member_2_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700538 cls.lb_member_2_ipv6_subnet = result['subnet']
539 LOG.info('lb_member_2_ipv6_subnet: {}'.format(
540 cls.lb_member_2_ipv6_subnet))
541 cls.addClassResourceCleanup(
542 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800543 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700544 cls.lb_mem_subnet_client.show_subnet,
545 cls.lb_member_2_ipv6_subnet['id'])
546
Adam Harwellcd72b562018-05-07 11:37:22 -0700547 @classmethod
Michael Johnson07c9a632018-06-07 13:27:42 -0700548 def _setup_lb_network_kwargs(cls, lb_kwargs, ip_version=None,
549 use_fixed_ip=False):
Adam Harwell60ed9d92018-05-10 13:23:13 -0700550 if not ip_version:
551 ip_version = 6 if CONF.load_balancer.test_with_ipv6 else 4
Michael Johnson5a16ad32018-10-18 14:49:11 -0700552 if cls.lb_member_vip_subnet or cls.lb_member_vip_ipv6_subnet:
Adam Harwellcd72b562018-05-07 11:37:22 -0700553 ip_index = data_utils.rand_int_id(start=10, end=100)
Michael Johnsondfd818a2018-08-21 20:54:54 -0700554 while ip_index in cls.used_ips:
555 ip_index = data_utils.rand_int_id(start=10, end=100)
556 cls.used_ips.append(ip_index)
Adam Harwellcd72b562018-05-07 11:37:22 -0700557 if ip_version == 4:
Adam Harwellcd72b562018-05-07 11:37:22 -0700558 subnet_id = cls.lb_member_vip_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700559 if CONF.load_balancer.test_with_noop:
560 lb_vip_address = '198.18.33.33'
561 else:
562 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
563 network = ipaddress.IPv4Network(subnet['subnet']['cidr'])
564 lb_vip_address = str(network[ip_index])
Adam Harwellcd72b562018-05-07 11:37:22 -0700565 else:
Adam Harwellcd72b562018-05-07 11:37:22 -0700566 subnet_id = cls.lb_member_vip_ipv6_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700567 if CONF.load_balancer.test_with_noop:
568 lb_vip_address = '2001:db8:33:33:33:33:33:33'
569 else:
570 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
571 network = ipaddress.IPv6Network(subnet['subnet']['cidr'])
572 lb_vip_address = str(network[ip_index])
Michael Johnson590fbe12019-07-03 14:30:01 -0700573 # If the subnet is IPv6 slaac or dhcpv6-stateless
574 # neutron does not allow a fixed IP
575 if not cls.lb_member_vip_ipv6_subnet_stateful:
576 use_fixed_ip = False
Adam Harwellcd72b562018-05-07 11:37:22 -0700577 lb_kwargs[const.VIP_SUBNET_ID] = subnet_id
Michael Johnson07c9a632018-06-07 13:27:42 -0700578 if use_fixed_ip:
579 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700580 if CONF.load_balancer.test_with_noop:
581 lb_kwargs[const.VIP_NETWORK_ID] = (
582 cls.lb_member_vip_net[const.ID])
Carlos Goncalvesbb238552020-01-15 10:10:55 +0000583 if ip_version == 6:
584 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700585 else:
586 lb_kwargs[const.VIP_NETWORK_ID] = cls.lb_member_vip_net[const.ID]
587 lb_kwargs[const.VIP_SUBNET_ID] = None
588
589
590class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest):
591 @classmethod
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +0100592 def remote_client_args(cls):
593 # In case we're using octavia-tempest-plugin with old tempest releases
594 # (for instance on stable/train) that don't support ssh_key_type, catch
595 # the exception and don't pass any argument
596 args = {}
597 try:
598 args['ssh_key_type'] = CONF.validation.ssh_key_type
599 except cfg.NoSuchOptError:
600 pass
601 return args
602
603 @classmethod
Adam Harwellcd72b562018-05-07 11:37:22 -0700604 def resource_setup(cls):
605 super(LoadBalancerBaseTestWithCompute, cls).resource_setup()
606 # If validation is disabled in this cloud, we won't be able to
607 # start the webservers, so don't even boot them.
608 if not CONF.validation.run_validation:
609 return
610
611 # Create a keypair for the webservers
612 keypair_name = data_utils.rand_name('lb_member_keypair')
613 result = cls.lb_mem_keypairs_client.create_keypair(
614 name=keypair_name)
615 cls.lb_member_keypair = result['keypair']
616 LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair))
617 cls.addClassResourceCleanup(
618 waiters.wait_for_not_found,
619 cls.lb_mem_keypairs_client.delete_keypair,
620 cls.lb_mem_keypairs_client.show_keypair,
621 keypair_name)
622
623 if (CONF.load_balancer.enable_security_groups and
624 CONF.network_feature_enabled.port_security):
625 # Set up the security group for the webservers
626 SG_name = data_utils.rand_name('lb_member_SG')
627 cls.lb_member_sec_group = (
628 cls.lb_mem_SG_client.create_security_group(
629 name=SG_name)['security_group'])
630 cls.addClassResourceCleanup(
631 waiters.wait_for_not_found,
632 cls.lb_mem_SG_client.delete_security_group,
633 cls.lb_mem_SG_client.show_security_group,
634 cls.lb_member_sec_group['id'])
635
636 # Create a security group rule to allow 80-81 (test webservers)
637 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
638 direction='ingress',
639 security_group_id=cls.lb_member_sec_group['id'],
640 protocol='tcp',
641 ethertype='IPv4',
642 port_range_min=80,
643 port_range_max=81)['security_group_rule']
644 cls.addClassResourceCleanup(
645 waiters.wait_for_not_found,
646 cls.lb_mem_SGr_client.delete_security_group_rule,
647 cls.lb_mem_SGr_client.show_security_group_rule,
648 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200649 # Create a security group rule to allow UDP 80-81 (test webservers)
650 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
651 direction='ingress',
652 security_group_id=cls.lb_member_sec_group['id'],
653 protocol='udp',
654 ethertype='IPv4',
655 port_range_min=80,
656 port_range_max=81)['security_group_rule']
657 cls.addClassResourceCleanup(
658 waiters.wait_for_not_found,
659 cls.lb_mem_SGr_client.delete_security_group_rule,
660 cls.lb_mem_SGr_client.show_security_group_rule,
661 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700662 # Create a security group rule to allow 443 (test webservers)
663 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
664 direction='ingress',
665 security_group_id=cls.lb_member_sec_group['id'],
666 protocol='tcp',
667 ethertype='IPv4',
668 port_range_min=443,
669 port_range_max=443)['security_group_rule']
670 cls.addClassResourceCleanup(
671 waiters.wait_for_not_found,
672 cls.lb_mem_SGr_client.delete_security_group_rule,
673 cls.lb_mem_SGr_client.show_security_group_rule,
674 SGr['id'])
Michael Johnson031ecca2020-10-29 16:45:32 -0700675 # Create a security group rule to allow 9443 (test webservers)
676 # Used in the pool backend encryption client authentication tests
677 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
678 direction='ingress',
679 security_group_id=cls.lb_member_sec_group['id'],
680 protocol='tcp',
681 ethertype='IPv4',
682 port_range_min=9443,
683 port_range_max=9443)['security_group_rule']
684 cls.addClassResourceCleanup(
685 waiters.wait_for_not_found,
686 cls.lb_mem_SGr_client.delete_security_group_rule,
687 cls.lb_mem_SGr_client.show_security_group_rule,
688 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200689 # Create a security group rule to allow UDP 9999 (test webservers)
690 # Port 9999 is used to illustrate health monitor ERRORs on closed
691 # ports.
692 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
693 direction='ingress',
694 security_group_id=cls.lb_member_sec_group['id'],
695 protocol='udp',
696 ethertype='IPv4',
697 port_range_min=9999,
698 port_range_max=9999)['security_group_rule']
699 cls.addClassResourceCleanup(
700 waiters.wait_for_not_found,
701 cls.lb_mem_SGr_client.delete_security_group_rule,
702 cls.lb_mem_SGr_client.show_security_group_rule,
703 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700704 # Create a security group rule to allow 22 (ssh)
705 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
706 direction='ingress',
707 security_group_id=cls.lb_member_sec_group['id'],
708 protocol='tcp',
709 ethertype='IPv4',
710 port_range_min=22,
711 port_range_max=22)['security_group_rule']
712 cls.addClassResourceCleanup(
713 waiters.wait_for_not_found,
714 cls.lb_mem_SGr_client.delete_security_group_rule,
715 cls.lb_mem_SGr_client.show_security_group_rule,
716 SGr['id'])
717 if CONF.load_balancer.test_with_ipv6:
718 # Create a security group rule to allow 80-81 (test webservers)
719 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
720 direction='ingress',
721 security_group_id=cls.lb_member_sec_group['id'],
722 protocol='tcp',
723 ethertype='IPv6',
724 port_range_min=80,
725 port_range_max=81)['security_group_rule']
726 cls.addClassResourceCleanup(
727 waiters.wait_for_not_found,
728 cls.lb_mem_SGr_client.delete_security_group_rule,
729 cls.lb_mem_SGr_client.show_security_group_rule,
730 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200731 # Create a security group rule to allow UDP 80-81 (test
732 # webservers)
733 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
734 direction='ingress',
735 security_group_id=cls.lb_member_sec_group['id'],
736 protocol='udp',
737 ethertype='IPv6',
738 port_range_min=80,
739 port_range_max=81)['security_group_rule']
740 cls.addClassResourceCleanup(
741 waiters.wait_for_not_found,
742 cls.lb_mem_SGr_client.delete_security_group_rule,
743 cls.lb_mem_SGr_client.show_security_group_rule,
744 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700745 # Create a security group rule to allow 443 (test webservers)
746 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
747 direction='ingress',
748 security_group_id=cls.lb_member_sec_group['id'],
749 protocol='tcp',
750 ethertype='IPv6',
751 port_range_min=443,
752 port_range_max=443)['security_group_rule']
753 cls.addClassResourceCleanup(
754 waiters.wait_for_not_found,
755 cls.lb_mem_SGr_client.delete_security_group_rule,
756 cls.lb_mem_SGr_client.show_security_group_rule,
757 SGr['id'])
Michael Johnson031ecca2020-10-29 16:45:32 -0700758 # Create a security group rule to allow 9443 (test webservers)
759 # Used in the pool encryption client authentication tests
760 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
761 direction='ingress',
762 security_group_id=cls.lb_member_sec_group['id'],
763 protocol='tcp',
764 ethertype='IPv6',
765 port_range_min=9443,
766 port_range_max=9443)['security_group_rule']
767 cls.addClassResourceCleanup(
768 waiters.wait_for_not_found,
769 cls.lb_mem_SGr_client.delete_security_group_rule,
770 cls.lb_mem_SGr_client.show_security_group_rule,
771 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700772 # Create a security group rule to allow 22 (ssh)
773 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
774 direction='ingress',
775 security_group_id=cls.lb_member_sec_group['id'],
776 protocol='tcp',
777 ethertype='IPv6',
778 port_range_min=22,
779 port_range_max=22)['security_group_rule']
780 cls.addClassResourceCleanup(
781 waiters.wait_for_not_found,
782 cls.lb_mem_SGr_client.delete_security_group_rule,
783 cls.lb_mem_SGr_client.show_security_group_rule,
784 SGr['id'])
785
786 LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group))
787
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700788 # Setup backend member reencryption PKI
789 cls._create_backend_reencryption_pki()
790
Adam Harwellcd72b562018-05-07 11:37:22 -0700791 # Create webserver 1 instance
792 server_details = cls._create_webserver('lb_member_webserver1',
793 cls.lb_member_1_net)
794
795 cls.lb_member_webserver1 = server_details['server']
796 cls.webserver1_ip = server_details.get('ipv4_address')
797 cls.webserver1_ipv6 = server_details.get('ipv6_address')
798 cls.webserver1_public_ip = server_details['public_ipv4_address']
799
800 LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format(
801 cls.lb_member_webserver1[const.ID]))
802 LOG.debug('Octavia Setup: webserver1_ip = {}'.format(
803 cls.webserver1_ip))
804 LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format(
805 cls.webserver1_ipv6))
806 LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format(
807 cls.webserver1_public_ip))
808
809 # Create webserver 2 instance
810 server_details = cls._create_webserver('lb_member_webserver2',
811 cls.lb_member_2_net)
812
813 cls.lb_member_webserver2 = server_details['server']
814 cls.webserver2_ip = server_details.get('ipv4_address')
815 cls.webserver2_ipv6 = server_details.get('ipv6_address')
816 cls.webserver2_public_ip = server_details['public_ipv4_address']
817
818 LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format(
819 cls.lb_member_webserver2[const.ID]))
820 LOG.debug('Octavia Setup: webserver2_ip = {}'.format(
821 cls.webserver2_ip))
822 LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format(
823 cls.webserver2_ipv6))
824 LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format(
825 cls.webserver2_public_ip))
826
Michael Johnsonbf916df2018-10-17 10:59:28 -0700827 if CONF.load_balancer.test_with_ipv6:
828 # Enable the IPv6 nic in webserver 1
829 cls._enable_ipv6_nic_webserver(
830 cls.webserver1_public_ip, cls.lb_member_keypair['private_key'],
831 cls.webserver1_ipv6, cls.lb_member_1_subnet_prefix)
832
833 # Enable the IPv6 nic in webserver 2
834 cls._enable_ipv6_nic_webserver(
835 cls.webserver2_public_ip, cls.lb_member_keypair['private_key'],
836 cls.webserver2_ipv6, cls.lb_member_2_subnet_prefix)
837
Adam Harwellcd72b562018-05-07 11:37:22 -0700838 # Set up serving on webserver 1
839 cls._install_start_webserver(cls.webserver1_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700840 cls.lb_member_keypair['private_key'],
841 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700842
843 # Validate webserver 1
Adam Harwelle029af22018-05-24 17:13:28 -0700844 cls._validate_webserver(cls.webserver1_public_ip,
845 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700846
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200847 # Validate udp server 1
848 cls._validate_udp_server(cls.webserver1_public_ip,
849 cls.webserver1_response)
850
Adam Harwellcd72b562018-05-07 11:37:22 -0700851 # Set up serving on webserver 2
852 cls._install_start_webserver(cls.webserver2_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700853 cls.lb_member_keypair['private_key'],
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700854 cls.webserver2_response, revoke_cert=True)
Adam Harwellcd72b562018-05-07 11:37:22 -0700855
856 # Validate webserver 2
Adam Harwelle029af22018-05-24 17:13:28 -0700857 cls._validate_webserver(cls.webserver2_public_ip,
858 cls.webserver2_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700859
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200860 # Validate udp server 2
861 cls._validate_udp_server(cls.webserver2_public_ip,
862 cls.webserver2_response)
863
Adam Harwellcd72b562018-05-07 11:37:22 -0700864 @classmethod
865 def _create_networks(cls):
866 super(LoadBalancerBaseTestWithCompute, cls)._create_networks()
Jude Cross986e3f52017-07-24 14:57:20 -0700867 # Create a router for the subnets (required for the floating IP)
868 router_name = data_utils.rand_name("lb_member_router")
869 result = cls.lb_mem_routers_client.create_router(
870 name=router_name, admin_state_up=True,
871 external_gateway_info=dict(
872 network_id=CONF.network.public_network_id))
873 cls.lb_member_router = result['router']
874 LOG.info('lb_member_router: {}'.format(cls.lb_member_router))
875 cls.addClassResourceCleanup(
876 waiters.wait_for_not_found,
877 cls.lb_mem_routers_client.delete_router,
878 cls.lb_mem_routers_client.show_router,
879 cls.lb_member_router['id'])
880
881 # Add VIP subnet to router
882 cls.lb_mem_routers_client.add_router_interface(
883 cls.lb_member_router['id'],
884 subnet_id=cls.lb_member_vip_subnet['id'])
885 cls.addClassResourceCleanup(
886 waiters.wait_for_not_found,
887 cls.lb_mem_routers_client.remove_router_interface,
888 cls.lb_mem_routers_client.remove_router_interface,
889 cls.lb_member_router['id'],
890 subnet_id=cls.lb_member_vip_subnet['id'])
891
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100892 if (CONF.load_balancer.test_with_ipv6 and
893 CONF.load_balancer.default_router and
894 cls.lb_member_vip_ipv6_subnet_use_subnetpool):
895
896 router_name = CONF.load_balancer.default_router
897 # if lb_member_vip_ipv6_subnet uses devstack's subnetpool,
898 # plug the subnet into the default router
899 router = cls.os_admin.routers_client.list_routers(
900 name=router_name)['routers']
901
902 if len(router) == 1:
903 router = router[0]
904
905 # Add IPv6 VIP subnet to router1
906 cls.os_admin_routers_client.add_router_interface(
907 router['id'],
908 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
909 cls.addClassResourceCleanup(
910 waiters.wait_for_not_found,
911 cls.os_admin_routers_client.remove_router_interface,
912 cls.os_admin_routers_client.remove_router_interface,
913 router['id'],
914 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
915
Jude Cross986e3f52017-07-24 14:57:20 -0700916 # Add member subnet 1 to router
917 cls.lb_mem_routers_client.add_router_interface(
918 cls.lb_member_router['id'],
919 subnet_id=cls.lb_member_1_subnet['id'])
920 cls.addClassResourceCleanup(
921 waiters.wait_for_not_found,
Jude Cross986e3f52017-07-24 14:57:20 -0700922 cls.lb_mem_routers_client.remove_router_interface,
923 cls.lb_mem_routers_client.remove_router_interface,
924 cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id'])
925
926 # Add member subnet 2 to router
927 cls.lb_mem_routers_client.add_router_interface(
928 cls.lb_member_router['id'],
929 subnet_id=cls.lb_member_2_subnet['id'])
930 cls.addClassResourceCleanup(
931 waiters.wait_for_not_found,
932 cls.lb_mem_routers_client.remove_router_interface,
933 cls.lb_mem_routers_client.remove_router_interface,
934 cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id'])
935
936 @classmethod
937 def _create_webserver(cls, name, network):
938 """Creates a webserver with two ports.
939
940 webserver_details dictionary contains:
941 server - The compute server object
942 ipv4_address - The IPv4 address for the server (optional)
943 ipv6_address - The IPv6 address for the server (optional)
944 public_ipv4_address - The publicly accessible IPv4 address for the
945 server, this may be a floating IP (optional)
946
947 :param name: The name of the server to create.
948 :param network: The network to boot the server on.
949 :returns: webserver_details dictionary.
950 """
951 server_kwargs = {
952 'name': data_utils.rand_name(name),
953 'flavorRef': CONF.compute.flavor_ref,
954 'imageRef': CONF.compute.image_ref,
955 'key_name': cls.lb_member_keypair['name']}
956 if (CONF.load_balancer.enable_security_groups and
957 CONF.network_feature_enabled.port_security):
958 server_kwargs['security_groups'] = [
959 {'name': cls.lb_member_sec_group['name']}]
960 if not CONF.load_balancer.disable_boot_network:
961 server_kwargs['networks'] = [{'uuid': network['id']}]
962
963 # Replace the name for clouds that have limitations
964 if CONF.load_balancer.random_server_name_length:
965 r = random.SystemRandom()
966 server_kwargs['name'] = "m{}".format("".join(
967 [r.choice(string.ascii_uppercase + string.digits)
968 for _ in range(
969 CONF.load_balancer.random_server_name_length - 1)]
970 ))
971 if CONF.load_balancer.availability_zone:
972 server_kwargs['availability_zone'] = (
973 CONF.load_balancer.availability_zone)
974
975 server = cls.lb_mem_servers_client.create_server(
976 **server_kwargs)['server']
977 cls.addClassResourceCleanup(
978 waiters.wait_for_not_found,
979 cls.lb_mem_servers_client.delete_server,
980 cls.lb_mem_servers_client.show_server,
981 server['id'])
982 server = waiters.wait_for_status(
983 cls.lb_mem_servers_client.show_server,
984 server['id'], 'status', 'ACTIVE',
985 CONF.load_balancer.build_interval,
986 CONF.load_balancer.build_timeout,
987 root_tag='server')
988 webserver_details = {'server': server}
989 LOG.info('Created server: {}'.format(server))
990
991 addresses = server['addresses']
992 if CONF.load_balancer.disable_boot_network:
993 instance_network = addresses.values()[0]
994 else:
995 instance_network = addresses[network['name']]
996 for addr in instance_network:
997 if addr['version'] == 4:
998 webserver_details['ipv4_address'] = addr['addr']
999 if addr['version'] == 6:
1000 webserver_details['ipv6_address'] = addr['addr']
1001
1002 if CONF.validation.connect_method == 'floating':
1003 result = cls.lb_mem_ports_client.list_ports(
1004 network_id=network['id'],
1005 mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr'])
1006 port_id = result['ports'][0]['id']
1007 result = cls.lb_mem_float_ip_client.create_floatingip(
1008 floating_network_id=CONF.network.public_network_id,
1009 port_id=port_id)
1010 floating_ip = result['floatingip']
1011 LOG.info('webserver1_floating_ip: {}'.format(floating_ip))
1012 cls.addClassResourceCleanup(
1013 waiters.wait_for_not_found,
1014 cls.lb_mem_float_ip_client.delete_floatingip,
1015 cls.lb_mem_float_ip_client.show_floatingip,
1016 floatingip_id=floating_ip['id'])
1017 webserver_details['public_ipv4_address'] = (
1018 floating_ip['floating_ip_address'])
1019 else:
1020 webserver_details['public_ipv4_address'] = (
1021 instance_network[0]['addr'])
1022
1023 return webserver_details
1024
1025 @classmethod
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001026 def _get_openssh_version(cls):
1027 p = subprocess.Popen(["ssh", "-V"],
1028 stdout=subprocess.PIPE,
1029 stderr=subprocess.PIPE)
1030 output = p.communicate()[1]
1031
1032 try:
1033 m = re.match(r"OpenSSH_(\d+)\.(\d+)", output.decode('utf-8'))
1034 version_maj = int(m.group(1))
1035 version_min = int(m.group(2))
1036 return version_maj, version_min
1037 except Exception:
1038 return None, None
1039
1040 @classmethod
1041 def _need_scp_protocol(cls):
1042 # When using scp >= 8.7, force the use of the SCP protocol,
1043 # the new default (SFTP protocol) doesn't work with
1044 # cirros VMs.
1045 ssh_version = cls._get_openssh_version()
1046 LOG.debug("ssh_version = {}".format(ssh_version))
1047 return (ssh_version[0] > 8 or
1048 (ssh_version[0] == 8 and ssh_version[1] >= 7))
1049
1050 @classmethod
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001051 def _install_start_webserver(cls, ip_address, ssh_key, start_id,
1052 revoke_cert=False):
Michael Johnson27357352020-11-13 13:55:09 -08001053 local_file = CONF.load_balancer.test_server_path
Adam Harwellcd72b562018-05-07 11:37:22 -07001054
1055 linux_client = remote_client.RemoteClient(
Ade Leed0ea4062021-09-06 15:33:27 -04001056 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key,
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +01001057 **cls.remote_client_args())
Adam Harwellcd72b562018-05-07 11:37:22 -07001058 linux_client.validate_authentication()
1059
1060 with tempfile.NamedTemporaryFile() as key:
1061 key.write(ssh_key.encode('utf-8'))
1062 key.flush()
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001063 ssh_extra_args = (
1064 "-o PubkeyAcceptedKeyTypes=+ssh-rsa")
1065 if cls._need_scp_protocol():
1066 ssh_extra_args += " -O"
Adam Harwellcd72b562018-05-07 11:37:22 -07001067 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001068 "{7} "
Adam Harwellcd72b562018-05-07 11:37:22 -07001069 "-o StrictHostKeyChecking=no "
1070 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1071 "-i {2} {3} {4}@{5}:{6}").format(
1072 CONF.load_balancer.scp_connection_timeout,
1073 CONF.load_balancer.scp_connection_attempts,
1074 key.name, local_file, CONF.validation.image_ssh_user,
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001075 ip_address, const.TEST_SERVER_BINARY,
1076 ssh_extra_args)
Adam Harwellcd72b562018-05-07 11:37:22 -07001077 args = shlex.split(cmd)
1078 subprocess_args = {'stdout': subprocess.PIPE,
1079 'stderr': subprocess.STDOUT,
1080 'cwd': None}
1081 proc = subprocess.Popen(args, **subprocess_args)
1082 stdout, stderr = proc.communicate()
1083 if proc.returncode != 0:
1084 raise exceptions.CommandFailed(proc.returncode, cmd,
1085 stdout, stderr)
Gregory Thiemongef72a8862019-08-06 17:25:42 +02001086
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001087 cls._load_member_pki_content(ip_address, key,
1088 revoke_cert=revoke_cert)
1089
Gregory Thiemongef72a8862019-08-06 17:25:42 +02001090 # Enabling memory overcommit allows to run golang static binaries
1091 # compiled with a recent golang toolchain (>=1.11). Those binaries
1092 # allocate a large amount of virtual memory at init time, and this
1093 # allocation fails in tempest's nano flavor (64MB of RAM)
1094 # (golang issue reported in https://github.com/golang/go/issues/28114,
1095 # follow-up: https://github.com/golang/go/issues/28081)
1096 # TODO(gthiemonge): Remove this call when golang issue is resolved.
1097 linux_client.exec_command('sudo sh -c "echo 1 > '
1098 '/proc/sys/vm/overcommit_memory"')
1099
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001100 # The initial process also supports HTTPS and HTTPS with client auth
1101 linux_client.exec_command(
1102 'sudo screen -d -m {0} -port 80 -id {1} -https_port 443 -cert {2} '
1103 '-key {3} -https_client_auth_port 9443 -client_ca {4}'.format(
1104 const.TEST_SERVER_BINARY, start_id, const.TEST_SERVER_CERT,
1105 const.TEST_SERVER_KEY, const.TEST_SERVER_CLIENT_CA))
1106
Adam Harwellcd72b562018-05-07 11:37:22 -07001107 linux_client.exec_command('sudo screen -d -m {0} -port 81 '
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001108 '-id {1}'.format(const.TEST_SERVER_BINARY,
1109 start_id + 1))
Adam Harwellcd72b562018-05-07 11:37:22 -07001110
Michael Johnsonbf916df2018-10-17 10:59:28 -07001111 # Cirros does not configure the assigned IPv6 address by default
1112 # so enable it manually like tempest does here:
1113 # tempest/scenario/test_netowrk_v6.py turn_nic6_on()
1114 @classmethod
1115 def _enable_ipv6_nic_webserver(cls, ip_address, ssh_key,
1116 ipv6_address, ipv6_prefix):
1117 linux_client = remote_client.RemoteClient(
Ade Leed0ea4062021-09-06 15:33:27 -04001118 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key,
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +01001119 **cls.remote_client_args())
Michael Johnsonbf916df2018-10-17 10:59:28 -07001120 linux_client.validate_authentication()
1121
1122 linux_client.exec_command('sudo ip address add {0}/{1} dev '
1123 'eth0'.format(ipv6_address, ipv6_prefix))
1124
Adam Harwellcd72b562018-05-07 11:37:22 -07001125 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -07001126 def _validate_webserver(cls, ip_address, start_id):
1127 URL = 'http://{0}'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001128 cls.validate_URL_response(URL, expected_body=str(start_id))
Jude Cross986e3f52017-07-24 14:57:20 -07001129 URL = 'http://{0}:81'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001130 cls.validate_URL_response(URL, expected_body=str(start_id + 1))
Jude Cross986e3f52017-07-24 14:57:20 -07001131
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001132 @classmethod
1133 def _validate_udp_server(cls, ip_address, start_id):
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001134 res = cls.make_udp_request(ip_address, 80)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001135 if res != str(start_id):
1136 raise Exception("Response from test server doesn't match the "
1137 "expected value ({0} != {1}).".format(
1138 res, str(start_id)))
1139
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001140 res = cls.make_udp_request(ip_address, 81)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001141 if res != str(start_id + 1):
1142 raise Exception("Response from test server doesn't match the "
1143 "expected value ({0} != {1}).".format(
1144 res, str(start_id + 1)))
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001145
1146 @classmethod
1147 def _create_backend_reencryption_pki(cls):
1148 # Create a CA self-signed cert and key for the member test servers
1149 cls.member_ca_cert, cls.member_ca_key = (
1150 cert_utils.generate_ca_cert_and_key())
1151
1152 LOG.debug('Member CA Cert: %s', cls.member_ca_cert.public_bytes(
1153 serialization.Encoding.PEM))
1154 LOG.debug('Member CA private Key: %s', cls.member_ca_key.private_bytes(
1155 encoding=serialization.Encoding.PEM,
1156 format=serialization.PrivateFormat.TraditionalOpenSSL,
1157 encryption_algorithm=serialization.NoEncryption()))
1158 LOG.debug('Member CA public Key: %s',
1159 cls.member_ca_key.public_key().public_bytes(
1160 encoding=serialization.Encoding.PEM,
1161 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1162
1163 # Create the member client authentication CA
1164 cls.member_client_ca_cert, member_client_ca_key = (
1165 cert_utils.generate_ca_cert_and_key())
1166
1167 # Create client cert and key
1168 cls.member_client_cn = uuidutils.generate_uuid()
1169 cls.member_client_cert, cls.member_client_key = (
1170 cert_utils.generate_client_cert_and_key(
1171 cls.member_client_ca_cert, member_client_ca_key,
1172 cls.member_client_cn))
1173 # Note: We are not revoking a client cert here as we don't need to
1174 # test the backend web server CRL checking.
1175
1176 @classmethod
1177 def _load_member_pki_content(cls, ip_address, ssh_key, revoke_cert=False):
1178 # Create webserver certificate and key
1179 cert, key = cert_utils.generate_server_cert_and_key(
1180 cls.member_ca_cert, cls.member_ca_key, ip_address)
1181
1182 LOG.debug('%s Cert: %s', ip_address, cert.public_bytes(
1183 serialization.Encoding.PEM))
1184 LOG.debug('%s private Key: %s', ip_address, key.private_bytes(
1185 encoding=serialization.Encoding.PEM,
1186 format=serialization.PrivateFormat.TraditionalOpenSSL,
1187 encryption_algorithm=serialization.NoEncryption()))
1188 public_key = key.public_key()
1189 LOG.debug('%s public Key: %s', ip_address, public_key.public_bytes(
1190 encoding=serialization.Encoding.PEM,
1191 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1192
1193 # Create a CRL with a revoked certificate
1194 if revoke_cert:
1195 # Create a CRL with webserver 2 revoked
1196 cls.member_crl = cert_utils.generate_certificate_revocation_list(
1197 cls.member_ca_cert, cls.member_ca_key, cert)
1198
1199 # Load the certificate, key, and client CA certificate into the
1200 # test server.
1201 with tempfile.TemporaryDirectory() as tmpdir:
1202 os.umask(0)
1203 files_to_send = []
1204 cert_filename = os.path.join(tmpdir, const.CERT_PEM)
1205 files_to_send.append(cert_filename)
1206 with open(os.open(cert_filename, os.O_CREAT | os.O_WRONLY,
1207 0o700), 'w') as fh:
1208 fh.write(cert.public_bytes(
1209 serialization.Encoding.PEM).decode('utf-8'))
1210 fh.flush()
1211 key_filename = os.path.join(tmpdir, const.KEY_PEM)
1212 files_to_send.append(key_filename)
1213 with open(os.open(key_filename, os.O_CREAT | os.O_WRONLY,
1214 0o700), 'w') as fh:
1215 fh.write(key.private_bytes(
1216 encoding=serialization.Encoding.PEM,
1217 format=serialization.PrivateFormat.TraditionalOpenSSL,
1218 encryption_algorithm=serialization.NoEncryption()).decode(
1219 'utf-8'))
1220 fh.flush()
1221 client_ca_filename = os.path.join(tmpdir, const.CLIENT_CA_PEM)
1222 files_to_send.append(client_ca_filename)
1223 with open(os.open(client_ca_filename, os.O_CREAT | os.O_WRONLY,
1224 0o700), 'w') as fh:
1225 fh.write(cls.member_client_ca_cert.public_bytes(
1226 serialization.Encoding.PEM).decode('utf-8'))
1227 fh.flush()
1228
1229 # For security, we don't want to use a shell that can glob
1230 # the file names, so iterate over them.
1231 subprocess_args = {'stdout': subprocess.PIPE,
1232 'stderr': subprocess.STDOUT,
1233 'cwd': None}
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001234 ssh_extra_args = (
1235 "-o PubkeyAcceptedKeyTypes=+ssh-rsa")
1236 if cls._need_scp_protocol():
1237 ssh_extra_args += " -O"
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001238 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001239 "{9} "
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001240 "-o StrictHostKeyChecking=no "
1241 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1242 "-i {2} {3} {4} {5} {6}@{7}:{8}").format(
1243 CONF.load_balancer.scp_connection_timeout,
1244 CONF.load_balancer.scp_connection_attempts,
1245 ssh_key.name, cert_filename, key_filename, client_ca_filename,
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001246 CONF.validation.image_ssh_user, ip_address, const.DEV_SHM_PATH,
1247 ssh_extra_args)
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001248 args = shlex.split(cmd)
1249 proc = subprocess.Popen(args, **subprocess_args)
1250 stdout, stderr = proc.communicate()
1251 if proc.returncode != 0:
1252 raise exceptions.CommandFailed(proc.returncode, cmd,
1253 stdout, stderr)