blob: 7800b408656655dbc128480988de25a32af48262 [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
ibumarskovcb804b12020-09-03 18:21:29 +0400584 @classmethod
585 def check_tf_compatibility(cls, protocol=None, algorithm=None):
586 # TungstenFabric supported protocols and algorithms
587 tf_protocols = [const.HTTP, const.HTTPS, const.TCP, const.UDP,
588 const.TERMINATED_HTTPS]
589 tf_algorithms = [const.LB_ALGORITHM_ROUND_ROBIN,
590 const.LB_ALGORITHM_LEAST_CONNECTIONS,
591 const.LB_ALGORITHM_SOURCE_IP]
592
593 if algorithm and algorithm not in tf_algorithms:
594 raise cls.skipException(
595 'TungstenFabric does not support {} algorithm.'
596 ''.format(algorithm))
597 if protocol and protocol not in tf_protocols:
598 raise cls.skipException(
599 'TungstenFabric does not support {} protocol.'
600 ''.format(protocol))
601
602 @classmethod
603 def _tf_create_listener(cls, name, proto, port, lb_id):
604 listener_kwargs = {
605 const.NAME: name,
606 const.PROTOCOL: proto,
607 const.PROTOCOL_PORT: port,
608 const.LOADBALANCER_ID: lb_id,
609 }
610 listener = cls.mem_listener_client.create_listener(**listener_kwargs)
611 return listener
612
613 @classmethod
614 def _tf_get_free_port(cls, lb_id):
615 port = 8081
616 lb = cls.mem_lb_client.show_loadbalancer(lb_id)
617 listeners = lb[const.LISTENERS]
618 if not listeners:
619 return port
620 ports = [cls.mem_listener_client.show_listener(x[const.ID])[
621 const.PROTOCOL_PORT] for x in listeners]
622 while port in ports:
623 port = port + 1
624 return port
625
Adam Harwellcd72b562018-05-07 11:37:22 -0700626
627class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest):
628 @classmethod
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +0100629 def remote_client_args(cls):
630 # In case we're using octavia-tempest-plugin with old tempest releases
631 # (for instance on stable/train) that don't support ssh_key_type, catch
632 # the exception and don't pass any argument
633 args = {}
634 try:
635 args['ssh_key_type'] = CONF.validation.ssh_key_type
636 except cfg.NoSuchOptError:
637 pass
638 return args
639
640 @classmethod
Adam Harwellcd72b562018-05-07 11:37:22 -0700641 def resource_setup(cls):
642 super(LoadBalancerBaseTestWithCompute, cls).resource_setup()
643 # If validation is disabled in this cloud, we won't be able to
644 # start the webservers, so don't even boot them.
645 if not CONF.validation.run_validation:
646 return
647
648 # Create a keypair for the webservers
649 keypair_name = data_utils.rand_name('lb_member_keypair')
650 result = cls.lb_mem_keypairs_client.create_keypair(
651 name=keypair_name)
652 cls.lb_member_keypair = result['keypair']
653 LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair))
654 cls.addClassResourceCleanup(
655 waiters.wait_for_not_found,
656 cls.lb_mem_keypairs_client.delete_keypair,
657 cls.lb_mem_keypairs_client.show_keypair,
658 keypair_name)
659
660 if (CONF.load_balancer.enable_security_groups and
661 CONF.network_feature_enabled.port_security):
662 # Set up the security group for the webservers
663 SG_name = data_utils.rand_name('lb_member_SG')
664 cls.lb_member_sec_group = (
665 cls.lb_mem_SG_client.create_security_group(
666 name=SG_name)['security_group'])
667 cls.addClassResourceCleanup(
668 waiters.wait_for_not_found,
669 cls.lb_mem_SG_client.delete_security_group,
670 cls.lb_mem_SG_client.show_security_group,
671 cls.lb_member_sec_group['id'])
672
673 # Create a security group rule to allow 80-81 (test webservers)
674 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
675 direction='ingress',
676 security_group_id=cls.lb_member_sec_group['id'],
677 protocol='tcp',
678 ethertype='IPv4',
679 port_range_min=80,
680 port_range_max=81)['security_group_rule']
681 cls.addClassResourceCleanup(
682 waiters.wait_for_not_found,
683 cls.lb_mem_SGr_client.delete_security_group_rule,
684 cls.lb_mem_SGr_client.show_security_group_rule,
685 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200686 # Create a security group rule to allow UDP 80-81 (test webservers)
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=80,
693 port_range_max=81)['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'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700699 # Create a security group rule to allow 443 (test webservers)
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=443,
706 port_range_max=443)['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'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200712 # Create a security group rule to allow UDP 9999 (test webservers)
713 # Port 9999 is used to illustrate health monitor ERRORs on closed
714 # ports.
715 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
716 direction='ingress',
717 security_group_id=cls.lb_member_sec_group['id'],
718 protocol='udp',
719 ethertype='IPv4',
720 port_range_min=9999,
721 port_range_max=9999)['security_group_rule']
722 cls.addClassResourceCleanup(
723 waiters.wait_for_not_found,
724 cls.lb_mem_SGr_client.delete_security_group_rule,
725 cls.lb_mem_SGr_client.show_security_group_rule,
726 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700727 # Create a security group rule to allow 22 (ssh)
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='tcp',
732 ethertype='IPv4',
733 port_range_min=22,
734 port_range_max=22)['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'])
740 if CONF.load_balancer.test_with_ipv6:
741 # Create a security group rule to allow 80-81 (test webservers)
742 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
743 direction='ingress',
744 security_group_id=cls.lb_member_sec_group['id'],
745 protocol='tcp',
746 ethertype='IPv6',
747 port_range_min=80,
748 port_range_max=81)['security_group_rule']
749 cls.addClassResourceCleanup(
750 waiters.wait_for_not_found,
751 cls.lb_mem_SGr_client.delete_security_group_rule,
752 cls.lb_mem_SGr_client.show_security_group_rule,
753 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200754 # Create a security group rule to allow UDP 80-81 (test
755 # webservers)
756 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
757 direction='ingress',
758 security_group_id=cls.lb_member_sec_group['id'],
759 protocol='udp',
760 ethertype='IPv6',
761 port_range_min=80,
762 port_range_max=81)['security_group_rule']
763 cls.addClassResourceCleanup(
764 waiters.wait_for_not_found,
765 cls.lb_mem_SGr_client.delete_security_group_rule,
766 cls.lb_mem_SGr_client.show_security_group_rule,
767 SGr['id'])
Michael Johnson74b6f2f2020-10-29 15:11:39 -0700768 # Create a security group rule to allow 443 (test webservers)
769 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
770 direction='ingress',
771 security_group_id=cls.lb_member_sec_group['id'],
772 protocol='tcp',
773 ethertype='IPv6',
774 port_range_min=443,
775 port_range_max=443)['security_group_rule']
776 cls.addClassResourceCleanup(
777 waiters.wait_for_not_found,
778 cls.lb_mem_SGr_client.delete_security_group_rule,
779 cls.lb_mem_SGr_client.show_security_group_rule,
780 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700781 # Create a security group rule to allow 22 (ssh)
782 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
783 direction='ingress',
784 security_group_id=cls.lb_member_sec_group['id'],
785 protocol='tcp',
786 ethertype='IPv6',
787 port_range_min=22,
788 port_range_max=22)['security_group_rule']
789 cls.addClassResourceCleanup(
790 waiters.wait_for_not_found,
791 cls.lb_mem_SGr_client.delete_security_group_rule,
792 cls.lb_mem_SGr_client.show_security_group_rule,
793 SGr['id'])
794
795 LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group))
796
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700797 # Setup backend member reencryption PKI
798 cls._create_backend_reencryption_pki()
799
Adam Harwellcd72b562018-05-07 11:37:22 -0700800 # Create webserver 1 instance
801 server_details = cls._create_webserver('lb_member_webserver1',
802 cls.lb_member_1_net)
803
804 cls.lb_member_webserver1 = server_details['server']
805 cls.webserver1_ip = server_details.get('ipv4_address')
806 cls.webserver1_ipv6 = server_details.get('ipv6_address')
807 cls.webserver1_public_ip = server_details['public_ipv4_address']
808
809 LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format(
810 cls.lb_member_webserver1[const.ID]))
811 LOG.debug('Octavia Setup: webserver1_ip = {}'.format(
812 cls.webserver1_ip))
813 LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format(
814 cls.webserver1_ipv6))
815 LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format(
816 cls.webserver1_public_ip))
817
818 # Create webserver 2 instance
819 server_details = cls._create_webserver('lb_member_webserver2',
820 cls.lb_member_2_net)
821
822 cls.lb_member_webserver2 = server_details['server']
823 cls.webserver2_ip = server_details.get('ipv4_address')
824 cls.webserver2_ipv6 = server_details.get('ipv6_address')
825 cls.webserver2_public_ip = server_details['public_ipv4_address']
826
827 LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format(
828 cls.lb_member_webserver2[const.ID]))
829 LOG.debug('Octavia Setup: webserver2_ip = {}'.format(
830 cls.webserver2_ip))
831 LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format(
832 cls.webserver2_ipv6))
833 LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format(
834 cls.webserver2_public_ip))
835
Michael Johnsonbf916df2018-10-17 10:59:28 -0700836 if CONF.load_balancer.test_with_ipv6:
837 # Enable the IPv6 nic in webserver 1
838 cls._enable_ipv6_nic_webserver(
839 cls.webserver1_public_ip, cls.lb_member_keypair['private_key'],
840 cls.webserver1_ipv6, cls.lb_member_1_subnet_prefix)
841
842 # Enable the IPv6 nic in webserver 2
843 cls._enable_ipv6_nic_webserver(
844 cls.webserver2_public_ip, cls.lb_member_keypair['private_key'],
845 cls.webserver2_ipv6, cls.lb_member_2_subnet_prefix)
846
Adam Harwellcd72b562018-05-07 11:37:22 -0700847 # Set up serving on webserver 1
848 cls._install_start_webserver(cls.webserver1_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700849 cls.lb_member_keypair['private_key'],
850 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700851
852 # Validate webserver 1
Adam Harwelle029af22018-05-24 17:13:28 -0700853 cls._validate_webserver(cls.webserver1_public_ip,
854 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700855
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200856 # Validate udp server 1
857 cls._validate_udp_server(cls.webserver1_public_ip,
858 cls.webserver1_response)
859
Adam Harwellcd72b562018-05-07 11:37:22 -0700860 # Set up serving on webserver 2
861 cls._install_start_webserver(cls.webserver2_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700862 cls.lb_member_keypair['private_key'],
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700863 cls.webserver2_response, revoke_cert=True)
Adam Harwellcd72b562018-05-07 11:37:22 -0700864
865 # Validate webserver 2
Adam Harwelle029af22018-05-24 17:13:28 -0700866 cls._validate_webserver(cls.webserver2_public_ip,
867 cls.webserver2_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700868
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200869 # Validate udp server 2
870 cls._validate_udp_server(cls.webserver2_public_ip,
871 cls.webserver2_response)
872
Adam Harwellcd72b562018-05-07 11:37:22 -0700873 @classmethod
874 def _create_networks(cls):
875 super(LoadBalancerBaseTestWithCompute, cls)._create_networks()
Jude Cross986e3f52017-07-24 14:57:20 -0700876 # Create a router for the subnets (required for the floating IP)
877 router_name = data_utils.rand_name("lb_member_router")
878 result = cls.lb_mem_routers_client.create_router(
879 name=router_name, admin_state_up=True,
880 external_gateway_info=dict(
881 network_id=CONF.network.public_network_id))
882 cls.lb_member_router = result['router']
883 LOG.info('lb_member_router: {}'.format(cls.lb_member_router))
884 cls.addClassResourceCleanup(
885 waiters.wait_for_not_found,
886 cls.lb_mem_routers_client.delete_router,
887 cls.lb_mem_routers_client.show_router,
888 cls.lb_member_router['id'])
889
890 # Add VIP subnet to router
891 cls.lb_mem_routers_client.add_router_interface(
892 cls.lb_member_router['id'],
893 subnet_id=cls.lb_member_vip_subnet['id'])
894 cls.addClassResourceCleanup(
895 waiters.wait_for_not_found,
896 cls.lb_mem_routers_client.remove_router_interface,
897 cls.lb_mem_routers_client.remove_router_interface,
898 cls.lb_member_router['id'],
899 subnet_id=cls.lb_member_vip_subnet['id'])
900
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100901 if (CONF.load_balancer.test_with_ipv6 and
902 CONF.load_balancer.default_router and
903 cls.lb_member_vip_ipv6_subnet_use_subnetpool):
904
905 router_name = CONF.load_balancer.default_router
906 # if lb_member_vip_ipv6_subnet uses devstack's subnetpool,
907 # plug the subnet into the default router
908 router = cls.os_admin.routers_client.list_routers(
909 name=router_name)['routers']
910
911 if len(router) == 1:
912 router = router[0]
913
914 # Add IPv6 VIP subnet to router1
915 cls.os_admin_routers_client.add_router_interface(
916 router['id'],
917 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
918 cls.addClassResourceCleanup(
919 waiters.wait_for_not_found,
920 cls.os_admin_routers_client.remove_router_interface,
921 cls.os_admin_routers_client.remove_router_interface,
922 router['id'],
923 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
924
Jude Cross986e3f52017-07-24 14:57:20 -0700925 # Add member subnet 1 to router
926 cls.lb_mem_routers_client.add_router_interface(
927 cls.lb_member_router['id'],
928 subnet_id=cls.lb_member_1_subnet['id'])
929 cls.addClassResourceCleanup(
930 waiters.wait_for_not_found,
Jude Cross986e3f52017-07-24 14:57:20 -0700931 cls.lb_mem_routers_client.remove_router_interface,
932 cls.lb_mem_routers_client.remove_router_interface,
933 cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id'])
934
935 # Add member subnet 2 to router
936 cls.lb_mem_routers_client.add_router_interface(
937 cls.lb_member_router['id'],
938 subnet_id=cls.lb_member_2_subnet['id'])
939 cls.addClassResourceCleanup(
940 waiters.wait_for_not_found,
941 cls.lb_mem_routers_client.remove_router_interface,
942 cls.lb_mem_routers_client.remove_router_interface,
943 cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id'])
944
945 @classmethod
946 def _create_webserver(cls, name, network):
947 """Creates a webserver with two ports.
948
949 webserver_details dictionary contains:
950 server - The compute server object
951 ipv4_address - The IPv4 address for the server (optional)
952 ipv6_address - The IPv6 address for the server (optional)
953 public_ipv4_address - The publicly accessible IPv4 address for the
954 server, this may be a floating IP (optional)
955
956 :param name: The name of the server to create.
957 :param network: The network to boot the server on.
958 :returns: webserver_details dictionary.
959 """
960 server_kwargs = {
961 'name': data_utils.rand_name(name),
962 'flavorRef': CONF.compute.flavor_ref,
963 'imageRef': CONF.compute.image_ref,
964 'key_name': cls.lb_member_keypair['name']}
965 if (CONF.load_balancer.enable_security_groups and
966 CONF.network_feature_enabled.port_security):
967 server_kwargs['security_groups'] = [
968 {'name': cls.lb_member_sec_group['name']}]
969 if not CONF.load_balancer.disable_boot_network:
970 server_kwargs['networks'] = [{'uuid': network['id']}]
971
972 # Replace the name for clouds that have limitations
973 if CONF.load_balancer.random_server_name_length:
974 r = random.SystemRandom()
975 server_kwargs['name'] = "m{}".format("".join(
976 [r.choice(string.ascii_uppercase + string.digits)
977 for _ in range(
978 CONF.load_balancer.random_server_name_length - 1)]
979 ))
980 if CONF.load_balancer.availability_zone:
981 server_kwargs['availability_zone'] = (
982 CONF.load_balancer.availability_zone)
983
984 server = cls.lb_mem_servers_client.create_server(
985 **server_kwargs)['server']
986 cls.addClassResourceCleanup(
987 waiters.wait_for_not_found,
988 cls.lb_mem_servers_client.delete_server,
989 cls.lb_mem_servers_client.show_server,
990 server['id'])
991 server = waiters.wait_for_status(
992 cls.lb_mem_servers_client.show_server,
993 server['id'], 'status', 'ACTIVE',
994 CONF.load_balancer.build_interval,
995 CONF.load_balancer.build_timeout,
996 root_tag='server')
997 webserver_details = {'server': server}
998 LOG.info('Created server: {}'.format(server))
999
1000 addresses = server['addresses']
1001 if CONF.load_balancer.disable_boot_network:
1002 instance_network = addresses.values()[0]
1003 else:
1004 instance_network = addresses[network['name']]
1005 for addr in instance_network:
1006 if addr['version'] == 4:
1007 webserver_details['ipv4_address'] = addr['addr']
1008 if addr['version'] == 6:
1009 webserver_details['ipv6_address'] = addr['addr']
1010
1011 if CONF.validation.connect_method == 'floating':
1012 result = cls.lb_mem_ports_client.list_ports(
1013 network_id=network['id'],
1014 mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr'])
1015 port_id = result['ports'][0]['id']
1016 result = cls.lb_mem_float_ip_client.create_floatingip(
1017 floating_network_id=CONF.network.public_network_id,
1018 port_id=port_id)
1019 floating_ip = result['floatingip']
1020 LOG.info('webserver1_floating_ip: {}'.format(floating_ip))
1021 cls.addClassResourceCleanup(
1022 waiters.wait_for_not_found,
1023 cls.lb_mem_float_ip_client.delete_floatingip,
1024 cls.lb_mem_float_ip_client.show_floatingip,
1025 floatingip_id=floating_ip['id'])
1026 webserver_details['public_ipv4_address'] = (
1027 floating_ip['floating_ip_address'])
1028 else:
1029 webserver_details['public_ipv4_address'] = (
1030 instance_network[0]['addr'])
1031
1032 return webserver_details
1033
1034 @classmethod
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001035 def _get_openssh_version(cls):
1036 p = subprocess.Popen(["ssh", "-V"],
1037 stdout=subprocess.PIPE,
1038 stderr=subprocess.PIPE)
1039 output = p.communicate()[1]
1040
1041 try:
1042 m = re.match(r"OpenSSH_(\d+)\.(\d+)", output.decode('utf-8'))
1043 version_maj = int(m.group(1))
1044 version_min = int(m.group(2))
1045 return version_maj, version_min
1046 except Exception:
1047 return None, None
1048
1049 @classmethod
1050 def _need_scp_protocol(cls):
1051 # When using scp >= 8.7, force the use of the SCP protocol,
1052 # the new default (SFTP protocol) doesn't work with
1053 # cirros VMs.
1054 ssh_version = cls._get_openssh_version()
1055 LOG.debug("ssh_version = {}".format(ssh_version))
1056 return (ssh_version[0] > 8 or
1057 (ssh_version[0] == 8 and ssh_version[1] >= 7))
1058
1059 @classmethod
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001060 def _install_start_webserver(cls, ip_address, ssh_key, start_id,
1061 revoke_cert=False):
Michael Johnson27357352020-11-13 13:55:09 -08001062 local_file = CONF.load_balancer.test_server_path
Adam Harwellcd72b562018-05-07 11:37:22 -07001063
1064 linux_client = remote_client.RemoteClient(
Ade Leed0ea4062021-09-06 15:33:27 -04001065 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key,
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +01001066 **cls.remote_client_args())
Adam Harwellcd72b562018-05-07 11:37:22 -07001067 linux_client.validate_authentication()
1068
1069 with tempfile.NamedTemporaryFile() as key:
1070 key.write(ssh_key.encode('utf-8'))
1071 key.flush()
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001072 ssh_extra_args = (
1073 "-o PubkeyAcceptedKeyTypes=+ssh-rsa")
1074 if cls._need_scp_protocol():
1075 ssh_extra_args += " -O"
Adam Harwellcd72b562018-05-07 11:37:22 -07001076 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001077 "{7} "
Adam Harwellcd72b562018-05-07 11:37:22 -07001078 "-o StrictHostKeyChecking=no "
1079 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1080 "-i {2} {3} {4}@{5}:{6}").format(
1081 CONF.load_balancer.scp_connection_timeout,
1082 CONF.load_balancer.scp_connection_attempts,
1083 key.name, local_file, CONF.validation.image_ssh_user,
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001084 ip_address, const.TEST_SERVER_BINARY,
1085 ssh_extra_args)
Adam Harwellcd72b562018-05-07 11:37:22 -07001086 args = shlex.split(cmd)
1087 subprocess_args = {'stdout': subprocess.PIPE,
1088 'stderr': subprocess.STDOUT,
1089 'cwd': None}
1090 proc = subprocess.Popen(args, **subprocess_args)
1091 stdout, stderr = proc.communicate()
1092 if proc.returncode != 0:
1093 raise exceptions.CommandFailed(proc.returncode, cmd,
1094 stdout, stderr)
Gregory Thiemongef72a8862019-08-06 17:25:42 +02001095
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001096 cls._load_member_pki_content(ip_address, key,
1097 revoke_cert=revoke_cert)
1098
Gregory Thiemongef72a8862019-08-06 17:25:42 +02001099 # Enabling memory overcommit allows to run golang static binaries
1100 # compiled with a recent golang toolchain (>=1.11). Those binaries
1101 # allocate a large amount of virtual memory at init time, and this
1102 # allocation fails in tempest's nano flavor (64MB of RAM)
1103 # (golang issue reported in https://github.com/golang/go/issues/28114,
1104 # follow-up: https://github.com/golang/go/issues/28081)
1105 # TODO(gthiemonge): Remove this call when golang issue is resolved.
1106 linux_client.exec_command('sudo sh -c "echo 1 > '
1107 '/proc/sys/vm/overcommit_memory"')
1108
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001109 # The initial process also supports HTTPS and HTTPS with client auth
1110 linux_client.exec_command(
1111 'sudo screen -d -m {0} -port 80 -id {1} -https_port 443 -cert {2} '
1112 '-key {3} -https_client_auth_port 9443 -client_ca {4}'.format(
1113 const.TEST_SERVER_BINARY, start_id, const.TEST_SERVER_CERT,
1114 const.TEST_SERVER_KEY, const.TEST_SERVER_CLIENT_CA))
1115
Adam Harwellcd72b562018-05-07 11:37:22 -07001116 linux_client.exec_command('sudo screen -d -m {0} -port 81 '
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001117 '-id {1}'.format(const.TEST_SERVER_BINARY,
1118 start_id + 1))
Adam Harwellcd72b562018-05-07 11:37:22 -07001119
Michael Johnsonbf916df2018-10-17 10:59:28 -07001120 # Cirros does not configure the assigned IPv6 address by default
1121 # so enable it manually like tempest does here:
1122 # tempest/scenario/test_netowrk_v6.py turn_nic6_on()
1123 @classmethod
1124 def _enable_ipv6_nic_webserver(cls, ip_address, ssh_key,
1125 ipv6_address, ipv6_prefix):
1126 linux_client = remote_client.RemoteClient(
Ade Leed0ea4062021-09-06 15:33:27 -04001127 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key,
Gregory Thiemongeb0da4f32022-02-04 08:58:06 +01001128 **cls.remote_client_args())
Michael Johnsonbf916df2018-10-17 10:59:28 -07001129 linux_client.validate_authentication()
1130
1131 linux_client.exec_command('sudo ip address add {0}/{1} dev '
1132 'eth0'.format(ipv6_address, ipv6_prefix))
1133
Adam Harwellcd72b562018-05-07 11:37:22 -07001134 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -07001135 def _validate_webserver(cls, ip_address, start_id):
1136 URL = 'http://{0}'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001137 cls.validate_URL_response(URL, expected_body=str(start_id))
Jude Cross986e3f52017-07-24 14:57:20 -07001138 URL = 'http://{0}:81'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001139 cls.validate_URL_response(URL, expected_body=str(start_id + 1))
Jude Cross986e3f52017-07-24 14:57:20 -07001140
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001141 @classmethod
1142 def _validate_udp_server(cls, ip_address, start_id):
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001143 res = cls.make_udp_request(ip_address, 80)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001144 if res != str(start_id):
1145 raise Exception("Response from test server doesn't match the "
1146 "expected value ({0} != {1}).".format(
1147 res, str(start_id)))
1148
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001149 res = cls.make_udp_request(ip_address, 81)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001150 if res != str(start_id + 1):
1151 raise Exception("Response from test server doesn't match the "
1152 "expected value ({0} != {1}).".format(
1153 res, str(start_id + 1)))
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001154
1155 @classmethod
1156 def _create_backend_reencryption_pki(cls):
1157 # Create a CA self-signed cert and key for the member test servers
1158 cls.member_ca_cert, cls.member_ca_key = (
1159 cert_utils.generate_ca_cert_and_key())
1160
1161 LOG.debug('Member CA Cert: %s', cls.member_ca_cert.public_bytes(
1162 serialization.Encoding.PEM))
1163 LOG.debug('Member CA private Key: %s', cls.member_ca_key.private_bytes(
1164 encoding=serialization.Encoding.PEM,
1165 format=serialization.PrivateFormat.TraditionalOpenSSL,
1166 encryption_algorithm=serialization.NoEncryption()))
1167 LOG.debug('Member CA public Key: %s',
1168 cls.member_ca_key.public_key().public_bytes(
1169 encoding=serialization.Encoding.PEM,
1170 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1171
1172 # Create the member client authentication CA
1173 cls.member_client_ca_cert, member_client_ca_key = (
1174 cert_utils.generate_ca_cert_and_key())
1175
1176 # Create client cert and key
1177 cls.member_client_cn = uuidutils.generate_uuid()
1178 cls.member_client_cert, cls.member_client_key = (
1179 cert_utils.generate_client_cert_and_key(
1180 cls.member_client_ca_cert, member_client_ca_key,
1181 cls.member_client_cn))
1182 # Note: We are not revoking a client cert here as we don't need to
1183 # test the backend web server CRL checking.
1184
1185 @classmethod
1186 def _load_member_pki_content(cls, ip_address, ssh_key, revoke_cert=False):
1187 # Create webserver certificate and key
1188 cert, key = cert_utils.generate_server_cert_and_key(
1189 cls.member_ca_cert, cls.member_ca_key, ip_address)
1190
1191 LOG.debug('%s Cert: %s', ip_address, cert.public_bytes(
1192 serialization.Encoding.PEM))
1193 LOG.debug('%s private Key: %s', ip_address, key.private_bytes(
1194 encoding=serialization.Encoding.PEM,
1195 format=serialization.PrivateFormat.TraditionalOpenSSL,
1196 encryption_algorithm=serialization.NoEncryption()))
1197 public_key = key.public_key()
1198 LOG.debug('%s public Key: %s', ip_address, public_key.public_bytes(
1199 encoding=serialization.Encoding.PEM,
1200 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1201
1202 # Create a CRL with a revoked certificate
1203 if revoke_cert:
1204 # Create a CRL with webserver 2 revoked
1205 cls.member_crl = cert_utils.generate_certificate_revocation_list(
1206 cls.member_ca_cert, cls.member_ca_key, cert)
1207
1208 # Load the certificate, key, and client CA certificate into the
1209 # test server.
1210 with tempfile.TemporaryDirectory() as tmpdir:
1211 os.umask(0)
1212 files_to_send = []
1213 cert_filename = os.path.join(tmpdir, const.CERT_PEM)
1214 files_to_send.append(cert_filename)
1215 with open(os.open(cert_filename, os.O_CREAT | os.O_WRONLY,
1216 0o700), 'w') as fh:
1217 fh.write(cert.public_bytes(
1218 serialization.Encoding.PEM).decode('utf-8'))
1219 fh.flush()
1220 key_filename = os.path.join(tmpdir, const.KEY_PEM)
1221 files_to_send.append(key_filename)
1222 with open(os.open(key_filename, os.O_CREAT | os.O_WRONLY,
1223 0o700), 'w') as fh:
1224 fh.write(key.private_bytes(
1225 encoding=serialization.Encoding.PEM,
1226 format=serialization.PrivateFormat.TraditionalOpenSSL,
1227 encryption_algorithm=serialization.NoEncryption()).decode(
1228 'utf-8'))
1229 fh.flush()
1230 client_ca_filename = os.path.join(tmpdir, const.CLIENT_CA_PEM)
1231 files_to_send.append(client_ca_filename)
1232 with open(os.open(client_ca_filename, os.O_CREAT | os.O_WRONLY,
1233 0o700), 'w') as fh:
1234 fh.write(cls.member_client_ca_cert.public_bytes(
1235 serialization.Encoding.PEM).decode('utf-8'))
1236 fh.flush()
1237
1238 # For security, we don't want to use a shell that can glob
1239 # the file names, so iterate over them.
1240 subprocess_args = {'stdout': subprocess.PIPE,
1241 'stderr': subprocess.STDOUT,
1242 'cwd': None}
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001243 ssh_extra_args = (
1244 "-o PubkeyAcceptedKeyTypes=+ssh-rsa")
1245 if cls._need_scp_protocol():
1246 ssh_extra_args += " -O"
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001247 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001248 "{9} "
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001249 "-o StrictHostKeyChecking=no "
1250 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1251 "-i {2} {3} {4} {5} {6}@{7}:{8}").format(
1252 CONF.load_balancer.scp_connection_timeout,
1253 CONF.load_balancer.scp_connection_attempts,
1254 ssh_key.name, cert_filename, key_filename, client_ca_filename,
Gregory Thiemongea2c234e2021-11-02 17:08:29 +01001255 CONF.validation.image_ssh_user, ip_address, const.DEV_SHM_PATH,
1256 ssh_extra_args)
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001257 args = shlex.split(cmd)
1258 proc = subprocess.Popen(args, **subprocess_args)
1259 stdout, stderr = proc.communicate()
1260 if proc.returncode != 0:
1261 raise exceptions.CommandFailed(proc.returncode, cmd,
1262 stdout, stderr)