blob: b0bd643b4b3bcde06884c98438e546d2d5fc3847 [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
18import shlex
Jude Cross986e3f52017-07-24 14:57:20 -070019import string
20import subprocess
21import tempfile
22
Michael Johnsonbaf12e02020-10-27 16:10:28 -070023from cryptography.hazmat.primitives import serialization
Jude Cross986e3f52017-07-24 14:57:20 -070024from oslo_log import log as logging
25from oslo_utils import uuidutils
26from tempest import config
27from tempest.lib.common.utils import data_utils
28from tempest.lib.common.utils.linux import remote_client
Jude Cross986e3f52017-07-24 14:57:20 -070029from tempest.lib import exceptions
30from tempest import test
Michael Johnson04dc5cb2019-01-20 11:03:50 -080031import tenacity
Jude Cross986e3f52017-07-24 14:57:20 -070032
Michael Johnsonbaf12e02020-10-27 16:10:28 -070033from octavia_tempest_plugin.common import cert_utils
Jude Cross986e3f52017-07-24 14:57:20 -070034from octavia_tempest_plugin.common import constants as const
Michael Johnson6006de72021-02-21 01:42:39 +000035from octavia_tempest_plugin.tests import RBAC_tests
Jude Cross986e3f52017-07-24 14:57:20 -070036from octavia_tempest_plugin.tests import validators
37from octavia_tempest_plugin.tests import waiters
38
39CONF = config.CONF
40LOG = logging.getLogger(__name__)
41
Michael Johnson04dc5cb2019-01-20 11:03:50 -080042RETRY_ATTEMPTS = 15
43RETRY_INITIAL_DELAY = 1
44RETRY_BACKOFF = 1
45RETRY_MAX = 5
46
Gregory Thiemonge29d17902019-04-30 15:06:17 +020047
Michael Johnson6006de72021-02-21 01:42:39 +000048class LoadBalancerBaseTest(validators.ValidatorsMixin,
49 RBAC_tests.RBACTestsMixin, test.BaseTestCase):
Jude Cross986e3f52017-07-24 14:57:20 -070050 """Base class for load balancer tests."""
51
Gregory Thiemonge3497f6c2021-04-19 21:33:13 +020052 if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN:
53 credentials = [
54 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role],
55 ['lb_member', CONF.load_balancer.member_role],
56 ['lb_member2', CONF.load_balancer.member_role]]
57 elif CONF.load_balancer.enforce_new_defaults:
Michael Johnson6006de72021-02-21 01:42:39 +000058 credentials = [
59 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role],
60 ['lb_observer', CONF.load_balancer.observer_role, 'reader'],
61 ['lb_global_observer', CONF.load_balancer.global_observer_role,
62 'reader'],
63 ['lb_member', CONF.load_balancer.member_role, 'member'],
64 ['lb_member2', CONF.load_balancer.member_role, 'member'],
65 ['lb_member_not_default_member', CONF.load_balancer.member_role]]
66 else:
67 credentials = [
68 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role],
69 ['lb_observer', CONF.load_balancer.observer_role, 'reader'],
70 ['lb_global_observer', CONF.load_balancer.global_observer_role,
71 'reader'],
72 ['lb_member', CONF.load_balancer.member_role],
73 ['lb_member2', CONF.load_balancer.member_role]]
74
75 # If scope enforcement is enabled, add in the system scope credentials.
76 # The project scope is already handled by the above credentials.
77 if CONF.enforce_scope.octavia:
78 credentials.extend(['system_admin', 'system_reader'])
79
80 # A tuple of credentials that will be allocated by tempest using the
81 # 'credentials' list above. These are used to build RBAC test lists.
82 allocated_creds = []
83 for cred in credentials:
84 if isinstance(cred, list):
85 allocated_creds.append('os_roles_' + cred[0])
86 else:
87 allocated_creds.append('os_' + cred)
88 # Tests shall not mess with the list of allocated credentials
89 allocated_credentials = tuple(allocated_creds)
Jude Cross986e3f52017-07-24 14:57:20 -070090
Adam Harwelle029af22018-05-24 17:13:28 -070091 webserver1_response = 1
92 webserver2_response = 5
Michael Johnsondfd818a2018-08-21 20:54:54 -070093 used_ips = []
Jude Cross986e3f52017-07-24 14:57:20 -070094
Michael Johnson89bdbcd2020-03-19 15:59:19 -070095 SRC_PORT_NUMBER_MIN = 32768
96 SRC_PORT_NUMBER_MAX = 61000
Gregory Thiemonge29d17902019-04-30 15:06:17 +020097 src_port_number = SRC_PORT_NUMBER_MIN
98
Jude Cross986e3f52017-07-24 14:57:20 -070099 @classmethod
100 def skip_checks(cls):
101 """Check if we should skip all of the children tests."""
102 super(LoadBalancerBaseTest, cls).skip_checks()
103
104 service_list = {
105 'load_balancer': CONF.service_available.load_balancer,
106 }
107
108 live_service_list = {
109 'compute': CONF.service_available.nova,
110 'image': CONF.service_available.glance,
111 'neutron': CONF.service_available.neutron
112 }
113
114 if not CONF.load_balancer.test_with_noop:
115 service_list.update(live_service_list)
116
117 for service, available in service_list.items():
118 if not available:
zhangzs2a6cf672018-11-10 16:13:11 +0800119 skip_msg = ("{0} skipped as {1} service is not "
Jude Cross986e3f52017-07-24 14:57:20 -0700120 "available.".format(cls.__name__, service))
121 raise cls.skipException(skip_msg)
122
123 # We must be able to reach our VIP and instances
124 if not (CONF.network.project_networks_reachable
125 or CONF.network.public_network_id):
126 msg = ('Either project_networks_reachable must be "true", or '
127 'public_network_id must be defined.')
128 raise cls.skipException(msg)
129
130 @classmethod
131 def setup_credentials(cls):
132 """Setup test credentials and network resources."""
133 # Do not auto create network resources
134 cls.set_network_resources()
135 super(LoadBalancerBaseTest, cls).setup_credentials()
136
Michael Johnson6006de72021-02-21 01:42:39 +0000137 # Log the user roles for this test run
138 role_name_cache = {}
139 for cred in cls.credentials:
140 user_roles = []
141 if isinstance(cred, list):
142 user_name = cred[0]
143 cred_obj = getattr(cls, 'os_roles_' + cred[0])
144 else:
145 user_name = cred
146 cred_obj = getattr(cls, 'os_' + cred)
147 params = {'user.id': cred_obj.credentials.user_id,
148 'project.id': cred_obj.credentials.project_id}
149 roles = cls.os_admin.role_assignments_client.list_role_assignments(
150 **params)['role_assignments']
151 for role in roles:
152 role_id = role['role']['id']
153 try:
154 role_name = role_name_cache[role_id]
155 except KeyError:
156 role_name = cls.os_admin.roles_v3_client.show_role(
157 role_id)['role']['name']
158 role_name_cache[role_id] = role_name
159 user_roles.append([role_name, role['scope']])
160 LOG.info("User %s has roles: %s", user_name, user_roles)
161
Jude Cross986e3f52017-07-24 14:57:20 -0700162 @classmethod
163 def setup_clients(cls):
164 """Setup client aliases."""
165 super(LoadBalancerBaseTest, cls).setup_clients()
Michael Johnson29d8e612021-06-23 16:16:12 +0000166 lb_admin_prefix = cls.os_roles_lb_admin.load_balancer_v2
Jude Cross986e3f52017-07-24 14:57:20 -0700167 cls.lb_mem_float_ip_client = cls.os_roles_lb_member.floating_ips_client
168 cls.lb_mem_keypairs_client = cls.os_roles_lb_member.keypairs_client
169 cls.lb_mem_net_client = cls.os_roles_lb_member.networks_client
170 cls.lb_mem_ports_client = cls.os_roles_lb_member.ports_client
171 cls.lb_mem_routers_client = cls.os_roles_lb_member.routers_client
172 cls.lb_mem_SG_client = cls.os_roles_lb_member.security_groups_client
173 cls.lb_mem_SGr_client = (
174 cls.os_roles_lb_member.security_group_rules_client)
175 cls.lb_mem_servers_client = cls.os_roles_lb_member.servers_client
176 cls.lb_mem_subnet_client = cls.os_roles_lb_member.subnets_client
Michael Johnson29d8e612021-06-23 16:16:12 +0000177 cls.mem_lb_client = (
178 cls.os_roles_lb_member.load_balancer_v2.LoadbalancerClient())
179 cls.mem_listener_client = (
180 cls.os_roles_lb_member.load_balancer_v2.ListenerClient())
181 cls.mem_pool_client = (
182 cls.os_roles_lb_member.load_balancer_v2.PoolClient())
183 cls.mem_member_client = (
184 cls.os_roles_lb_member.load_balancer_v2.MemberClient())
Adam Harwell60ed9d92018-05-10 13:23:13 -0700185 cls.mem_healthmonitor_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000186 cls.os_roles_lb_member.load_balancer_v2.HealthMonitorClient())
187 cls.mem_l7policy_client = (
188 cls.os_roles_lb_member.load_balancer_v2.L7PolicyClient())
189 cls.mem_l7rule_client = (
190 cls.os_roles_lb_member.load_balancer_v2.L7RuleClient())
191 cls.lb_admin_amphora_client = lb_admin_prefix.AmphoraClient()
Michael Johnsonaff2e862019-01-11 16:38:00 -0800192 cls.lb_admin_flavor_profile_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000193 lb_admin_prefix.FlavorProfileClient())
194 cls.lb_admin_flavor_client = lb_admin_prefix.FlavorClient()
195 cls.mem_flavor_client = (
196 cls.os_roles_lb_member.load_balancer_v2.FlavorClient())
197 cls.mem_provider_client = (
198 cls.os_roles_lb_member.load_balancer_v2.ProviderClient())
Carlos Goncalvesc2e12162019-02-14 23:57:44 +0100199 cls.os_admin_servers_client = cls.os_admin.servers_client
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100200 cls.os_admin_routers_client = cls.os_admin.routers_client
201 cls.os_admin_subnetpools_client = cls.os_admin.subnetpools_client
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800202 cls.lb_admin_flavor_capabilities_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000203 lb_admin_prefix.FlavorCapabilitiesClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800204 cls.lb_admin_availability_zone_capabilities_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000205 lb_admin_prefix.AvailabilityZoneCapabilitiesClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800206 cls.lb_admin_availability_zone_profile_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000207 lb_admin_prefix.AvailabilityZoneProfileClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800208 cls.lb_admin_availability_zone_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000209 lb_admin_prefix.AvailabilityZoneClient())
Adam Harwellc2aa20c2019-11-20 11:15:07 -0800210 cls.mem_availability_zone_client = (
Michael Johnson29d8e612021-06-23 16:16:12 +0000211 cls.os_roles_lb_member.load_balancer_v2.AvailabilityZoneClient())
Jude Cross986e3f52017-07-24 14:57:20 -0700212
213 @classmethod
214 def resource_setup(cls):
215 """Setup resources needed by the tests."""
216 super(LoadBalancerBaseTest, cls).resource_setup()
217
218 conf_lb = CONF.load_balancer
219
Michael Johnsondfd818a2018-08-21 20:54:54 -0700220 cls.api_version = cls.mem_lb_client.get_max_api_version()
221
Jude Cross986e3f52017-07-24 14:57:20 -0700222 if conf_lb.test_subnet_override and not conf_lb.test_network_override:
223 raise exceptions.InvalidConfiguration(
224 "Configuration value test_network_override must be "
225 "specified if test_subnet_override is used.")
226
Michael Johnson6a9236a2020-08-04 23:54:54 +0000227 # TODO(johnsom) Remove this
Maciej Józefczykb6df5f82019-12-10 10:12:30 +0000228 # Get loadbalancing algorithms supported by provider driver.
229 try:
230 algorithms = const.SUPPORTED_LB_ALGORITHMS[
231 CONF.load_balancer.provider]
232 except KeyError:
233 algorithms = const.SUPPORTED_LB_ALGORITHMS['default']
234 # Set default algorithm as first from the list.
235 cls.lb_algorithm = algorithms[0]
236
Jude Cross986e3f52017-07-24 14:57:20 -0700237 show_subnet = cls.lb_mem_subnet_client.show_subnet
238 if CONF.load_balancer.test_with_noop:
239 cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()}
240 cls.lb_member_vip_subnet = {'id': uuidutils.generate_uuid()}
241 cls.lb_member_1_net = {'id': uuidutils.generate_uuid()}
242 cls.lb_member_1_subnet = {'id': uuidutils.generate_uuid()}
243 cls.lb_member_2_net = {'id': uuidutils.generate_uuid()}
244 cls.lb_member_2_subnet = {'id': uuidutils.generate_uuid()}
245 if CONF.load_balancer.test_with_ipv6:
Michael Johnson5a16ad32018-10-18 14:49:11 -0700246 cls.lb_member_vip_ipv6_net = {'id': uuidutils.generate_uuid()}
Jude Cross986e3f52017-07-24 14:57:20 -0700247 cls.lb_member_vip_ipv6_subnet = {'id':
248 uuidutils.generate_uuid()}
249 cls.lb_member_1_ipv6_subnet = {'id': uuidutils.generate_uuid()}
250 cls.lb_member_2_ipv6_subnet = {'id': uuidutils.generate_uuid()}
Michael Johnson590fbe12019-07-03 14:30:01 -0700251 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700252 return
253 elif CONF.load_balancer.test_network_override:
254 if conf_lb.test_subnet_override:
255 override_subnet = show_subnet(conf_lb.test_subnet_override)
256 else:
257 override_subnet = None
258
259 show_net = cls.lb_mem_net_client.show_network
260 override_network = show_net(conf_lb.test_network_override)
261 override_network = override_network.get('network')
262
263 cls.lb_member_vip_net = override_network
264 cls.lb_member_vip_subnet = override_subnet
265 cls.lb_member_1_net = override_network
266 cls.lb_member_1_subnet = override_subnet
267 cls.lb_member_2_net = override_network
268 cls.lb_member_2_subnet = override_subnet
269
270 if (CONF.load_balancer.test_with_ipv6 and
271 conf_lb.test_IPv6_subnet_override):
272 override_ipv6_subnet = show_subnet(
273 conf_lb.test_IPv6_subnet_override)
274 cls.lb_member_vip_ipv6_subnet = override_ipv6_subnet
275 cls.lb_member_1_ipv6_subnet = override_ipv6_subnet
276 cls.lb_member_2_ipv6_subnet = override_ipv6_subnet
Michael Johnson590fbe12019-07-03 14:30:01 -0700277 cls.lb_member_vip_ipv6_subnet_stateful = False
278 if (override_ipv6_subnet[0]['ipv6_address_mode'] ==
279 'dhcpv6-stateful'):
280 cls.lb_member_vip_ipv6_subnet_stateful = True
Jude Cross986e3f52017-07-24 14:57:20 -0700281 else:
282 cls.lb_member_vip_ipv6_subnet = None
283 cls.lb_member_1_ipv6_subnet = None
284 cls.lb_member_2_ipv6_subnet = None
285 else:
286 cls._create_networks()
287
288 LOG.debug('Octavia Setup: lb_member_vip_net = {}'.format(
289 cls.lb_member_vip_net[const.ID]))
290 if cls.lb_member_vip_subnet:
291 LOG.debug('Octavia Setup: lb_member_vip_subnet = {}'.format(
292 cls.lb_member_vip_subnet[const.ID]))
293 LOG.debug('Octavia Setup: lb_member_1_net = {}'.format(
294 cls.lb_member_1_net[const.ID]))
295 if cls.lb_member_1_subnet:
296 LOG.debug('Octavia Setup: lb_member_1_subnet = {}'.format(
297 cls.lb_member_1_subnet[const.ID]))
298 LOG.debug('Octavia Setup: lb_member_2_net = {}'.format(
299 cls.lb_member_2_net[const.ID]))
300 if cls.lb_member_2_subnet:
301 LOG.debug('Octavia Setup: lb_member_2_subnet = {}'.format(
302 cls.lb_member_2_subnet[const.ID]))
Michael Johnson124ba8b2018-08-30 16:06:05 -0700303 if CONF.load_balancer.test_with_ipv6:
304 if cls.lb_member_vip_ipv6_subnet:
305 LOG.debug('Octavia Setup: lb_member_vip_ipv6_subnet = '
306 '{}'.format(cls.lb_member_vip_ipv6_subnet[const.ID]))
307 if cls.lb_member_1_ipv6_subnet:
308 LOG.debug('Octavia Setup: lb_member_1_ipv6_subnet = {}'.format(
309 cls.lb_member_1_ipv6_subnet[const.ID]))
310 if cls.lb_member_2_ipv6_subnet:
311 LOG.debug('Octavia Setup: lb_member_2_ipv6_subnet = {}'.format(
312 cls.lb_member_2_ipv6_subnet[const.ID]))
Jude Cross986e3f52017-07-24 14:57:20 -0700313
Jude Cross986e3f52017-07-24 14:57:20 -0700314 @classmethod
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800315 # Neutron can be slow to clean up ports from the subnets/networks.
316 # Retry this delete a few times if we get a "Conflict" error to give
317 # neutron time to fully cleanup the ports.
318 @tenacity.retry(
319 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
320 wait=tenacity.wait_incrementing(
321 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
322 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
323 def _logging_delete_network(cls, net_id):
324 try:
325 cls.lb_mem_net_client.delete_network(net_id)
326 except Exception:
327 LOG.error('Unable to delete network {}. Active ports:'.format(
328 net_id))
329 LOG.error(cls.lb_mem_ports_client.list_ports())
330 raise
331
332 @classmethod
333 # Neutron can be slow to clean up ports from the subnets/networks.
334 # Retry this delete a few times if we get a "Conflict" error to give
335 # neutron time to fully cleanup the ports.
336 @tenacity.retry(
337 retry=tenacity.retry_if_exception_type(exceptions.Conflict),
338 wait=tenacity.wait_incrementing(
339 RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX),
340 stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS))
341 def _logging_delete_subnet(cls, subnet_id):
342 try:
343 cls.lb_mem_subnet_client.delete_subnet(subnet_id)
344 except Exception:
345 LOG.error('Unable to delete subnet {}. Active ports:'.format(
346 subnet_id))
347 LOG.error(cls.lb_mem_ports_client.list_ports())
348 raise
349
350 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -0700351 def _create_networks(cls):
352 """Creates networks, subnets, and routers used in tests.
353
354 The following are expected to be defined and available to the tests:
355 cls.lb_member_vip_net
356 cls.lb_member_vip_subnet
357 cls.lb_member_vip_ipv6_subnet (optional)
358 cls.lb_member_1_net
359 cls.lb_member_1_subnet
360 cls.lb_member_1_ipv6_subnet (optional)
361 cls.lb_member_2_net
362 cls.lb_member_2_subnet
363 cls.lb_member_2_ipv6_subnet (optional)
364 """
365
366 # Create tenant VIP network
367 network_kwargs = {
368 'name': data_utils.rand_name("lb_member_vip_network")}
369 if CONF.network_feature_enabled.port_security:
Andreas Jaeger4215b702020-03-28 20:13:46 +0100370 # Note: Allowed Address Pairs requires port security
371 network_kwargs['port_security_enabled'] = True
Jude Cross986e3f52017-07-24 14:57:20 -0700372 result = cls.lb_mem_net_client.create_network(**network_kwargs)
373 cls.lb_member_vip_net = result['network']
374 LOG.info('lb_member_vip_net: {}'.format(cls.lb_member_vip_net))
375 cls.addClassResourceCleanup(
376 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800377 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700378 cls.lb_mem_net_client.show_network,
379 cls.lb_member_vip_net['id'])
380
381 # Create tenant VIP subnet
382 subnet_kwargs = {
383 'name': data_utils.rand_name("lb_member_vip_subnet"),
384 'network_id': cls.lb_member_vip_net['id'],
385 'cidr': CONF.load_balancer.vip_subnet_cidr,
386 'ip_version': 4}
387 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
388 cls.lb_member_vip_subnet = result['subnet']
389 LOG.info('lb_member_vip_subnet: {}'.format(cls.lb_member_vip_subnet))
390 cls.addClassResourceCleanup(
391 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800392 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700393 cls.lb_mem_subnet_client.show_subnet,
394 cls.lb_member_vip_subnet['id'])
395
396 # Create tenant VIP IPv6 subnet
397 if CONF.load_balancer.test_with_ipv6:
Michael Johnson590fbe12019-07-03 14:30:01 -0700398 cls.lb_member_vip_ipv6_subnet_stateful = False
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100399 cls.lb_member_vip_ipv6_subnet_use_subnetpool = False
400 subnet_kwargs = {
401 'name': data_utils.rand_name("lb_member_vip_ipv6_subnet"),
402 'network_id': cls.lb_member_vip_net['id'],
403 'ip_version': 6}
404
405 # Use a CIDR from devstack's default IPv6 subnetpool if it exists,
406 # the subnetpool's cidr is routable from the devstack node
407 # through the default router
408 subnetpool_name = CONF.load_balancer.default_ipv6_subnetpool
409 if subnetpool_name:
410 subnetpool = cls.os_admin_subnetpools_client.list_subnetpools(
411 name=subnetpool_name)['subnetpools']
412 if len(subnetpool) == 1:
413 subnetpool = subnetpool[0]
414 subnet_kwargs['subnetpool_id'] = subnetpool['id']
415 cls.lb_member_vip_ipv6_subnet_use_subnetpool = True
416
417 if 'subnetpool_id' not in subnet_kwargs:
418 subnet_kwargs['cidr'] = (
419 CONF.load_balancer.vip_ipv6_subnet_cidr)
420
421 result = cls.lb_mem_subnet_client.create_subnet(
422 **subnet_kwargs)
423 cls.lb_member_vip_ipv6_net = cls.lb_member_vip_net
424 cls.lb_member_vip_ipv6_subnet = result['subnet']
425 cls.addClassResourceCleanup(
426 waiters.wait_for_not_found,
427 cls._logging_delete_subnet,
428 cls.lb_mem_subnet_client.show_subnet,
429 cls.lb_member_vip_ipv6_subnet['id'])
Carlos Goncalves84af48c2019-07-25 15:51:30 +0200430
Jude Cross986e3f52017-07-24 14:57:20 -0700431 LOG.info('lb_member_vip_ipv6_subnet: {}'.format(
432 cls.lb_member_vip_ipv6_subnet))
Jude Cross986e3f52017-07-24 14:57:20 -0700433
434 # Create tenant member 1 network
435 network_kwargs = {
436 'name': data_utils.rand_name("lb_member_1_network")}
437 if CONF.network_feature_enabled.port_security:
438 if CONF.load_balancer.enable_security_groups:
439 network_kwargs['port_security_enabled'] = True
440 else:
441 network_kwargs['port_security_enabled'] = False
442 result = cls.lb_mem_net_client.create_network(**network_kwargs)
443 cls.lb_member_1_net = result['network']
444 LOG.info('lb_member_1_net: {}'.format(cls.lb_member_1_net))
445 cls.addClassResourceCleanup(
446 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800447 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700448 cls.lb_mem_net_client.show_network,
449 cls.lb_member_1_net['id'])
450
451 # Create tenant member 1 subnet
452 subnet_kwargs = {
453 'name': data_utils.rand_name("lb_member_1_subnet"),
454 'network_id': cls.lb_member_1_net['id'],
455 'cidr': CONF.load_balancer.member_1_ipv4_subnet_cidr,
456 'ip_version': 4}
457 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
458 cls.lb_member_1_subnet = result['subnet']
459 LOG.info('lb_member_1_subnet: {}'.format(cls.lb_member_1_subnet))
460 cls.addClassResourceCleanup(
461 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800462 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700463 cls.lb_mem_subnet_client.show_subnet,
464 cls.lb_member_1_subnet['id'])
465
466 # Create tenant member 1 ipv6 subnet
467 if CONF.load_balancer.test_with_ipv6:
468 subnet_kwargs = {
469 'name': data_utils.rand_name("lb_member_1_ipv6_subnet"),
470 'network_id': cls.lb_member_1_net['id'],
471 'cidr': CONF.load_balancer.member_1_ipv6_subnet_cidr,
472 'ip_version': 6}
473 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700474 cls.lb_member_1_subnet_prefix = (
475 CONF.load_balancer.member_1_ipv6_subnet_cidr.rpartition('/')[2]
476 )
477 assert(cls.lb_member_1_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700478 cls.lb_member_1_ipv6_subnet = result['subnet']
479 LOG.info('lb_member_1_ipv6_subnet: {}'.format(
480 cls.lb_member_1_ipv6_subnet))
481 cls.addClassResourceCleanup(
482 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800483 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700484 cls.lb_mem_subnet_client.show_subnet,
485 cls.lb_member_1_ipv6_subnet['id'])
486
487 # Create tenant member 2 network
488 network_kwargs = {
489 'name': data_utils.rand_name("lb_member_2_network")}
490 if CONF.network_feature_enabled.port_security:
491 if CONF.load_balancer.enable_security_groups:
492 network_kwargs['port_security_enabled'] = True
493 else:
494 network_kwargs['port_security_enabled'] = False
495 result = cls.lb_mem_net_client.create_network(**network_kwargs)
496 cls.lb_member_2_net = result['network']
497 LOG.info('lb_member_2_net: {}'.format(cls.lb_member_2_net))
498 cls.addClassResourceCleanup(
499 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800500 cls._logging_delete_network,
Jude Cross986e3f52017-07-24 14:57:20 -0700501 cls.lb_mem_net_client.show_network,
502 cls.lb_member_2_net['id'])
503
504 # Create tenant member 2 subnet
505 subnet_kwargs = {
506 'name': data_utils.rand_name("lb_member_2_subnet"),
507 'network_id': cls.lb_member_2_net['id'],
508 'cidr': CONF.load_balancer.member_2_ipv4_subnet_cidr,
509 'ip_version': 4}
510 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
511 cls.lb_member_2_subnet = result['subnet']
512 LOG.info('lb_member_2_subnet: {}'.format(cls.lb_member_2_subnet))
513 cls.addClassResourceCleanup(
514 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800515 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700516 cls.lb_mem_subnet_client.show_subnet,
517 cls.lb_member_2_subnet['id'])
518
519 # Create tenant member 2 ipv6 subnet
520 if CONF.load_balancer.test_with_ipv6:
521 subnet_kwargs = {
522 'name': data_utils.rand_name("lb_member_2_ipv6_subnet"),
523 'network_id': cls.lb_member_2_net['id'],
524 'cidr': CONF.load_balancer.member_2_ipv6_subnet_cidr,
525 'ip_version': 6}
526 result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs)
Michael Johnsonbf916df2018-10-17 10:59:28 -0700527 cls.lb_member_2_subnet_prefix = (
528 CONF.load_balancer.member_2_ipv6_subnet_cidr.rpartition('/')[2]
529 )
530 assert(cls.lb_member_2_subnet_prefix.isdigit())
Jude Cross986e3f52017-07-24 14:57:20 -0700531 cls.lb_member_2_ipv6_subnet = result['subnet']
532 LOG.info('lb_member_2_ipv6_subnet: {}'.format(
533 cls.lb_member_2_ipv6_subnet))
534 cls.addClassResourceCleanup(
535 waiters.wait_for_not_found,
Michael Johnson04dc5cb2019-01-20 11:03:50 -0800536 cls._logging_delete_subnet,
Jude Cross986e3f52017-07-24 14:57:20 -0700537 cls.lb_mem_subnet_client.show_subnet,
538 cls.lb_member_2_ipv6_subnet['id'])
539
Adam Harwellcd72b562018-05-07 11:37:22 -0700540 @classmethod
Michael Johnson07c9a632018-06-07 13:27:42 -0700541 def _setup_lb_network_kwargs(cls, lb_kwargs, ip_version=None,
542 use_fixed_ip=False):
Adam Harwell60ed9d92018-05-10 13:23:13 -0700543 if not ip_version:
544 ip_version = 6 if CONF.load_balancer.test_with_ipv6 else 4
Michael Johnson5a16ad32018-10-18 14:49:11 -0700545 if cls.lb_member_vip_subnet or cls.lb_member_vip_ipv6_subnet:
Adam Harwellcd72b562018-05-07 11:37:22 -0700546 ip_index = data_utils.rand_int_id(start=10, end=100)
Michael Johnsondfd818a2018-08-21 20:54:54 -0700547 while ip_index in cls.used_ips:
548 ip_index = data_utils.rand_int_id(start=10, end=100)
549 cls.used_ips.append(ip_index)
Adam Harwellcd72b562018-05-07 11:37:22 -0700550 if ip_version == 4:
Adam Harwellcd72b562018-05-07 11:37:22 -0700551 subnet_id = cls.lb_member_vip_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700552 if CONF.load_balancer.test_with_noop:
553 lb_vip_address = '198.18.33.33'
554 else:
555 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
556 network = ipaddress.IPv4Network(subnet['subnet']['cidr'])
557 lb_vip_address = str(network[ip_index])
Adam Harwellcd72b562018-05-07 11:37:22 -0700558 else:
Adam Harwellcd72b562018-05-07 11:37:22 -0700559 subnet_id = cls.lb_member_vip_ipv6_subnet[const.ID]
Michael Johnson5a16ad32018-10-18 14:49:11 -0700560 if CONF.load_balancer.test_with_noop:
561 lb_vip_address = '2001:db8:33:33:33:33:33:33'
562 else:
563 subnet = cls.os_admin.subnets_client.show_subnet(subnet_id)
564 network = ipaddress.IPv6Network(subnet['subnet']['cidr'])
565 lb_vip_address = str(network[ip_index])
Michael Johnson590fbe12019-07-03 14:30:01 -0700566 # If the subnet is IPv6 slaac or dhcpv6-stateless
567 # neutron does not allow a fixed IP
568 if not cls.lb_member_vip_ipv6_subnet_stateful:
569 use_fixed_ip = False
Adam Harwellcd72b562018-05-07 11:37:22 -0700570 lb_kwargs[const.VIP_SUBNET_ID] = subnet_id
Michael Johnson07c9a632018-06-07 13:27:42 -0700571 if use_fixed_ip:
572 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700573 if CONF.load_balancer.test_with_noop:
574 lb_kwargs[const.VIP_NETWORK_ID] = (
575 cls.lb_member_vip_net[const.ID])
Carlos Goncalvesbb238552020-01-15 10:10:55 +0000576 if ip_version == 6:
577 lb_kwargs[const.VIP_ADDRESS] = lb_vip_address
Adam Harwellcd72b562018-05-07 11:37:22 -0700578 else:
579 lb_kwargs[const.VIP_NETWORK_ID] = cls.lb_member_vip_net[const.ID]
580 lb_kwargs[const.VIP_SUBNET_ID] = None
581
582
583class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest):
584 @classmethod
585 def resource_setup(cls):
586 super(LoadBalancerBaseTestWithCompute, cls).resource_setup()
587 # If validation is disabled in this cloud, we won't be able to
588 # start the webservers, so don't even boot them.
589 if not CONF.validation.run_validation:
590 return
591
592 # Create a keypair for the webservers
593 keypair_name = data_utils.rand_name('lb_member_keypair')
594 result = cls.lb_mem_keypairs_client.create_keypair(
595 name=keypair_name)
596 cls.lb_member_keypair = result['keypair']
597 LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair))
598 cls.addClassResourceCleanup(
599 waiters.wait_for_not_found,
600 cls.lb_mem_keypairs_client.delete_keypair,
601 cls.lb_mem_keypairs_client.show_keypair,
602 keypair_name)
603
604 if (CONF.load_balancer.enable_security_groups and
605 CONF.network_feature_enabled.port_security):
606 # Set up the security group for the webservers
607 SG_name = data_utils.rand_name('lb_member_SG')
608 cls.lb_member_sec_group = (
609 cls.lb_mem_SG_client.create_security_group(
610 name=SG_name)['security_group'])
611 cls.addClassResourceCleanup(
612 waiters.wait_for_not_found,
613 cls.lb_mem_SG_client.delete_security_group,
614 cls.lb_mem_SG_client.show_security_group,
615 cls.lb_member_sec_group['id'])
616
617 # Create a security group rule to allow 80-81 (test webservers)
618 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
619 direction='ingress',
620 security_group_id=cls.lb_member_sec_group['id'],
621 protocol='tcp',
622 ethertype='IPv4',
623 port_range_min=80,
624 port_range_max=81)['security_group_rule']
625 cls.addClassResourceCleanup(
626 waiters.wait_for_not_found,
627 cls.lb_mem_SGr_client.delete_security_group_rule,
628 cls.lb_mem_SGr_client.show_security_group_rule,
629 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200630 # Create a security group rule to allow UDP 80-81 (test webservers)
631 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
632 direction='ingress',
633 security_group_id=cls.lb_member_sec_group['id'],
634 protocol='udp',
635 ethertype='IPv4',
636 port_range_min=80,
637 port_range_max=81)['security_group_rule']
638 cls.addClassResourceCleanup(
639 waiters.wait_for_not_found,
640 cls.lb_mem_SGr_client.delete_security_group_rule,
641 cls.lb_mem_SGr_client.show_security_group_rule,
642 SGr['id'])
643 # Create a security group rule to allow UDP 9999 (test webservers)
644 # Port 9999 is used to illustrate health monitor ERRORs on closed
645 # ports.
646 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
647 direction='ingress',
648 security_group_id=cls.lb_member_sec_group['id'],
649 protocol='udp',
650 ethertype='IPv4',
651 port_range_min=9999,
652 port_range_max=9999)['security_group_rule']
653 cls.addClassResourceCleanup(
654 waiters.wait_for_not_found,
655 cls.lb_mem_SGr_client.delete_security_group_rule,
656 cls.lb_mem_SGr_client.show_security_group_rule,
657 SGr['id'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700658 # Create a security group rule to allow 22 (ssh)
659 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
660 direction='ingress',
661 security_group_id=cls.lb_member_sec_group['id'],
662 protocol='tcp',
663 ethertype='IPv4',
664 port_range_min=22,
665 port_range_max=22)['security_group_rule']
666 cls.addClassResourceCleanup(
667 waiters.wait_for_not_found,
668 cls.lb_mem_SGr_client.delete_security_group_rule,
669 cls.lb_mem_SGr_client.show_security_group_rule,
670 SGr['id'])
671 if CONF.load_balancer.test_with_ipv6:
672 # Create a security group rule to allow 80-81 (test webservers)
673 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
674 direction='ingress',
675 security_group_id=cls.lb_member_sec_group['id'],
676 protocol='tcp',
677 ethertype='IPv6',
678 port_range_min=80,
679 port_range_max=81)['security_group_rule']
680 cls.addClassResourceCleanup(
681 waiters.wait_for_not_found,
682 cls.lb_mem_SGr_client.delete_security_group_rule,
683 cls.lb_mem_SGr_client.show_security_group_rule,
684 SGr['id'])
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200685 # Create a security group rule to allow UDP 80-81 (test
686 # 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='IPv6',
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'])
Adam Harwellcd72b562018-05-07 11:37:22 -0700699 # Create a security group rule to allow 22 (ssh)
700 SGr = cls.lb_mem_SGr_client.create_security_group_rule(
701 direction='ingress',
702 security_group_id=cls.lb_member_sec_group['id'],
703 protocol='tcp',
704 ethertype='IPv6',
705 port_range_min=22,
706 port_range_max=22)['security_group_rule']
707 cls.addClassResourceCleanup(
708 waiters.wait_for_not_found,
709 cls.lb_mem_SGr_client.delete_security_group_rule,
710 cls.lb_mem_SGr_client.show_security_group_rule,
711 SGr['id'])
712
713 LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group))
714
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700715 # Setup backend member reencryption PKI
716 cls._create_backend_reencryption_pki()
717
Adam Harwellcd72b562018-05-07 11:37:22 -0700718 # Create webserver 1 instance
719 server_details = cls._create_webserver('lb_member_webserver1',
720 cls.lb_member_1_net)
721
722 cls.lb_member_webserver1 = server_details['server']
723 cls.webserver1_ip = server_details.get('ipv4_address')
724 cls.webserver1_ipv6 = server_details.get('ipv6_address')
725 cls.webserver1_public_ip = server_details['public_ipv4_address']
726
727 LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format(
728 cls.lb_member_webserver1[const.ID]))
729 LOG.debug('Octavia Setup: webserver1_ip = {}'.format(
730 cls.webserver1_ip))
731 LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format(
732 cls.webserver1_ipv6))
733 LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format(
734 cls.webserver1_public_ip))
735
736 # Create webserver 2 instance
737 server_details = cls._create_webserver('lb_member_webserver2',
738 cls.lb_member_2_net)
739
740 cls.lb_member_webserver2 = server_details['server']
741 cls.webserver2_ip = server_details.get('ipv4_address')
742 cls.webserver2_ipv6 = server_details.get('ipv6_address')
743 cls.webserver2_public_ip = server_details['public_ipv4_address']
744
745 LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format(
746 cls.lb_member_webserver2[const.ID]))
747 LOG.debug('Octavia Setup: webserver2_ip = {}'.format(
748 cls.webserver2_ip))
749 LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format(
750 cls.webserver2_ipv6))
751 LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format(
752 cls.webserver2_public_ip))
753
Michael Johnsonbf916df2018-10-17 10:59:28 -0700754 if CONF.load_balancer.test_with_ipv6:
755 # Enable the IPv6 nic in webserver 1
756 cls._enable_ipv6_nic_webserver(
757 cls.webserver1_public_ip, cls.lb_member_keypair['private_key'],
758 cls.webserver1_ipv6, cls.lb_member_1_subnet_prefix)
759
760 # Enable the IPv6 nic in webserver 2
761 cls._enable_ipv6_nic_webserver(
762 cls.webserver2_public_ip, cls.lb_member_keypair['private_key'],
763 cls.webserver2_ipv6, cls.lb_member_2_subnet_prefix)
764
Adam Harwellcd72b562018-05-07 11:37:22 -0700765 # Set up serving on webserver 1
766 cls._install_start_webserver(cls.webserver1_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700767 cls.lb_member_keypair['private_key'],
768 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700769
770 # Validate webserver 1
Adam Harwelle029af22018-05-24 17:13:28 -0700771 cls._validate_webserver(cls.webserver1_public_ip,
772 cls.webserver1_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700773
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200774 # Validate udp server 1
775 cls._validate_udp_server(cls.webserver1_public_ip,
776 cls.webserver1_response)
777
Adam Harwellcd72b562018-05-07 11:37:22 -0700778 # Set up serving on webserver 2
779 cls._install_start_webserver(cls.webserver2_public_ip,
Adam Harwelle029af22018-05-24 17:13:28 -0700780 cls.lb_member_keypair['private_key'],
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700781 cls.webserver2_response, revoke_cert=True)
Adam Harwellcd72b562018-05-07 11:37:22 -0700782
783 # Validate webserver 2
Adam Harwelle029af22018-05-24 17:13:28 -0700784 cls._validate_webserver(cls.webserver2_public_ip,
785 cls.webserver2_response)
Adam Harwellcd72b562018-05-07 11:37:22 -0700786
Gregory Thiemonge29d17902019-04-30 15:06:17 +0200787 # Validate udp server 2
788 cls._validate_udp_server(cls.webserver2_public_ip,
789 cls.webserver2_response)
790
Adam Harwellcd72b562018-05-07 11:37:22 -0700791 @classmethod
792 def _create_networks(cls):
793 super(LoadBalancerBaseTestWithCompute, cls)._create_networks()
Jude Cross986e3f52017-07-24 14:57:20 -0700794 # Create a router for the subnets (required for the floating IP)
795 router_name = data_utils.rand_name("lb_member_router")
796 result = cls.lb_mem_routers_client.create_router(
797 name=router_name, admin_state_up=True,
798 external_gateway_info=dict(
799 network_id=CONF.network.public_network_id))
800 cls.lb_member_router = result['router']
801 LOG.info('lb_member_router: {}'.format(cls.lb_member_router))
802 cls.addClassResourceCleanup(
803 waiters.wait_for_not_found,
804 cls.lb_mem_routers_client.delete_router,
805 cls.lb_mem_routers_client.show_router,
806 cls.lb_member_router['id'])
807
808 # Add VIP subnet to router
809 cls.lb_mem_routers_client.add_router_interface(
810 cls.lb_member_router['id'],
811 subnet_id=cls.lb_member_vip_subnet['id'])
812 cls.addClassResourceCleanup(
813 waiters.wait_for_not_found,
814 cls.lb_mem_routers_client.remove_router_interface,
815 cls.lb_mem_routers_client.remove_router_interface,
816 cls.lb_member_router['id'],
817 subnet_id=cls.lb_member_vip_subnet['id'])
818
Gregory Thiemonge54225ad2021-02-04 15:25:17 +0100819 if (CONF.load_balancer.test_with_ipv6 and
820 CONF.load_balancer.default_router and
821 cls.lb_member_vip_ipv6_subnet_use_subnetpool):
822
823 router_name = CONF.load_balancer.default_router
824 # if lb_member_vip_ipv6_subnet uses devstack's subnetpool,
825 # plug the subnet into the default router
826 router = cls.os_admin.routers_client.list_routers(
827 name=router_name)['routers']
828
829 if len(router) == 1:
830 router = router[0]
831
832 # Add IPv6 VIP subnet to router1
833 cls.os_admin_routers_client.add_router_interface(
834 router['id'],
835 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
836 cls.addClassResourceCleanup(
837 waiters.wait_for_not_found,
838 cls.os_admin_routers_client.remove_router_interface,
839 cls.os_admin_routers_client.remove_router_interface,
840 router['id'],
841 subnet_id=cls.lb_member_vip_ipv6_subnet['id'])
842
Jude Cross986e3f52017-07-24 14:57:20 -0700843 # Add member subnet 1 to router
844 cls.lb_mem_routers_client.add_router_interface(
845 cls.lb_member_router['id'],
846 subnet_id=cls.lb_member_1_subnet['id'])
847 cls.addClassResourceCleanup(
848 waiters.wait_for_not_found,
Jude Cross986e3f52017-07-24 14:57:20 -0700849 cls.lb_mem_routers_client.remove_router_interface,
850 cls.lb_mem_routers_client.remove_router_interface,
851 cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id'])
852
853 # Add member subnet 2 to router
854 cls.lb_mem_routers_client.add_router_interface(
855 cls.lb_member_router['id'],
856 subnet_id=cls.lb_member_2_subnet['id'])
857 cls.addClassResourceCleanup(
858 waiters.wait_for_not_found,
859 cls.lb_mem_routers_client.remove_router_interface,
860 cls.lb_mem_routers_client.remove_router_interface,
861 cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id'])
862
863 @classmethod
864 def _create_webserver(cls, name, network):
865 """Creates a webserver with two ports.
866
867 webserver_details dictionary contains:
868 server - The compute server object
869 ipv4_address - The IPv4 address for the server (optional)
870 ipv6_address - The IPv6 address for the server (optional)
871 public_ipv4_address - The publicly accessible IPv4 address for the
872 server, this may be a floating IP (optional)
873
874 :param name: The name of the server to create.
875 :param network: The network to boot the server on.
876 :returns: webserver_details dictionary.
877 """
878 server_kwargs = {
879 'name': data_utils.rand_name(name),
880 'flavorRef': CONF.compute.flavor_ref,
881 'imageRef': CONF.compute.image_ref,
882 'key_name': cls.lb_member_keypair['name']}
883 if (CONF.load_balancer.enable_security_groups and
884 CONF.network_feature_enabled.port_security):
885 server_kwargs['security_groups'] = [
886 {'name': cls.lb_member_sec_group['name']}]
887 if not CONF.load_balancer.disable_boot_network:
888 server_kwargs['networks'] = [{'uuid': network['id']}]
889
890 # Replace the name for clouds that have limitations
891 if CONF.load_balancer.random_server_name_length:
892 r = random.SystemRandom()
893 server_kwargs['name'] = "m{}".format("".join(
894 [r.choice(string.ascii_uppercase + string.digits)
895 for _ in range(
896 CONF.load_balancer.random_server_name_length - 1)]
897 ))
898 if CONF.load_balancer.availability_zone:
899 server_kwargs['availability_zone'] = (
900 CONF.load_balancer.availability_zone)
901
902 server = cls.lb_mem_servers_client.create_server(
903 **server_kwargs)['server']
904 cls.addClassResourceCleanup(
905 waiters.wait_for_not_found,
906 cls.lb_mem_servers_client.delete_server,
907 cls.lb_mem_servers_client.show_server,
908 server['id'])
909 server = waiters.wait_for_status(
910 cls.lb_mem_servers_client.show_server,
911 server['id'], 'status', 'ACTIVE',
912 CONF.load_balancer.build_interval,
913 CONF.load_balancer.build_timeout,
914 root_tag='server')
915 webserver_details = {'server': server}
916 LOG.info('Created server: {}'.format(server))
917
918 addresses = server['addresses']
919 if CONF.load_balancer.disable_boot_network:
920 instance_network = addresses.values()[0]
921 else:
922 instance_network = addresses[network['name']]
923 for addr in instance_network:
924 if addr['version'] == 4:
925 webserver_details['ipv4_address'] = addr['addr']
926 if addr['version'] == 6:
927 webserver_details['ipv6_address'] = addr['addr']
928
929 if CONF.validation.connect_method == 'floating':
930 result = cls.lb_mem_ports_client.list_ports(
931 network_id=network['id'],
932 mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr'])
933 port_id = result['ports'][0]['id']
934 result = cls.lb_mem_float_ip_client.create_floatingip(
935 floating_network_id=CONF.network.public_network_id,
936 port_id=port_id)
937 floating_ip = result['floatingip']
938 LOG.info('webserver1_floating_ip: {}'.format(floating_ip))
939 cls.addClassResourceCleanup(
940 waiters.wait_for_not_found,
941 cls.lb_mem_float_ip_client.delete_floatingip,
942 cls.lb_mem_float_ip_client.show_floatingip,
943 floatingip_id=floating_ip['id'])
944 webserver_details['public_ipv4_address'] = (
945 floating_ip['floating_ip_address'])
946 else:
947 webserver_details['public_ipv4_address'] = (
948 instance_network[0]['addr'])
949
950 return webserver_details
951
952 @classmethod
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700953 def _install_start_webserver(cls, ip_address, ssh_key, start_id,
954 revoke_cert=False):
Michael Johnson27357352020-11-13 13:55:09 -0800955 local_file = CONF.load_balancer.test_server_path
Adam Harwellcd72b562018-05-07 11:37:22 -0700956
957 linux_client = remote_client.RemoteClient(
958 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key)
959 linux_client.validate_authentication()
960
961 with tempfile.NamedTemporaryFile() as key:
962 key.write(ssh_key.encode('utf-8'))
963 key.flush()
964 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
965 "-o StrictHostKeyChecking=no "
966 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
967 "-i {2} {3} {4}@{5}:{6}").format(
968 CONF.load_balancer.scp_connection_timeout,
969 CONF.load_balancer.scp_connection_attempts,
970 key.name, local_file, CONF.validation.image_ssh_user,
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700971 ip_address, const.TEST_SERVER_BINARY)
Adam Harwellcd72b562018-05-07 11:37:22 -0700972 args = shlex.split(cmd)
973 subprocess_args = {'stdout': subprocess.PIPE,
974 'stderr': subprocess.STDOUT,
975 'cwd': None}
976 proc = subprocess.Popen(args, **subprocess_args)
977 stdout, stderr = proc.communicate()
978 if proc.returncode != 0:
979 raise exceptions.CommandFailed(proc.returncode, cmd,
980 stdout, stderr)
Gregory Thiemongef72a8862019-08-06 17:25:42 +0200981
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700982 cls._load_member_pki_content(ip_address, key,
983 revoke_cert=revoke_cert)
984
Gregory Thiemongef72a8862019-08-06 17:25:42 +0200985 # Enabling memory overcommit allows to run golang static binaries
986 # compiled with a recent golang toolchain (>=1.11). Those binaries
987 # allocate a large amount of virtual memory at init time, and this
988 # allocation fails in tempest's nano flavor (64MB of RAM)
989 # (golang issue reported in https://github.com/golang/go/issues/28114,
990 # follow-up: https://github.com/golang/go/issues/28081)
991 # TODO(gthiemonge): Remove this call when golang issue is resolved.
992 linux_client.exec_command('sudo sh -c "echo 1 > '
993 '/proc/sys/vm/overcommit_memory"')
994
Michael Johnsonbaf12e02020-10-27 16:10:28 -0700995 # The initial process also supports HTTPS and HTTPS with client auth
996 linux_client.exec_command(
997 'sudo screen -d -m {0} -port 80 -id {1} -https_port 443 -cert {2} '
998 '-key {3} -https_client_auth_port 9443 -client_ca {4}'.format(
999 const.TEST_SERVER_BINARY, start_id, const.TEST_SERVER_CERT,
1000 const.TEST_SERVER_KEY, const.TEST_SERVER_CLIENT_CA))
1001
Adam Harwellcd72b562018-05-07 11:37:22 -07001002 linux_client.exec_command('sudo screen -d -m {0} -port 81 '
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001003 '-id {1}'.format(const.TEST_SERVER_BINARY,
1004 start_id + 1))
Adam Harwellcd72b562018-05-07 11:37:22 -07001005
Michael Johnsonbf916df2018-10-17 10:59:28 -07001006 # Cirros does not configure the assigned IPv6 address by default
1007 # so enable it manually like tempest does here:
1008 # tempest/scenario/test_netowrk_v6.py turn_nic6_on()
1009 @classmethod
1010 def _enable_ipv6_nic_webserver(cls, ip_address, ssh_key,
1011 ipv6_address, ipv6_prefix):
1012 linux_client = remote_client.RemoteClient(
1013 ip_address, CONF.validation.image_ssh_user, pkey=ssh_key)
1014 linux_client.validate_authentication()
1015
1016 linux_client.exec_command('sudo ip address add {0}/{1} dev '
1017 'eth0'.format(ipv6_address, ipv6_prefix))
1018
Adam Harwellcd72b562018-05-07 11:37:22 -07001019 @classmethod
Jude Cross986e3f52017-07-24 14:57:20 -07001020 def _validate_webserver(cls, ip_address, start_id):
1021 URL = 'http://{0}'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001022 cls.validate_URL_response(URL, expected_body=str(start_id))
Jude Cross986e3f52017-07-24 14:57:20 -07001023 URL = 'http://{0}:81'.format(ip_address)
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001024 cls.validate_URL_response(URL, expected_body=str(start_id + 1))
Jude Cross986e3f52017-07-24 14:57:20 -07001025
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001026 @classmethod
1027 def _validate_udp_server(cls, ip_address, start_id):
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001028 res = cls.make_udp_request(ip_address, 80)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001029 if res != str(start_id):
1030 raise Exception("Response from test server doesn't match the "
1031 "expected value ({0} != {1}).".format(
1032 res, str(start_id)))
1033
Michael Johnson89bdbcd2020-03-19 15:59:19 -07001034 res = cls.make_udp_request(ip_address, 81)
Gregory Thiemonge29d17902019-04-30 15:06:17 +02001035 if res != str(start_id + 1):
1036 raise Exception("Response from test server doesn't match the "
1037 "expected value ({0} != {1}).".format(
1038 res, str(start_id + 1)))
Michael Johnsonbaf12e02020-10-27 16:10:28 -07001039
1040 @classmethod
1041 def _create_backend_reencryption_pki(cls):
1042 # Create a CA self-signed cert and key for the member test servers
1043 cls.member_ca_cert, cls.member_ca_key = (
1044 cert_utils.generate_ca_cert_and_key())
1045
1046 LOG.debug('Member CA Cert: %s', cls.member_ca_cert.public_bytes(
1047 serialization.Encoding.PEM))
1048 LOG.debug('Member CA private Key: %s', cls.member_ca_key.private_bytes(
1049 encoding=serialization.Encoding.PEM,
1050 format=serialization.PrivateFormat.TraditionalOpenSSL,
1051 encryption_algorithm=serialization.NoEncryption()))
1052 LOG.debug('Member CA public Key: %s',
1053 cls.member_ca_key.public_key().public_bytes(
1054 encoding=serialization.Encoding.PEM,
1055 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1056
1057 # Create the member client authentication CA
1058 cls.member_client_ca_cert, member_client_ca_key = (
1059 cert_utils.generate_ca_cert_and_key())
1060
1061 # Create client cert and key
1062 cls.member_client_cn = uuidutils.generate_uuid()
1063 cls.member_client_cert, cls.member_client_key = (
1064 cert_utils.generate_client_cert_and_key(
1065 cls.member_client_ca_cert, member_client_ca_key,
1066 cls.member_client_cn))
1067 # Note: We are not revoking a client cert here as we don't need to
1068 # test the backend web server CRL checking.
1069
1070 @classmethod
1071 def _load_member_pki_content(cls, ip_address, ssh_key, revoke_cert=False):
1072 # Create webserver certificate and key
1073 cert, key = cert_utils.generate_server_cert_and_key(
1074 cls.member_ca_cert, cls.member_ca_key, ip_address)
1075
1076 LOG.debug('%s Cert: %s', ip_address, cert.public_bytes(
1077 serialization.Encoding.PEM))
1078 LOG.debug('%s private Key: %s', ip_address, key.private_bytes(
1079 encoding=serialization.Encoding.PEM,
1080 format=serialization.PrivateFormat.TraditionalOpenSSL,
1081 encryption_algorithm=serialization.NoEncryption()))
1082 public_key = key.public_key()
1083 LOG.debug('%s public Key: %s', ip_address, public_key.public_bytes(
1084 encoding=serialization.Encoding.PEM,
1085 format=serialization.PublicFormat.SubjectPublicKeyInfo))
1086
1087 # Create a CRL with a revoked certificate
1088 if revoke_cert:
1089 # Create a CRL with webserver 2 revoked
1090 cls.member_crl = cert_utils.generate_certificate_revocation_list(
1091 cls.member_ca_cert, cls.member_ca_key, cert)
1092
1093 # Load the certificate, key, and client CA certificate into the
1094 # test server.
1095 with tempfile.TemporaryDirectory() as tmpdir:
1096 os.umask(0)
1097 files_to_send = []
1098 cert_filename = os.path.join(tmpdir, const.CERT_PEM)
1099 files_to_send.append(cert_filename)
1100 with open(os.open(cert_filename, os.O_CREAT | os.O_WRONLY,
1101 0o700), 'w') as fh:
1102 fh.write(cert.public_bytes(
1103 serialization.Encoding.PEM).decode('utf-8'))
1104 fh.flush()
1105 key_filename = os.path.join(tmpdir, const.KEY_PEM)
1106 files_to_send.append(key_filename)
1107 with open(os.open(key_filename, os.O_CREAT | os.O_WRONLY,
1108 0o700), 'w') as fh:
1109 fh.write(key.private_bytes(
1110 encoding=serialization.Encoding.PEM,
1111 format=serialization.PrivateFormat.TraditionalOpenSSL,
1112 encryption_algorithm=serialization.NoEncryption()).decode(
1113 'utf-8'))
1114 fh.flush()
1115 client_ca_filename = os.path.join(tmpdir, const.CLIENT_CA_PEM)
1116 files_to_send.append(client_ca_filename)
1117 with open(os.open(client_ca_filename, os.O_CREAT | os.O_WRONLY,
1118 0o700), 'w') as fh:
1119 fh.write(cls.member_client_ca_cert.public_bytes(
1120 serialization.Encoding.PEM).decode('utf-8'))
1121 fh.flush()
1122
1123 # For security, we don't want to use a shell that can glob
1124 # the file names, so iterate over them.
1125 subprocess_args = {'stdout': subprocess.PIPE,
1126 'stderr': subprocess.STDOUT,
1127 'cwd': None}
1128 cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
1129 "-o StrictHostKeyChecking=no "
1130 "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
1131 "-i {2} {3} {4} {5} {6}@{7}:{8}").format(
1132 CONF.load_balancer.scp_connection_timeout,
1133 CONF.load_balancer.scp_connection_attempts,
1134 ssh_key.name, cert_filename, key_filename, client_ca_filename,
1135 CONF.validation.image_ssh_user, ip_address, const.DEV_SHM_PATH)
1136 args = shlex.split(cmd)
1137 proc = subprocess.Popen(args, **subprocess_args)
1138 stdout, stderr = proc.communicate()
1139 if proc.returncode != 0:
1140 raise exceptions.CommandFailed(proc.returncode, cmd,
1141 stdout, stderr)