Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | import ipaddress |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 16 | import os |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 17 | import random |
Gregory Thiemonge | a2c234e | 2021-11-02 17:08:29 +0100 | [diff] [blame] | 18 | import re |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 19 | import shlex |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 20 | import string |
| 21 | import subprocess |
| 22 | import tempfile |
| 23 | |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 24 | from cryptography.hazmat.primitives import serialization |
Gregory Thiemonge | b0da4f3 | 2022-02-04 08:58:06 +0100 | [diff] [blame] | 25 | from oslo_config import cfg |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 26 | from oslo_log import log as logging |
| 27 | from oslo_utils import uuidutils |
| 28 | from tempest import config |
| 29 | from tempest.lib.common.utils import data_utils |
| 30 | from tempest.lib.common.utils.linux import remote_client |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 31 | from tempest.lib import exceptions |
| 32 | from tempest import test |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 33 | import tenacity |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 34 | |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 35 | from octavia_tempest_plugin.common import cert_utils |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 36 | from octavia_tempest_plugin.common import constants as const |
Michael Johnson | 6006de7 | 2021-02-21 01:42:39 +0000 | [diff] [blame] | 37 | from octavia_tempest_plugin.tests import RBAC_tests |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 38 | from octavia_tempest_plugin.tests import validators |
| 39 | from octavia_tempest_plugin.tests import waiters |
| 40 | |
| 41 | CONF = config.CONF |
| 42 | LOG = logging.getLogger(__name__) |
| 43 | |
Gregory Thiemonge | 29d1790 | 2019-04-30 15:06:17 +0200 | [diff] [blame] | 44 | |
Michael Johnson | 6006de7 | 2021-02-21 01:42:39 +0000 | [diff] [blame] | 45 | class LoadBalancerBaseTest(validators.ValidatorsMixin, |
| 46 | RBAC_tests.RBACTestsMixin, test.BaseTestCase): |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 47 | """Base class for load balancer tests.""" |
| 48 | |
Gregory Thiemonge | 3497f6c | 2021-04-19 21:33:13 +0200 | [diff] [blame] | 49 | if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN: |
| 50 | credentials = [ |
| 51 | 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role], |
| 52 | ['lb_member', CONF.load_balancer.member_role], |
| 53 | ['lb_member2', CONF.load_balancer.member_role]] |
Michael Johnson | 6dac8ff | 2023-03-09 00:04:37 +0000 | [diff] [blame] | 54 | elif CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES: |
Michael Johnson | 6006de7 | 2021-02-21 01:42:39 +0000 | [diff] [blame] | 55 | credentials = [ |
Michael Johnson | 6dac8ff | 2023-03-09 00:04:37 +0000 | [diff] [blame] | 56 | 'admin', 'primary', |
| 57 | ['lb_admin', CONF.load_balancer.admin_role, 'admin'], |
Michael Johnson | 6006de7 | 2021-02-21 01:42:39 +0000 | [diff] [blame] | 58 | ['lb_observer', CONF.load_balancer.observer_role, 'reader'], |
| 59 | ['lb_global_observer', CONF.load_balancer.global_observer_role, |
| 60 | 'reader'], |
| 61 | ['lb_member', CONF.load_balancer.member_role, 'member'], |
| 62 | ['lb_member2', CONF.load_balancer.member_role, 'member'], |
| 63 | ['lb_member_not_default_member', CONF.load_balancer.member_role]] |
| 64 | else: |
| 65 | credentials = [ |
| 66 | 'admin', 'primary', ['lb_admin', CONF.load_balancer.admin_role], |
| 67 | ['lb_observer', CONF.load_balancer.observer_role, 'reader'], |
| 68 | ['lb_global_observer', CONF.load_balancer.global_observer_role, |
| 69 | 'reader'], |
Michael Johnson | 9e9f526 | 2023-01-18 17:59:17 +0000 | [diff] [blame] | 70 | # Note: Some projects are now requiring the 'member' role by |
| 71 | # default (nova for example) so make sure our creds have this role |
| 72 | ['lb_member', CONF.load_balancer.member_role, 'member'], |
| 73 | ['lb_member2', CONF.load_balancer.member_role, 'member']] |
Michael Johnson | 6006de7 | 2021-02-21 01:42:39 +0000 | [diff] [blame] | 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 Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 90 | |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 91 | webserver1_response = 1 |
| 92 | webserver2_response = 5 |
Michael Johnson | dfd818a | 2018-08-21 20:54:54 -0700 | [diff] [blame] | 93 | used_ips = [] |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 94 | |
Michael Johnson | 89bdbcd | 2020-03-19 15:59:19 -0700 | [diff] [blame] | 95 | SRC_PORT_NUMBER_MIN = 32768 |
| 96 | SRC_PORT_NUMBER_MAX = 61000 |
Gregory Thiemonge | 29d1790 | 2019-04-30 15:06:17 +0200 | [diff] [blame] | 97 | src_port_number = SRC_PORT_NUMBER_MIN |
| 98 | |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 99 | @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: |
zhangzs | 2a6cf67 | 2018-11-10 16:13:11 +0800 | [diff] [blame] | 119 | skip_msg = ("{0} skipped as {1} service is not " |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 120 | "available.".format(cls.__name__, service)) |
| 121 | raise cls.skipException(skip_msg) |
| 122 | |
| 123 | # We must be able to reach our VIP and instances |
| 124 | if not (CONF.network.project_networks_reachable |
| 125 | or CONF.network.public_network_id): |
| 126 | msg = ('Either project_networks_reachable must be "true", or ' |
| 127 | 'public_network_id must be defined.') |
| 128 | raise cls.skipException(msg) |
| 129 | |
| 130 | @classmethod |
| 131 | def setup_credentials(cls): |
| 132 | """Setup test credentials and network resources.""" |
| 133 | # Do not auto create network resources |
| 134 | cls.set_network_resources() |
| 135 | super(LoadBalancerBaseTest, cls).setup_credentials() |
| 136 | |
Bas de Bruijne | 530a88a | 2022-12-15 11:12:45 -0400 | [diff] [blame] | 137 | if not CONF.load_balancer.log_user_roles: |
| 138 | return |
| 139 | |
Michael Johnson | 6006de7 | 2021-02-21 01:42:39 +0000 | [diff] [blame] | 140 | # Log the user roles for this test run |
| 141 | role_name_cache = {} |
| 142 | for cred in cls.credentials: |
| 143 | user_roles = [] |
| 144 | if isinstance(cred, list): |
| 145 | user_name = cred[0] |
| 146 | cred_obj = getattr(cls, 'os_roles_' + cred[0]) |
| 147 | else: |
| 148 | user_name = cred |
| 149 | cred_obj = getattr(cls, 'os_' + cred) |
| 150 | params = {'user.id': cred_obj.credentials.user_id, |
| 151 | 'project.id': cred_obj.credentials.project_id} |
| 152 | roles = cls.os_admin.role_assignments_client.list_role_assignments( |
| 153 | **params)['role_assignments'] |
| 154 | for role in roles: |
| 155 | role_id = role['role']['id'] |
| 156 | try: |
| 157 | role_name = role_name_cache[role_id] |
| 158 | except KeyError: |
| 159 | role_name = cls.os_admin.roles_v3_client.show_role( |
| 160 | role_id)['role']['name'] |
| 161 | role_name_cache[role_id] = role_name |
| 162 | user_roles.append([role_name, role['scope']]) |
| 163 | LOG.info("User %s has roles: %s", user_name, user_roles) |
| 164 | |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 165 | @classmethod |
| 166 | def setup_clients(cls): |
| 167 | """Setup client aliases.""" |
| 168 | super(LoadBalancerBaseTest, cls).setup_clients() |
Michael Johnson | 29d8e61 | 2021-06-23 16:16:12 +0000 | [diff] [blame] | 169 | lb_admin_prefix = cls.os_roles_lb_admin.load_balancer_v2 |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 170 | cls.lb_mem_float_ip_client = cls.os_roles_lb_member.floating_ips_client |
| 171 | cls.lb_mem_keypairs_client = cls.os_roles_lb_member.keypairs_client |
| 172 | cls.lb_mem_net_client = cls.os_roles_lb_member.networks_client |
| 173 | cls.lb_mem_ports_client = cls.os_roles_lb_member.ports_client |
| 174 | cls.lb_mem_routers_client = cls.os_roles_lb_member.routers_client |
| 175 | cls.lb_mem_SG_client = cls.os_roles_lb_member.security_groups_client |
| 176 | cls.lb_mem_SGr_client = ( |
| 177 | cls.os_roles_lb_member.security_group_rules_client) |
| 178 | cls.lb_mem_servers_client = cls.os_roles_lb_member.servers_client |
| 179 | cls.lb_mem_subnet_client = cls.os_roles_lb_member.subnets_client |
Michael Johnson | 29d8e61 | 2021-06-23 16:16:12 +0000 | [diff] [blame] | 180 | cls.mem_lb_client = ( |
| 181 | cls.os_roles_lb_member.load_balancer_v2.LoadbalancerClient()) |
| 182 | cls.mem_listener_client = ( |
| 183 | cls.os_roles_lb_member.load_balancer_v2.ListenerClient()) |
| 184 | cls.mem_pool_client = ( |
| 185 | cls.os_roles_lb_member.load_balancer_v2.PoolClient()) |
| 186 | cls.mem_member_client = ( |
| 187 | cls.os_roles_lb_member.load_balancer_v2.MemberClient()) |
Adam Harwell | 60ed9d9 | 2018-05-10 13:23:13 -0700 | [diff] [blame] | 188 | cls.mem_healthmonitor_client = ( |
Michael Johnson | 29d8e61 | 2021-06-23 16:16:12 +0000 | [diff] [blame] | 189 | cls.os_roles_lb_member.load_balancer_v2.HealthMonitorClient()) |
| 190 | cls.mem_l7policy_client = ( |
| 191 | cls.os_roles_lb_member.load_balancer_v2.L7PolicyClient()) |
| 192 | cls.mem_l7rule_client = ( |
| 193 | cls.os_roles_lb_member.load_balancer_v2.L7RuleClient()) |
| 194 | cls.lb_admin_amphora_client = lb_admin_prefix.AmphoraClient() |
Michael Johnson | aff2e86 | 2019-01-11 16:38:00 -0800 | [diff] [blame] | 195 | cls.lb_admin_flavor_profile_client = ( |
Michael Johnson | 29d8e61 | 2021-06-23 16:16:12 +0000 | [diff] [blame] | 196 | lb_admin_prefix.FlavorProfileClient()) |
| 197 | cls.lb_admin_flavor_client = lb_admin_prefix.FlavorClient() |
| 198 | cls.mem_flavor_client = ( |
| 199 | cls.os_roles_lb_member.load_balancer_v2.FlavorClient()) |
| 200 | cls.mem_provider_client = ( |
| 201 | cls.os_roles_lb_member.load_balancer_v2.ProviderClient()) |
Carlos Goncalves | c2e1216 | 2019-02-14 23:57:44 +0100 | [diff] [blame] | 202 | cls.os_admin_servers_client = cls.os_admin.servers_client |
Gregory Thiemonge | 54225ad | 2021-02-04 15:25:17 +0100 | [diff] [blame] | 203 | cls.os_admin_routers_client = cls.os_admin.routers_client |
| 204 | cls.os_admin_subnetpools_client = cls.os_admin.subnetpools_client |
Adam Harwell | c2aa20c | 2019-11-20 11:15:07 -0800 | [diff] [blame] | 205 | cls.lb_admin_flavor_capabilities_client = ( |
Michael Johnson | 29d8e61 | 2021-06-23 16:16:12 +0000 | [diff] [blame] | 206 | lb_admin_prefix.FlavorCapabilitiesClient()) |
Adam Harwell | c2aa20c | 2019-11-20 11:15:07 -0800 | [diff] [blame] | 207 | cls.lb_admin_availability_zone_capabilities_client = ( |
Michael Johnson | 29d8e61 | 2021-06-23 16:16:12 +0000 | [diff] [blame] | 208 | lb_admin_prefix.AvailabilityZoneCapabilitiesClient()) |
Adam Harwell | c2aa20c | 2019-11-20 11:15:07 -0800 | [diff] [blame] | 209 | cls.lb_admin_availability_zone_profile_client = ( |
Michael Johnson | 29d8e61 | 2021-06-23 16:16:12 +0000 | [diff] [blame] | 210 | lb_admin_prefix.AvailabilityZoneProfileClient()) |
Adam Harwell | c2aa20c | 2019-11-20 11:15:07 -0800 | [diff] [blame] | 211 | cls.lb_admin_availability_zone_client = ( |
Michael Johnson | 29d8e61 | 2021-06-23 16:16:12 +0000 | [diff] [blame] | 212 | lb_admin_prefix.AvailabilityZoneClient()) |
Adam Harwell | c2aa20c | 2019-11-20 11:15:07 -0800 | [diff] [blame] | 213 | cls.mem_availability_zone_client = ( |
Michael Johnson | 29d8e61 | 2021-06-23 16:16:12 +0000 | [diff] [blame] | 214 | cls.os_roles_lb_member.load_balancer_v2.AvailabilityZoneClient()) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 215 | |
| 216 | @classmethod |
| 217 | def resource_setup(cls): |
| 218 | """Setup resources needed by the tests.""" |
| 219 | super(LoadBalancerBaseTest, cls).resource_setup() |
| 220 | |
| 221 | conf_lb = CONF.load_balancer |
| 222 | |
Michael Johnson | dfd818a | 2018-08-21 20:54:54 -0700 | [diff] [blame] | 223 | cls.api_version = cls.mem_lb_client.get_max_api_version() |
| 224 | |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 225 | if conf_lb.test_subnet_override and not conf_lb.test_network_override: |
| 226 | raise exceptions.InvalidConfiguration( |
| 227 | "Configuration value test_network_override must be " |
| 228 | "specified if test_subnet_override is used.") |
| 229 | |
Michael Johnson | 6a9236a | 2020-08-04 23:54:54 +0000 | [diff] [blame] | 230 | # TODO(johnsom) Remove this |
Maciej Józefczyk | b6df5f8 | 2019-12-10 10:12:30 +0000 | [diff] [blame] | 231 | # Get loadbalancing algorithms supported by provider driver. |
| 232 | try: |
| 233 | algorithms = const.SUPPORTED_LB_ALGORITHMS[ |
| 234 | CONF.load_balancer.provider] |
| 235 | except KeyError: |
| 236 | algorithms = const.SUPPORTED_LB_ALGORITHMS['default'] |
| 237 | # Set default algorithm as first from the list. |
| 238 | cls.lb_algorithm = algorithms[0] |
| 239 | |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 240 | show_subnet = cls.lb_mem_subnet_client.show_subnet |
| 241 | if CONF.load_balancer.test_with_noop: |
| 242 | cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()} |
| 243 | cls.lb_member_vip_subnet = {'id': uuidutils.generate_uuid()} |
| 244 | cls.lb_member_1_net = {'id': uuidutils.generate_uuid()} |
| 245 | cls.lb_member_1_subnet = {'id': uuidutils.generate_uuid()} |
| 246 | cls.lb_member_2_net = {'id': uuidutils.generate_uuid()} |
| 247 | cls.lb_member_2_subnet = {'id': uuidutils.generate_uuid()} |
| 248 | if CONF.load_balancer.test_with_ipv6: |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 249 | cls.lb_member_vip_ipv6_net = {'id': uuidutils.generate_uuid()} |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 250 | cls.lb_member_vip_ipv6_subnet = {'id': |
| 251 | uuidutils.generate_uuid()} |
| 252 | cls.lb_member_1_ipv6_subnet = {'id': uuidutils.generate_uuid()} |
| 253 | cls.lb_member_2_ipv6_subnet = {'id': uuidutils.generate_uuid()} |
Michael Johnson | 590fbe1 | 2019-07-03 14:30:01 -0700 | [diff] [blame] | 254 | cls.lb_member_vip_ipv6_subnet_stateful = True |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 255 | return |
| 256 | elif CONF.load_balancer.test_network_override: |
| 257 | if conf_lb.test_subnet_override: |
| 258 | override_subnet = show_subnet(conf_lb.test_subnet_override) |
| 259 | else: |
| 260 | override_subnet = None |
| 261 | |
| 262 | show_net = cls.lb_mem_net_client.show_network |
| 263 | override_network = show_net(conf_lb.test_network_override) |
| 264 | override_network = override_network.get('network') |
| 265 | |
| 266 | cls.lb_member_vip_net = override_network |
| 267 | cls.lb_member_vip_subnet = override_subnet |
| 268 | cls.lb_member_1_net = override_network |
| 269 | cls.lb_member_1_subnet = override_subnet |
| 270 | cls.lb_member_2_net = override_network |
| 271 | cls.lb_member_2_subnet = override_subnet |
| 272 | |
| 273 | if (CONF.load_balancer.test_with_ipv6 and |
Michael Polenchuk | 4beb66b | 2022-01-18 15:44:56 +0400 | [diff] [blame] | 274 | conf_lb.test_ipv6_subnet_override): |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 275 | override_ipv6_subnet = show_subnet( |
Michael Polenchuk | 4beb66b | 2022-01-18 15:44:56 +0400 | [diff] [blame] | 276 | conf_lb.test_ipv6_subnet_override) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 277 | cls.lb_member_vip_ipv6_subnet = override_ipv6_subnet |
| 278 | cls.lb_member_1_ipv6_subnet = override_ipv6_subnet |
| 279 | cls.lb_member_2_ipv6_subnet = override_ipv6_subnet |
Michael Johnson | 590fbe1 | 2019-07-03 14:30:01 -0700 | [diff] [blame] | 280 | cls.lb_member_vip_ipv6_subnet_stateful = False |
| 281 | if (override_ipv6_subnet[0]['ipv6_address_mode'] == |
| 282 | 'dhcpv6-stateful'): |
| 283 | cls.lb_member_vip_ipv6_subnet_stateful = True |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 284 | else: |
| 285 | cls.lb_member_vip_ipv6_subnet = None |
| 286 | cls.lb_member_1_ipv6_subnet = None |
| 287 | cls.lb_member_2_ipv6_subnet = None |
| 288 | else: |
| 289 | cls._create_networks() |
| 290 | |
| 291 | LOG.debug('Octavia Setup: lb_member_vip_net = {}'.format( |
| 292 | cls.lb_member_vip_net[const.ID])) |
| 293 | if cls.lb_member_vip_subnet: |
| 294 | LOG.debug('Octavia Setup: lb_member_vip_subnet = {}'.format( |
| 295 | cls.lb_member_vip_subnet[const.ID])) |
| 296 | LOG.debug('Octavia Setup: lb_member_1_net = {}'.format( |
| 297 | cls.lb_member_1_net[const.ID])) |
| 298 | if cls.lb_member_1_subnet: |
| 299 | LOG.debug('Octavia Setup: lb_member_1_subnet = {}'.format( |
| 300 | cls.lb_member_1_subnet[const.ID])) |
| 301 | LOG.debug('Octavia Setup: lb_member_2_net = {}'.format( |
| 302 | cls.lb_member_2_net[const.ID])) |
| 303 | if cls.lb_member_2_subnet: |
| 304 | LOG.debug('Octavia Setup: lb_member_2_subnet = {}'.format( |
| 305 | cls.lb_member_2_subnet[const.ID])) |
Michael Johnson | 124ba8b | 2018-08-30 16:06:05 -0700 | [diff] [blame] | 306 | if CONF.load_balancer.test_with_ipv6: |
| 307 | if cls.lb_member_vip_ipv6_subnet: |
| 308 | LOG.debug('Octavia Setup: lb_member_vip_ipv6_subnet = ' |
| 309 | '{}'.format(cls.lb_member_vip_ipv6_subnet[const.ID])) |
| 310 | if cls.lb_member_1_ipv6_subnet: |
| 311 | LOG.debug('Octavia Setup: lb_member_1_ipv6_subnet = {}'.format( |
| 312 | cls.lb_member_1_ipv6_subnet[const.ID])) |
| 313 | if cls.lb_member_2_ipv6_subnet: |
| 314 | LOG.debug('Octavia Setup: lb_member_2_ipv6_subnet = {}'.format( |
| 315 | cls.lb_member_2_ipv6_subnet[const.ID])) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 316 | |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 317 | @classmethod |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 318 | # Neutron can be slow to clean up ports from the subnets/networks. |
| 319 | # Retry this delete a few times if we get a "Conflict" error to give |
| 320 | # neutron time to fully cleanup the ports. |
| 321 | @tenacity.retry( |
| 322 | retry=tenacity.retry_if_exception_type(exceptions.Conflict), |
| 323 | wait=tenacity.wait_incrementing( |
Vasyl Saienko | 0d5a4f4 | 2021-05-12 16:30:26 +0300 | [diff] [blame] | 324 | const.RETRY_INITIAL_DELAY, const.RETRY_BACKOFF, const.RETRY_MAX), |
| 325 | stop=tenacity.stop_after_attempt(const.RETRY_ATTEMPTS)) |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 326 | def _logging_delete_network(cls, net_id): |
| 327 | try: |
| 328 | cls.lb_mem_net_client.delete_network(net_id) |
| 329 | except Exception: |
| 330 | LOG.error('Unable to delete network {}. Active ports:'.format( |
| 331 | net_id)) |
| 332 | LOG.error(cls.lb_mem_ports_client.list_ports()) |
| 333 | raise |
| 334 | |
| 335 | @classmethod |
| 336 | # Neutron can be slow to clean up ports from the subnets/networks. |
| 337 | # Retry this delete a few times if we get a "Conflict" error to give |
| 338 | # neutron time to fully cleanup the ports. |
| 339 | @tenacity.retry( |
| 340 | retry=tenacity.retry_if_exception_type(exceptions.Conflict), |
| 341 | wait=tenacity.wait_incrementing( |
Vasyl Saienko | 0d5a4f4 | 2021-05-12 16:30:26 +0300 | [diff] [blame] | 342 | const.RETRY_INITIAL_DELAY, const.RETRY_BACKOFF, const.RETRY_MAX), |
| 343 | stop=tenacity.stop_after_attempt(const.RETRY_ATTEMPTS)) |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 344 | def _logging_delete_subnet(cls, subnet_id): |
| 345 | try: |
| 346 | cls.lb_mem_subnet_client.delete_subnet(subnet_id) |
| 347 | except Exception: |
| 348 | LOG.error('Unable to delete subnet {}. Active ports:'.format( |
| 349 | subnet_id)) |
| 350 | LOG.error(cls.lb_mem_ports_client.list_ports()) |
| 351 | raise |
| 352 | |
| 353 | @classmethod |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 354 | def _create_networks(cls): |
| 355 | """Creates networks, subnets, and routers used in tests. |
| 356 | |
| 357 | The following are expected to be defined and available to the tests: |
| 358 | cls.lb_member_vip_net |
| 359 | cls.lb_member_vip_subnet |
| 360 | cls.lb_member_vip_ipv6_subnet (optional) |
| 361 | cls.lb_member_1_net |
| 362 | cls.lb_member_1_subnet |
| 363 | cls.lb_member_1_ipv6_subnet (optional) |
| 364 | cls.lb_member_2_net |
| 365 | cls.lb_member_2_subnet |
| 366 | cls.lb_member_2_ipv6_subnet (optional) |
| 367 | """ |
| 368 | |
| 369 | # Create tenant VIP network |
| 370 | network_kwargs = { |
| 371 | 'name': data_utils.rand_name("lb_member_vip_network")} |
| 372 | if CONF.network_feature_enabled.port_security: |
Andreas Jaeger | 4215b70 | 2020-03-28 20:13:46 +0100 | [diff] [blame] | 373 | # Note: Allowed Address Pairs requires port security |
| 374 | network_kwargs['port_security_enabled'] = True |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 375 | result = cls.lb_mem_net_client.create_network(**network_kwargs) |
| 376 | cls.lb_member_vip_net = result['network'] |
| 377 | LOG.info('lb_member_vip_net: {}'.format(cls.lb_member_vip_net)) |
| 378 | cls.addClassResourceCleanup( |
| 379 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 380 | cls._logging_delete_network, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 381 | cls.lb_mem_net_client.show_network, |
| 382 | cls.lb_member_vip_net['id']) |
| 383 | |
| 384 | # Create tenant VIP subnet |
| 385 | subnet_kwargs = { |
| 386 | 'name': data_utils.rand_name("lb_member_vip_subnet"), |
| 387 | 'network_id': cls.lb_member_vip_net['id'], |
| 388 | 'cidr': CONF.load_balancer.vip_subnet_cidr, |
| 389 | 'ip_version': 4} |
| 390 | result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs) |
| 391 | cls.lb_member_vip_subnet = result['subnet'] |
| 392 | LOG.info('lb_member_vip_subnet: {}'.format(cls.lb_member_vip_subnet)) |
| 393 | cls.addClassResourceCleanup( |
| 394 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 395 | cls._logging_delete_subnet, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 396 | cls.lb_mem_subnet_client.show_subnet, |
| 397 | cls.lb_member_vip_subnet['id']) |
| 398 | |
| 399 | # Create tenant VIP IPv6 subnet |
| 400 | if CONF.load_balancer.test_with_ipv6: |
Michael Johnson | 590fbe1 | 2019-07-03 14:30:01 -0700 | [diff] [blame] | 401 | cls.lb_member_vip_ipv6_subnet_stateful = False |
Gregory Thiemonge | 54225ad | 2021-02-04 15:25:17 +0100 | [diff] [blame] | 402 | cls.lb_member_vip_ipv6_subnet_use_subnetpool = False |
| 403 | subnet_kwargs = { |
| 404 | 'name': data_utils.rand_name("lb_member_vip_ipv6_subnet"), |
| 405 | 'network_id': cls.lb_member_vip_net['id'], |
| 406 | 'ip_version': 6} |
| 407 | |
| 408 | # Use a CIDR from devstack's default IPv6 subnetpool if it exists, |
| 409 | # the subnetpool's cidr is routable from the devstack node |
| 410 | # through the default router |
| 411 | subnetpool_name = CONF.load_balancer.default_ipv6_subnetpool |
| 412 | if subnetpool_name: |
| 413 | subnetpool = cls.os_admin_subnetpools_client.list_subnetpools( |
| 414 | name=subnetpool_name)['subnetpools'] |
| 415 | if len(subnetpool) == 1: |
| 416 | subnetpool = subnetpool[0] |
| 417 | subnet_kwargs['subnetpool_id'] = subnetpool['id'] |
| 418 | cls.lb_member_vip_ipv6_subnet_use_subnetpool = True |
| 419 | |
| 420 | if 'subnetpool_id' not in subnet_kwargs: |
| 421 | subnet_kwargs['cidr'] = ( |
| 422 | CONF.load_balancer.vip_ipv6_subnet_cidr) |
| 423 | |
| 424 | result = cls.lb_mem_subnet_client.create_subnet( |
| 425 | **subnet_kwargs) |
| 426 | cls.lb_member_vip_ipv6_net = cls.lb_member_vip_net |
| 427 | cls.lb_member_vip_ipv6_subnet = result['subnet'] |
| 428 | cls.addClassResourceCleanup( |
| 429 | waiters.wait_for_not_found, |
| 430 | cls._logging_delete_subnet, |
| 431 | cls.lb_mem_subnet_client.show_subnet, |
| 432 | cls.lb_member_vip_ipv6_subnet['id']) |
Carlos Goncalves | 84af48c | 2019-07-25 15:51:30 +0200 | [diff] [blame] | 433 | |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 434 | LOG.info('lb_member_vip_ipv6_subnet: {}'.format( |
| 435 | cls.lb_member_vip_ipv6_subnet)) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 436 | |
| 437 | # Create tenant member 1 network |
| 438 | network_kwargs = { |
| 439 | 'name': data_utils.rand_name("lb_member_1_network")} |
| 440 | if CONF.network_feature_enabled.port_security: |
| 441 | if CONF.load_balancer.enable_security_groups: |
| 442 | network_kwargs['port_security_enabled'] = True |
| 443 | else: |
| 444 | network_kwargs['port_security_enabled'] = False |
| 445 | result = cls.lb_mem_net_client.create_network(**network_kwargs) |
| 446 | cls.lb_member_1_net = result['network'] |
| 447 | LOG.info('lb_member_1_net: {}'.format(cls.lb_member_1_net)) |
| 448 | cls.addClassResourceCleanup( |
| 449 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 450 | cls._logging_delete_network, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 451 | cls.lb_mem_net_client.show_network, |
| 452 | cls.lb_member_1_net['id']) |
| 453 | |
| 454 | # Create tenant member 1 subnet |
| 455 | subnet_kwargs = { |
| 456 | 'name': data_utils.rand_name("lb_member_1_subnet"), |
| 457 | 'network_id': cls.lb_member_1_net['id'], |
| 458 | 'cidr': CONF.load_balancer.member_1_ipv4_subnet_cidr, |
| 459 | 'ip_version': 4} |
| 460 | result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs) |
| 461 | cls.lb_member_1_subnet = result['subnet'] |
| 462 | LOG.info('lb_member_1_subnet: {}'.format(cls.lb_member_1_subnet)) |
| 463 | cls.addClassResourceCleanup( |
| 464 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 465 | cls._logging_delete_subnet, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 466 | cls.lb_mem_subnet_client.show_subnet, |
| 467 | cls.lb_member_1_subnet['id']) |
| 468 | |
| 469 | # Create tenant member 1 ipv6 subnet |
| 470 | if CONF.load_balancer.test_with_ipv6: |
| 471 | subnet_kwargs = { |
| 472 | 'name': data_utils.rand_name("lb_member_1_ipv6_subnet"), |
| 473 | 'network_id': cls.lb_member_1_net['id'], |
| 474 | 'cidr': CONF.load_balancer.member_1_ipv6_subnet_cidr, |
| 475 | 'ip_version': 6} |
| 476 | result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs) |
Michael Johnson | bf916df | 2018-10-17 10:59:28 -0700 | [diff] [blame] | 477 | cls.lb_member_1_subnet_prefix = ( |
| 478 | CONF.load_balancer.member_1_ipv6_subnet_cidr.rpartition('/')[2] |
| 479 | ) |
| 480 | assert(cls.lb_member_1_subnet_prefix.isdigit()) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 481 | cls.lb_member_1_ipv6_subnet = result['subnet'] |
| 482 | LOG.info('lb_member_1_ipv6_subnet: {}'.format( |
| 483 | cls.lb_member_1_ipv6_subnet)) |
| 484 | cls.addClassResourceCleanup( |
| 485 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 486 | cls._logging_delete_subnet, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 487 | cls.lb_mem_subnet_client.show_subnet, |
| 488 | cls.lb_member_1_ipv6_subnet['id']) |
| 489 | |
| 490 | # Create tenant member 2 network |
| 491 | network_kwargs = { |
| 492 | 'name': data_utils.rand_name("lb_member_2_network")} |
| 493 | if CONF.network_feature_enabled.port_security: |
| 494 | if CONF.load_balancer.enable_security_groups: |
| 495 | network_kwargs['port_security_enabled'] = True |
| 496 | else: |
| 497 | network_kwargs['port_security_enabled'] = False |
| 498 | result = cls.lb_mem_net_client.create_network(**network_kwargs) |
| 499 | cls.lb_member_2_net = result['network'] |
| 500 | LOG.info('lb_member_2_net: {}'.format(cls.lb_member_2_net)) |
| 501 | cls.addClassResourceCleanup( |
| 502 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 503 | cls._logging_delete_network, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 504 | cls.lb_mem_net_client.show_network, |
| 505 | cls.lb_member_2_net['id']) |
| 506 | |
| 507 | # Create tenant member 2 subnet |
| 508 | subnet_kwargs = { |
| 509 | 'name': data_utils.rand_name("lb_member_2_subnet"), |
| 510 | 'network_id': cls.lb_member_2_net['id'], |
| 511 | 'cidr': CONF.load_balancer.member_2_ipv4_subnet_cidr, |
| 512 | 'ip_version': 4} |
| 513 | result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs) |
| 514 | cls.lb_member_2_subnet = result['subnet'] |
| 515 | LOG.info('lb_member_2_subnet: {}'.format(cls.lb_member_2_subnet)) |
| 516 | cls.addClassResourceCleanup( |
| 517 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 518 | cls._logging_delete_subnet, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 519 | cls.lb_mem_subnet_client.show_subnet, |
| 520 | cls.lb_member_2_subnet['id']) |
| 521 | |
| 522 | # Create tenant member 2 ipv6 subnet |
| 523 | if CONF.load_balancer.test_with_ipv6: |
| 524 | subnet_kwargs = { |
| 525 | 'name': data_utils.rand_name("lb_member_2_ipv6_subnet"), |
| 526 | 'network_id': cls.lb_member_2_net['id'], |
| 527 | 'cidr': CONF.load_balancer.member_2_ipv6_subnet_cidr, |
| 528 | 'ip_version': 6} |
| 529 | result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs) |
Michael Johnson | bf916df | 2018-10-17 10:59:28 -0700 | [diff] [blame] | 530 | cls.lb_member_2_subnet_prefix = ( |
| 531 | CONF.load_balancer.member_2_ipv6_subnet_cidr.rpartition('/')[2] |
| 532 | ) |
| 533 | assert(cls.lb_member_2_subnet_prefix.isdigit()) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 534 | cls.lb_member_2_ipv6_subnet = result['subnet'] |
| 535 | LOG.info('lb_member_2_ipv6_subnet: {}'.format( |
| 536 | cls.lb_member_2_ipv6_subnet)) |
| 537 | cls.addClassResourceCleanup( |
| 538 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 539 | cls._logging_delete_subnet, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 540 | cls.lb_mem_subnet_client.show_subnet, |
| 541 | cls.lb_member_2_ipv6_subnet['id']) |
| 542 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 543 | @classmethod |
Michael Johnson | 07c9a63 | 2018-06-07 13:27:42 -0700 | [diff] [blame] | 544 | def _setup_lb_network_kwargs(cls, lb_kwargs, ip_version=None, |
| 545 | use_fixed_ip=False): |
Adam Harwell | 60ed9d9 | 2018-05-10 13:23:13 -0700 | [diff] [blame] | 546 | if not ip_version: |
| 547 | ip_version = 6 if CONF.load_balancer.test_with_ipv6 else 4 |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 548 | if cls.lb_member_vip_subnet or cls.lb_member_vip_ipv6_subnet: |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 549 | ip_index = data_utils.rand_int_id(start=10, end=100) |
Michael Johnson | dfd818a | 2018-08-21 20:54:54 -0700 | [diff] [blame] | 550 | while ip_index in cls.used_ips: |
| 551 | ip_index = data_utils.rand_int_id(start=10, end=100) |
| 552 | cls.used_ips.append(ip_index) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 553 | if ip_version == 4: |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 554 | subnet_id = cls.lb_member_vip_subnet[const.ID] |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 555 | if CONF.load_balancer.test_with_noop: |
| 556 | lb_vip_address = '198.18.33.33' |
| 557 | else: |
| 558 | subnet = cls.os_admin.subnets_client.show_subnet(subnet_id) |
| 559 | network = ipaddress.IPv4Network(subnet['subnet']['cidr']) |
| 560 | lb_vip_address = str(network[ip_index]) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 561 | else: |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 562 | subnet_id = cls.lb_member_vip_ipv6_subnet[const.ID] |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 563 | if CONF.load_balancer.test_with_noop: |
| 564 | lb_vip_address = '2001:db8:33:33:33:33:33:33' |
| 565 | else: |
| 566 | subnet = cls.os_admin.subnets_client.show_subnet(subnet_id) |
| 567 | network = ipaddress.IPv6Network(subnet['subnet']['cidr']) |
| 568 | lb_vip_address = str(network[ip_index]) |
Michael Johnson | 590fbe1 | 2019-07-03 14:30:01 -0700 | [diff] [blame] | 569 | # If the subnet is IPv6 slaac or dhcpv6-stateless |
| 570 | # neutron does not allow a fixed IP |
| 571 | if not cls.lb_member_vip_ipv6_subnet_stateful: |
| 572 | use_fixed_ip = False |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 573 | lb_kwargs[const.VIP_SUBNET_ID] = subnet_id |
Michael Johnson | 07c9a63 | 2018-06-07 13:27:42 -0700 | [diff] [blame] | 574 | if use_fixed_ip: |
| 575 | lb_kwargs[const.VIP_ADDRESS] = lb_vip_address |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 576 | if CONF.load_balancer.test_with_noop: |
| 577 | lb_kwargs[const.VIP_NETWORK_ID] = ( |
| 578 | cls.lb_member_vip_net[const.ID]) |
Carlos Goncalves | bb23855 | 2020-01-15 10:10:55 +0000 | [diff] [blame] | 579 | if ip_version == 6: |
| 580 | lb_kwargs[const.VIP_ADDRESS] = lb_vip_address |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 581 | else: |
| 582 | lb_kwargs[const.VIP_NETWORK_ID] = cls.lb_member_vip_net[const.ID] |
| 583 | lb_kwargs[const.VIP_SUBNET_ID] = None |
| 584 | |
Gregory Thiemonge | ece5ab4 | 2020-10-29 08:46:05 +0100 | [diff] [blame] | 585 | def _validate_listener_protocol(self, protocol, raise_if_unsupported=True): |
| 586 | if (protocol == const.SCTP and |
| 587 | not self.mem_listener_client.is_version_supported( |
| 588 | self.api_version, '2.23')): |
| 589 | if raise_if_unsupported: |
| 590 | raise self.skipException('SCTP listener protocol ' |
| 591 | 'is only available on Octavia ' |
| 592 | 'API version 2.23 or newer.') |
| 593 | return False |
| 594 | return True |
| 595 | |
ibumarskov | c506392 | 2020-09-03 18:21:29 +0400 | [diff] [blame] | 596 | @classmethod |
| 597 | def check_tf_compatibility(cls, protocol=None, algorithm=None): |
| 598 | # TungstenFabric supported protocols and algorithms |
Ilya Bumarskov | 2b40629 | 2021-02-03 16:16:42 +0400 | [diff] [blame^] | 599 | tf_protocols = [const.HTTP, const.HTTPS, const.TCP, |
ibumarskov | c506392 | 2020-09-03 18:21:29 +0400 | [diff] [blame] | 600 | const.TERMINATED_HTTPS] |
| 601 | tf_algorithms = [const.LB_ALGORITHM_ROUND_ROBIN, |
| 602 | const.LB_ALGORITHM_LEAST_CONNECTIONS, |
| 603 | const.LB_ALGORITHM_SOURCE_IP] |
| 604 | |
| 605 | if algorithm and algorithm not in tf_algorithms: |
| 606 | raise cls.skipException( |
| 607 | 'TungstenFabric does not support {} algorithm.' |
| 608 | ''.format(algorithm)) |
| 609 | if protocol and protocol not in tf_protocols: |
| 610 | raise cls.skipException( |
| 611 | 'TungstenFabric does not support {} protocol.' |
| 612 | ''.format(protocol)) |
| 613 | |
| 614 | @classmethod |
| 615 | def _tf_create_listener(cls, name, proto, port, lb_id): |
| 616 | listener_kwargs = { |
| 617 | const.NAME: name, |
| 618 | const.PROTOCOL: proto, |
| 619 | const.PROTOCOL_PORT: port, |
| 620 | const.LOADBALANCER_ID: lb_id, |
| 621 | } |
| 622 | listener = cls.mem_listener_client.create_listener(**listener_kwargs) |
| 623 | return listener |
| 624 | |
| 625 | @classmethod |
| 626 | def _tf_get_free_port(cls, lb_id): |
| 627 | port = 8081 |
| 628 | lb = cls.mem_lb_client.show_loadbalancer(lb_id) |
| 629 | listeners = lb[const.LISTENERS] |
| 630 | if not listeners: |
| 631 | return port |
| 632 | ports = [cls.mem_listener_client.show_listener(x[const.ID])[ |
| 633 | const.PROTOCOL_PORT] for x in listeners] |
| 634 | while port in ports: |
| 635 | port = port + 1 |
| 636 | return port |
| 637 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 638 | |
| 639 | class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest): |
| 640 | @classmethod |
Gregory Thiemonge | b0da4f3 | 2022-02-04 08:58:06 +0100 | [diff] [blame] | 641 | def remote_client_args(cls): |
| 642 | # In case we're using octavia-tempest-plugin with old tempest releases |
| 643 | # (for instance on stable/train) that don't support ssh_key_type, catch |
| 644 | # the exception and don't pass any argument |
| 645 | args = {} |
| 646 | try: |
| 647 | args['ssh_key_type'] = CONF.validation.ssh_key_type |
| 648 | except cfg.NoSuchOptError: |
| 649 | pass |
| 650 | return args |
| 651 | |
| 652 | @classmethod |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 653 | def resource_setup(cls): |
| 654 | super(LoadBalancerBaseTestWithCompute, cls).resource_setup() |
| 655 | # If validation is disabled in this cloud, we won't be able to |
| 656 | # start the webservers, so don't even boot them. |
| 657 | if not CONF.validation.run_validation: |
| 658 | return |
| 659 | |
| 660 | # Create a keypair for the webservers |
| 661 | keypair_name = data_utils.rand_name('lb_member_keypair') |
| 662 | result = cls.lb_mem_keypairs_client.create_keypair( |
| 663 | name=keypair_name) |
| 664 | cls.lb_member_keypair = result['keypair'] |
| 665 | LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair)) |
| 666 | cls.addClassResourceCleanup( |
| 667 | waiters.wait_for_not_found, |
| 668 | cls.lb_mem_keypairs_client.delete_keypair, |
| 669 | cls.lb_mem_keypairs_client.show_keypair, |
| 670 | keypair_name) |
| 671 | |
| 672 | if (CONF.load_balancer.enable_security_groups and |
| 673 | CONF.network_feature_enabled.port_security): |
| 674 | # Set up the security group for the webservers |
| 675 | SG_name = data_utils.rand_name('lb_member_SG') |
| 676 | cls.lb_member_sec_group = ( |
| 677 | cls.lb_mem_SG_client.create_security_group( |
| 678 | name=SG_name)['security_group']) |
| 679 | cls.addClassResourceCleanup( |
| 680 | waiters.wait_for_not_found, |
| 681 | cls.lb_mem_SG_client.delete_security_group, |
| 682 | cls.lb_mem_SG_client.show_security_group, |
| 683 | cls.lb_member_sec_group['id']) |
| 684 | |
| 685 | # Create a security group rule to allow 80-81 (test webservers) |
| 686 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 687 | direction='ingress', |
| 688 | security_group_id=cls.lb_member_sec_group['id'], |
| 689 | protocol='tcp', |
| 690 | ethertype='IPv4', |
| 691 | port_range_min=80, |
| 692 | port_range_max=81)['security_group_rule'] |
| 693 | cls.addClassResourceCleanup( |
| 694 | waiters.wait_for_not_found, |
| 695 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 696 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 697 | SGr['id']) |
Gregory Thiemonge | 29d1790 | 2019-04-30 15:06:17 +0200 | [diff] [blame] | 698 | # Create a security group rule to allow UDP 80-81 (test webservers) |
| 699 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 700 | direction='ingress', |
| 701 | security_group_id=cls.lb_member_sec_group['id'], |
| 702 | protocol='udp', |
| 703 | ethertype='IPv4', |
| 704 | port_range_min=80, |
| 705 | port_range_max=81)['security_group_rule'] |
| 706 | cls.addClassResourceCleanup( |
| 707 | waiters.wait_for_not_found, |
| 708 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 709 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 710 | SGr['id']) |
Michael Johnson | 74b6f2f | 2020-10-29 15:11:39 -0700 | [diff] [blame] | 711 | # Create a security group rule to allow 443 (test webservers) |
| 712 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 713 | direction='ingress', |
| 714 | security_group_id=cls.lb_member_sec_group['id'], |
| 715 | protocol='tcp', |
| 716 | ethertype='IPv4', |
| 717 | port_range_min=443, |
| 718 | port_range_max=443)['security_group_rule'] |
| 719 | cls.addClassResourceCleanup( |
| 720 | waiters.wait_for_not_found, |
| 721 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 722 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 723 | SGr['id']) |
Michael Johnson | 031ecca | 2020-10-29 16:45:32 -0700 | [diff] [blame] | 724 | # Create a security group rule to allow 9443 (test webservers) |
| 725 | # Used in the pool backend encryption client authentication tests |
| 726 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 727 | direction='ingress', |
| 728 | security_group_id=cls.lb_member_sec_group['id'], |
| 729 | protocol='tcp', |
| 730 | ethertype='IPv4', |
| 731 | port_range_min=9443, |
| 732 | port_range_max=9443)['security_group_rule'] |
| 733 | cls.addClassResourceCleanup( |
| 734 | waiters.wait_for_not_found, |
| 735 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 736 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 737 | SGr['id']) |
Gregory Thiemonge | 29d1790 | 2019-04-30 15:06:17 +0200 | [diff] [blame] | 738 | # Create a security group rule to allow UDP 9999 (test webservers) |
| 739 | # Port 9999 is used to illustrate health monitor ERRORs on closed |
| 740 | # ports. |
| 741 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 742 | direction='ingress', |
| 743 | security_group_id=cls.lb_member_sec_group['id'], |
| 744 | protocol='udp', |
| 745 | ethertype='IPv4', |
| 746 | port_range_min=9999, |
| 747 | port_range_max=9999)['security_group_rule'] |
| 748 | cls.addClassResourceCleanup( |
| 749 | waiters.wait_for_not_found, |
| 750 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 751 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 752 | SGr['id']) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 753 | # Create a security group rule to allow 22 (ssh) |
| 754 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 755 | direction='ingress', |
| 756 | security_group_id=cls.lb_member_sec_group['id'], |
| 757 | protocol='tcp', |
| 758 | ethertype='IPv4', |
| 759 | port_range_min=22, |
| 760 | port_range_max=22)['security_group_rule'] |
| 761 | cls.addClassResourceCleanup( |
| 762 | waiters.wait_for_not_found, |
| 763 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 764 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 765 | SGr['id']) |
| 766 | if CONF.load_balancer.test_with_ipv6: |
| 767 | # Create a security group rule to allow 80-81 (test webservers) |
| 768 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 769 | direction='ingress', |
| 770 | security_group_id=cls.lb_member_sec_group['id'], |
| 771 | protocol='tcp', |
| 772 | ethertype='IPv6', |
| 773 | port_range_min=80, |
| 774 | port_range_max=81)['security_group_rule'] |
| 775 | cls.addClassResourceCleanup( |
| 776 | waiters.wait_for_not_found, |
| 777 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 778 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 779 | SGr['id']) |
Gregory Thiemonge | 29d1790 | 2019-04-30 15:06:17 +0200 | [diff] [blame] | 780 | # Create a security group rule to allow UDP 80-81 (test |
| 781 | # webservers) |
| 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='udp', |
| 786 | ethertype='IPv6', |
| 787 | port_range_min=80, |
| 788 | port_range_max=81)['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']) |
Michael Johnson | 74b6f2f | 2020-10-29 15:11:39 -0700 | [diff] [blame] | 794 | # Create a security group rule to allow 443 (test webservers) |
| 795 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 796 | direction='ingress', |
| 797 | security_group_id=cls.lb_member_sec_group['id'], |
| 798 | protocol='tcp', |
| 799 | ethertype='IPv6', |
| 800 | port_range_min=443, |
| 801 | port_range_max=443)['security_group_rule'] |
| 802 | cls.addClassResourceCleanup( |
| 803 | waiters.wait_for_not_found, |
| 804 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 805 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 806 | SGr['id']) |
Michael Johnson | 031ecca | 2020-10-29 16:45:32 -0700 | [diff] [blame] | 807 | # Create a security group rule to allow 9443 (test webservers) |
| 808 | # Used in the pool encryption client authentication tests |
| 809 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 810 | direction='ingress', |
| 811 | security_group_id=cls.lb_member_sec_group['id'], |
| 812 | protocol='tcp', |
| 813 | ethertype='IPv6', |
| 814 | port_range_min=9443, |
| 815 | port_range_max=9443)['security_group_rule'] |
| 816 | cls.addClassResourceCleanup( |
| 817 | waiters.wait_for_not_found, |
| 818 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 819 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 820 | SGr['id']) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 821 | # Create a security group rule to allow 22 (ssh) |
| 822 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 823 | direction='ingress', |
| 824 | security_group_id=cls.lb_member_sec_group['id'], |
| 825 | protocol='tcp', |
| 826 | ethertype='IPv6', |
| 827 | port_range_min=22, |
| 828 | port_range_max=22)['security_group_rule'] |
| 829 | cls.addClassResourceCleanup( |
| 830 | waiters.wait_for_not_found, |
| 831 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 832 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 833 | SGr['id']) |
| 834 | |
| 835 | LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group)) |
| 836 | |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 837 | # Setup backend member reencryption PKI |
| 838 | cls._create_backend_reencryption_pki() |
| 839 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 840 | # Create webserver 1 instance |
| 841 | server_details = cls._create_webserver('lb_member_webserver1', |
| 842 | cls.lb_member_1_net) |
| 843 | |
| 844 | cls.lb_member_webserver1 = server_details['server'] |
| 845 | cls.webserver1_ip = server_details.get('ipv4_address') |
| 846 | cls.webserver1_ipv6 = server_details.get('ipv6_address') |
| 847 | cls.webserver1_public_ip = server_details['public_ipv4_address'] |
| 848 | |
| 849 | LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format( |
| 850 | cls.lb_member_webserver1[const.ID])) |
| 851 | LOG.debug('Octavia Setup: webserver1_ip = {}'.format( |
| 852 | cls.webserver1_ip)) |
| 853 | LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format( |
| 854 | cls.webserver1_ipv6)) |
| 855 | LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format( |
| 856 | cls.webserver1_public_ip)) |
| 857 | |
| 858 | # Create webserver 2 instance |
| 859 | server_details = cls._create_webserver('lb_member_webserver2', |
| 860 | cls.lb_member_2_net) |
| 861 | |
| 862 | cls.lb_member_webserver2 = server_details['server'] |
| 863 | cls.webserver2_ip = server_details.get('ipv4_address') |
| 864 | cls.webserver2_ipv6 = server_details.get('ipv6_address') |
| 865 | cls.webserver2_public_ip = server_details['public_ipv4_address'] |
| 866 | |
| 867 | LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format( |
| 868 | cls.lb_member_webserver2[const.ID])) |
| 869 | LOG.debug('Octavia Setup: webserver2_ip = {}'.format( |
| 870 | cls.webserver2_ip)) |
| 871 | LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format( |
| 872 | cls.webserver2_ipv6)) |
| 873 | LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format( |
| 874 | cls.webserver2_public_ip)) |
| 875 | |
Michael Johnson | bf916df | 2018-10-17 10:59:28 -0700 | [diff] [blame] | 876 | if CONF.load_balancer.test_with_ipv6: |
| 877 | # Enable the IPv6 nic in webserver 1 |
| 878 | cls._enable_ipv6_nic_webserver( |
| 879 | cls.webserver1_public_ip, cls.lb_member_keypair['private_key'], |
| 880 | cls.webserver1_ipv6, cls.lb_member_1_subnet_prefix) |
| 881 | |
| 882 | # Enable the IPv6 nic in webserver 2 |
| 883 | cls._enable_ipv6_nic_webserver( |
| 884 | cls.webserver2_public_ip, cls.lb_member_keypair['private_key'], |
| 885 | cls.webserver2_ipv6, cls.lb_member_2_subnet_prefix) |
| 886 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 887 | # Set up serving on webserver 1 |
| 888 | cls._install_start_webserver(cls.webserver1_public_ip, |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 889 | cls.lb_member_keypair['private_key'], |
| 890 | cls.webserver1_response) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 891 | |
| 892 | # Validate webserver 1 |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 893 | cls._validate_webserver(cls.webserver1_public_ip, |
| 894 | cls.webserver1_response) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 895 | |
Gregory Thiemonge | 29d1790 | 2019-04-30 15:06:17 +0200 | [diff] [blame] | 896 | # Validate udp server 1 |
| 897 | cls._validate_udp_server(cls.webserver1_public_ip, |
| 898 | cls.webserver1_response) |
| 899 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 900 | # Set up serving on webserver 2 |
| 901 | cls._install_start_webserver(cls.webserver2_public_ip, |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 902 | cls.lb_member_keypair['private_key'], |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 903 | cls.webserver2_response, revoke_cert=True) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 904 | |
| 905 | # Validate webserver 2 |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 906 | cls._validate_webserver(cls.webserver2_public_ip, |
| 907 | cls.webserver2_response) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 908 | |
Gregory Thiemonge | 29d1790 | 2019-04-30 15:06:17 +0200 | [diff] [blame] | 909 | # Validate udp server 2 |
| 910 | cls._validate_udp_server(cls.webserver2_public_ip, |
| 911 | cls.webserver2_response) |
| 912 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 913 | @classmethod |
| 914 | def _create_networks(cls): |
| 915 | super(LoadBalancerBaseTestWithCompute, cls)._create_networks() |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 916 | # Create a router for the subnets (required for the floating IP) |
| 917 | router_name = data_utils.rand_name("lb_member_router") |
| 918 | result = cls.lb_mem_routers_client.create_router( |
| 919 | name=router_name, admin_state_up=True, |
| 920 | external_gateway_info=dict( |
| 921 | network_id=CONF.network.public_network_id)) |
| 922 | cls.lb_member_router = result['router'] |
| 923 | LOG.info('lb_member_router: {}'.format(cls.lb_member_router)) |
| 924 | cls.addClassResourceCleanup( |
| 925 | waiters.wait_for_not_found, |
| 926 | cls.lb_mem_routers_client.delete_router, |
| 927 | cls.lb_mem_routers_client.show_router, |
| 928 | cls.lb_member_router['id']) |
| 929 | |
| 930 | # Add VIP subnet to router |
| 931 | cls.lb_mem_routers_client.add_router_interface( |
| 932 | cls.lb_member_router['id'], |
| 933 | subnet_id=cls.lb_member_vip_subnet['id']) |
| 934 | cls.addClassResourceCleanup( |
| 935 | waiters.wait_for_not_found, |
| 936 | cls.lb_mem_routers_client.remove_router_interface, |
| 937 | cls.lb_mem_routers_client.remove_router_interface, |
| 938 | cls.lb_member_router['id'], |
| 939 | subnet_id=cls.lb_member_vip_subnet['id']) |
| 940 | |
Gregory Thiemonge | 54225ad | 2021-02-04 15:25:17 +0100 | [diff] [blame] | 941 | if (CONF.load_balancer.test_with_ipv6 and |
| 942 | CONF.load_balancer.default_router and |
| 943 | cls.lb_member_vip_ipv6_subnet_use_subnetpool): |
| 944 | |
| 945 | router_name = CONF.load_balancer.default_router |
| 946 | # if lb_member_vip_ipv6_subnet uses devstack's subnetpool, |
| 947 | # plug the subnet into the default router |
| 948 | router = cls.os_admin.routers_client.list_routers( |
| 949 | name=router_name)['routers'] |
| 950 | |
| 951 | if len(router) == 1: |
| 952 | router = router[0] |
| 953 | |
| 954 | # Add IPv6 VIP subnet to router1 |
| 955 | cls.os_admin_routers_client.add_router_interface( |
| 956 | router['id'], |
| 957 | subnet_id=cls.lb_member_vip_ipv6_subnet['id']) |
| 958 | cls.addClassResourceCleanup( |
| 959 | waiters.wait_for_not_found, |
| 960 | cls.os_admin_routers_client.remove_router_interface, |
| 961 | cls.os_admin_routers_client.remove_router_interface, |
| 962 | router['id'], |
| 963 | subnet_id=cls.lb_member_vip_ipv6_subnet['id']) |
| 964 | |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 965 | # Add member subnet 1 to router |
| 966 | cls.lb_mem_routers_client.add_router_interface( |
| 967 | cls.lb_member_router['id'], |
| 968 | subnet_id=cls.lb_member_1_subnet['id']) |
| 969 | cls.addClassResourceCleanup( |
| 970 | waiters.wait_for_not_found, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 971 | cls.lb_mem_routers_client.remove_router_interface, |
| 972 | cls.lb_mem_routers_client.remove_router_interface, |
| 973 | cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id']) |
| 974 | |
| 975 | # Add member subnet 2 to router |
| 976 | cls.lb_mem_routers_client.add_router_interface( |
| 977 | cls.lb_member_router['id'], |
| 978 | subnet_id=cls.lb_member_2_subnet['id']) |
| 979 | cls.addClassResourceCleanup( |
| 980 | waiters.wait_for_not_found, |
| 981 | cls.lb_mem_routers_client.remove_router_interface, |
| 982 | cls.lb_mem_routers_client.remove_router_interface, |
| 983 | cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id']) |
| 984 | |
| 985 | @classmethod |
| 986 | def _create_webserver(cls, name, network): |
| 987 | """Creates a webserver with two ports. |
| 988 | |
| 989 | webserver_details dictionary contains: |
| 990 | server - The compute server object |
| 991 | ipv4_address - The IPv4 address for the server (optional) |
| 992 | ipv6_address - The IPv6 address for the server (optional) |
| 993 | public_ipv4_address - The publicly accessible IPv4 address for the |
| 994 | server, this may be a floating IP (optional) |
| 995 | |
| 996 | :param name: The name of the server to create. |
| 997 | :param network: The network to boot the server on. |
| 998 | :returns: webserver_details dictionary. |
| 999 | """ |
| 1000 | server_kwargs = { |
| 1001 | 'name': data_utils.rand_name(name), |
| 1002 | 'flavorRef': CONF.compute.flavor_ref, |
| 1003 | 'imageRef': CONF.compute.image_ref, |
| 1004 | 'key_name': cls.lb_member_keypair['name']} |
| 1005 | if (CONF.load_balancer.enable_security_groups and |
| 1006 | CONF.network_feature_enabled.port_security): |
| 1007 | server_kwargs['security_groups'] = [ |
| 1008 | {'name': cls.lb_member_sec_group['name']}] |
| 1009 | if not CONF.load_balancer.disable_boot_network: |
| 1010 | server_kwargs['networks'] = [{'uuid': network['id']}] |
| 1011 | |
| 1012 | # Replace the name for clouds that have limitations |
| 1013 | if CONF.load_balancer.random_server_name_length: |
| 1014 | r = random.SystemRandom() |
| 1015 | server_kwargs['name'] = "m{}".format("".join( |
| 1016 | [r.choice(string.ascii_uppercase + string.digits) |
| 1017 | for _ in range( |
| 1018 | CONF.load_balancer.random_server_name_length - 1)] |
| 1019 | )) |
| 1020 | if CONF.load_balancer.availability_zone: |
| 1021 | server_kwargs['availability_zone'] = ( |
| 1022 | CONF.load_balancer.availability_zone) |
| 1023 | |
| 1024 | server = cls.lb_mem_servers_client.create_server( |
| 1025 | **server_kwargs)['server'] |
| 1026 | cls.addClassResourceCleanup( |
| 1027 | waiters.wait_for_not_found, |
| 1028 | cls.lb_mem_servers_client.delete_server, |
| 1029 | cls.lb_mem_servers_client.show_server, |
| 1030 | server['id']) |
| 1031 | server = waiters.wait_for_status( |
| 1032 | cls.lb_mem_servers_client.show_server, |
| 1033 | server['id'], 'status', 'ACTIVE', |
| 1034 | CONF.load_balancer.build_interval, |
| 1035 | CONF.load_balancer.build_timeout, |
| 1036 | root_tag='server') |
| 1037 | webserver_details = {'server': server} |
| 1038 | LOG.info('Created server: {}'.format(server)) |
| 1039 | |
| 1040 | addresses = server['addresses'] |
| 1041 | if CONF.load_balancer.disable_boot_network: |
| 1042 | instance_network = addresses.values()[0] |
| 1043 | else: |
| 1044 | instance_network = addresses[network['name']] |
| 1045 | for addr in instance_network: |
| 1046 | if addr['version'] == 4: |
| 1047 | webserver_details['ipv4_address'] = addr['addr'] |
| 1048 | if addr['version'] == 6: |
| 1049 | webserver_details['ipv6_address'] = addr['addr'] |
| 1050 | |
| 1051 | if CONF.validation.connect_method == 'floating': |
| 1052 | result = cls.lb_mem_ports_client.list_ports( |
| 1053 | network_id=network['id'], |
| 1054 | mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr']) |
| 1055 | port_id = result['ports'][0]['id'] |
| 1056 | result = cls.lb_mem_float_ip_client.create_floatingip( |
| 1057 | floating_network_id=CONF.network.public_network_id, |
| 1058 | port_id=port_id) |
| 1059 | floating_ip = result['floatingip'] |
| 1060 | LOG.info('webserver1_floating_ip: {}'.format(floating_ip)) |
| 1061 | cls.addClassResourceCleanup( |
| 1062 | waiters.wait_for_not_found, |
| 1063 | cls.lb_mem_float_ip_client.delete_floatingip, |
| 1064 | cls.lb_mem_float_ip_client.show_floatingip, |
| 1065 | floatingip_id=floating_ip['id']) |
| 1066 | webserver_details['public_ipv4_address'] = ( |
| 1067 | floating_ip['floating_ip_address']) |
| 1068 | else: |
| 1069 | webserver_details['public_ipv4_address'] = ( |
| 1070 | instance_network[0]['addr']) |
| 1071 | |
| 1072 | return webserver_details |
| 1073 | |
| 1074 | @classmethod |
Gregory Thiemonge | a2c234e | 2021-11-02 17:08:29 +0100 | [diff] [blame] | 1075 | def _get_openssh_version(cls): |
| 1076 | p = subprocess.Popen(["ssh", "-V"], |
| 1077 | stdout=subprocess.PIPE, |
| 1078 | stderr=subprocess.PIPE) |
| 1079 | output = p.communicate()[1] |
| 1080 | |
| 1081 | try: |
| 1082 | m = re.match(r"OpenSSH_(\d+)\.(\d+)", output.decode('utf-8')) |
| 1083 | version_maj = int(m.group(1)) |
| 1084 | version_min = int(m.group(2)) |
| 1085 | return version_maj, version_min |
| 1086 | except Exception: |
| 1087 | return None, None |
| 1088 | |
| 1089 | @classmethod |
| 1090 | def _need_scp_protocol(cls): |
| 1091 | # When using scp >= 8.7, force the use of the SCP protocol, |
| 1092 | # the new default (SFTP protocol) doesn't work with |
| 1093 | # cirros VMs. |
| 1094 | ssh_version = cls._get_openssh_version() |
| 1095 | LOG.debug("ssh_version = {}".format(ssh_version)) |
| 1096 | return (ssh_version[0] > 8 or |
| 1097 | (ssh_version[0] == 8 and ssh_version[1] >= 7)) |
| 1098 | |
| 1099 | @classmethod |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 1100 | def _install_start_webserver(cls, ip_address, ssh_key, start_id, |
| 1101 | revoke_cert=False): |
Michael Johnson | 2735735 | 2020-11-13 13:55:09 -0800 | [diff] [blame] | 1102 | local_file = CONF.load_balancer.test_server_path |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 1103 | |
| 1104 | linux_client = remote_client.RemoteClient( |
Ade Lee | d0ea406 | 2021-09-06 15:33:27 -0400 | [diff] [blame] | 1105 | ip_address, CONF.validation.image_ssh_user, pkey=ssh_key, |
Gregory Thiemonge | b0da4f3 | 2022-02-04 08:58:06 +0100 | [diff] [blame] | 1106 | **cls.remote_client_args()) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 1107 | linux_client.validate_authentication() |
| 1108 | |
| 1109 | with tempfile.NamedTemporaryFile() as key: |
| 1110 | key.write(ssh_key.encode('utf-8')) |
| 1111 | key.flush() |
Gregory Thiemonge | a2c234e | 2021-11-02 17:08:29 +0100 | [diff] [blame] | 1112 | ssh_extra_args = ( |
| 1113 | "-o PubkeyAcceptedKeyTypes=+ssh-rsa") |
| 1114 | if cls._need_scp_protocol(): |
| 1115 | ssh_extra_args += " -O" |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 1116 | cmd = ("scp -v -o UserKnownHostsFile=/dev/null " |
Gregory Thiemonge | a2c234e | 2021-11-02 17:08:29 +0100 | [diff] [blame] | 1117 | "{7} " |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 1118 | "-o StrictHostKeyChecking=no " |
| 1119 | "-o ConnectTimeout={0} -o ConnectionAttempts={1} " |
| 1120 | "-i {2} {3} {4}@{5}:{6}").format( |
| 1121 | CONF.load_balancer.scp_connection_timeout, |
| 1122 | CONF.load_balancer.scp_connection_attempts, |
| 1123 | key.name, local_file, CONF.validation.image_ssh_user, |
Gregory Thiemonge | a2c234e | 2021-11-02 17:08:29 +0100 | [diff] [blame] | 1124 | ip_address, const.TEST_SERVER_BINARY, |
| 1125 | ssh_extra_args) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 1126 | args = shlex.split(cmd) |
| 1127 | subprocess_args = {'stdout': subprocess.PIPE, |
| 1128 | 'stderr': subprocess.STDOUT, |
| 1129 | 'cwd': None} |
| 1130 | proc = subprocess.Popen(args, **subprocess_args) |
| 1131 | stdout, stderr = proc.communicate() |
| 1132 | if proc.returncode != 0: |
| 1133 | raise exceptions.CommandFailed(proc.returncode, cmd, |
| 1134 | stdout, stderr) |
Gregory Thiemonge | f72a886 | 2019-08-06 17:25:42 +0200 | [diff] [blame] | 1135 | |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 1136 | cls._load_member_pki_content(ip_address, key, |
| 1137 | revoke_cert=revoke_cert) |
| 1138 | |
Gregory Thiemonge | f72a886 | 2019-08-06 17:25:42 +0200 | [diff] [blame] | 1139 | # Enabling memory overcommit allows to run golang static binaries |
| 1140 | # compiled with a recent golang toolchain (>=1.11). Those binaries |
| 1141 | # allocate a large amount of virtual memory at init time, and this |
| 1142 | # allocation fails in tempest's nano flavor (64MB of RAM) |
| 1143 | # (golang issue reported in https://github.com/golang/go/issues/28114, |
| 1144 | # follow-up: https://github.com/golang/go/issues/28081) |
| 1145 | # TODO(gthiemonge): Remove this call when golang issue is resolved. |
| 1146 | linux_client.exec_command('sudo sh -c "echo 1 > ' |
| 1147 | '/proc/sys/vm/overcommit_memory"') |
| 1148 | |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 1149 | # The initial process also supports HTTPS and HTTPS with client auth |
| 1150 | linux_client.exec_command( |
| 1151 | 'sudo screen -d -m {0} -port 80 -id {1} -https_port 443 -cert {2} ' |
| 1152 | '-key {3} -https_client_auth_port 9443 -client_ca {4}'.format( |
| 1153 | const.TEST_SERVER_BINARY, start_id, const.TEST_SERVER_CERT, |
| 1154 | const.TEST_SERVER_KEY, const.TEST_SERVER_CLIENT_CA)) |
| 1155 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 1156 | linux_client.exec_command('sudo screen -d -m {0} -port 81 ' |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 1157 | '-id {1}'.format(const.TEST_SERVER_BINARY, |
| 1158 | start_id + 1)) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 1159 | |
Michael Johnson | bf916df | 2018-10-17 10:59:28 -0700 | [diff] [blame] | 1160 | # Cirros does not configure the assigned IPv6 address by default |
| 1161 | # so enable it manually like tempest does here: |
| 1162 | # tempest/scenario/test_netowrk_v6.py turn_nic6_on() |
| 1163 | @classmethod |
| 1164 | def _enable_ipv6_nic_webserver(cls, ip_address, ssh_key, |
| 1165 | ipv6_address, ipv6_prefix): |
| 1166 | linux_client = remote_client.RemoteClient( |
Ade Lee | d0ea406 | 2021-09-06 15:33:27 -0400 | [diff] [blame] | 1167 | ip_address, CONF.validation.image_ssh_user, pkey=ssh_key, |
Gregory Thiemonge | b0da4f3 | 2022-02-04 08:58:06 +0100 | [diff] [blame] | 1168 | **cls.remote_client_args()) |
Michael Johnson | bf916df | 2018-10-17 10:59:28 -0700 | [diff] [blame] | 1169 | linux_client.validate_authentication() |
| 1170 | |
| 1171 | linux_client.exec_command('sudo ip address add {0}/{1} dev ' |
| 1172 | 'eth0'.format(ipv6_address, ipv6_prefix)) |
| 1173 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 1174 | @classmethod |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 1175 | def _validate_webserver(cls, ip_address, start_id): |
| 1176 | URL = 'http://{0}'.format(ip_address) |
Michael Johnson | 89bdbcd | 2020-03-19 15:59:19 -0700 | [diff] [blame] | 1177 | cls.validate_URL_response(URL, expected_body=str(start_id)) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 1178 | URL = 'http://{0}:81'.format(ip_address) |
Michael Johnson | 89bdbcd | 2020-03-19 15:59:19 -0700 | [diff] [blame] | 1179 | cls.validate_URL_response(URL, expected_body=str(start_id + 1)) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 1180 | |
Gregory Thiemonge | 29d1790 | 2019-04-30 15:06:17 +0200 | [diff] [blame] | 1181 | @classmethod |
| 1182 | def _validate_udp_server(cls, ip_address, start_id): |
Michael Johnson | 89bdbcd | 2020-03-19 15:59:19 -0700 | [diff] [blame] | 1183 | res = cls.make_udp_request(ip_address, 80) |
Gregory Thiemonge | 29d1790 | 2019-04-30 15:06:17 +0200 | [diff] [blame] | 1184 | if res != str(start_id): |
| 1185 | raise Exception("Response from test server doesn't match the " |
| 1186 | "expected value ({0} != {1}).".format( |
| 1187 | res, str(start_id))) |
| 1188 | |
Michael Johnson | 89bdbcd | 2020-03-19 15:59:19 -0700 | [diff] [blame] | 1189 | res = cls.make_udp_request(ip_address, 81) |
Gregory Thiemonge | 29d1790 | 2019-04-30 15:06:17 +0200 | [diff] [blame] | 1190 | if res != str(start_id + 1): |
| 1191 | raise Exception("Response from test server doesn't match the " |
| 1192 | "expected value ({0} != {1}).".format( |
| 1193 | res, str(start_id + 1))) |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 1194 | |
| 1195 | @classmethod |
| 1196 | def _create_backend_reencryption_pki(cls): |
| 1197 | # Create a CA self-signed cert and key for the member test servers |
| 1198 | cls.member_ca_cert, cls.member_ca_key = ( |
| 1199 | cert_utils.generate_ca_cert_and_key()) |
| 1200 | |
| 1201 | LOG.debug('Member CA Cert: %s', cls.member_ca_cert.public_bytes( |
| 1202 | serialization.Encoding.PEM)) |
| 1203 | LOG.debug('Member CA private Key: %s', cls.member_ca_key.private_bytes( |
| 1204 | encoding=serialization.Encoding.PEM, |
| 1205 | format=serialization.PrivateFormat.TraditionalOpenSSL, |
| 1206 | encryption_algorithm=serialization.NoEncryption())) |
| 1207 | LOG.debug('Member CA public Key: %s', |
| 1208 | cls.member_ca_key.public_key().public_bytes( |
| 1209 | encoding=serialization.Encoding.PEM, |
| 1210 | format=serialization.PublicFormat.SubjectPublicKeyInfo)) |
| 1211 | |
| 1212 | # Create the member client authentication CA |
| 1213 | cls.member_client_ca_cert, member_client_ca_key = ( |
| 1214 | cert_utils.generate_ca_cert_and_key()) |
| 1215 | |
| 1216 | # Create client cert and key |
| 1217 | cls.member_client_cn = uuidutils.generate_uuid() |
| 1218 | cls.member_client_cert, cls.member_client_key = ( |
| 1219 | cert_utils.generate_client_cert_and_key( |
| 1220 | cls.member_client_ca_cert, member_client_ca_key, |
| 1221 | cls.member_client_cn)) |
| 1222 | # Note: We are not revoking a client cert here as we don't need to |
| 1223 | # test the backend web server CRL checking. |
| 1224 | |
| 1225 | @classmethod |
| 1226 | def _load_member_pki_content(cls, ip_address, ssh_key, revoke_cert=False): |
| 1227 | # Create webserver certificate and key |
| 1228 | cert, key = cert_utils.generate_server_cert_and_key( |
| 1229 | cls.member_ca_cert, cls.member_ca_key, ip_address) |
| 1230 | |
| 1231 | LOG.debug('%s Cert: %s', ip_address, cert.public_bytes( |
| 1232 | serialization.Encoding.PEM)) |
| 1233 | LOG.debug('%s private Key: %s', ip_address, key.private_bytes( |
| 1234 | encoding=serialization.Encoding.PEM, |
| 1235 | format=serialization.PrivateFormat.TraditionalOpenSSL, |
| 1236 | encryption_algorithm=serialization.NoEncryption())) |
| 1237 | public_key = key.public_key() |
| 1238 | LOG.debug('%s public Key: %s', ip_address, public_key.public_bytes( |
| 1239 | encoding=serialization.Encoding.PEM, |
| 1240 | format=serialization.PublicFormat.SubjectPublicKeyInfo)) |
| 1241 | |
| 1242 | # Create a CRL with a revoked certificate |
| 1243 | if revoke_cert: |
| 1244 | # Create a CRL with webserver 2 revoked |
| 1245 | cls.member_crl = cert_utils.generate_certificate_revocation_list( |
| 1246 | cls.member_ca_cert, cls.member_ca_key, cert) |
| 1247 | |
| 1248 | # Load the certificate, key, and client CA certificate into the |
| 1249 | # test server. |
| 1250 | with tempfile.TemporaryDirectory() as tmpdir: |
| 1251 | os.umask(0) |
| 1252 | files_to_send = [] |
| 1253 | cert_filename = os.path.join(tmpdir, const.CERT_PEM) |
| 1254 | files_to_send.append(cert_filename) |
| 1255 | with open(os.open(cert_filename, os.O_CREAT | os.O_WRONLY, |
| 1256 | 0o700), 'w') as fh: |
| 1257 | fh.write(cert.public_bytes( |
| 1258 | serialization.Encoding.PEM).decode('utf-8')) |
| 1259 | fh.flush() |
| 1260 | key_filename = os.path.join(tmpdir, const.KEY_PEM) |
| 1261 | files_to_send.append(key_filename) |
| 1262 | with open(os.open(key_filename, os.O_CREAT | os.O_WRONLY, |
| 1263 | 0o700), 'w') as fh: |
| 1264 | fh.write(key.private_bytes( |
| 1265 | encoding=serialization.Encoding.PEM, |
| 1266 | format=serialization.PrivateFormat.TraditionalOpenSSL, |
| 1267 | encryption_algorithm=serialization.NoEncryption()).decode( |
| 1268 | 'utf-8')) |
| 1269 | fh.flush() |
| 1270 | client_ca_filename = os.path.join(tmpdir, const.CLIENT_CA_PEM) |
| 1271 | files_to_send.append(client_ca_filename) |
| 1272 | with open(os.open(client_ca_filename, os.O_CREAT | os.O_WRONLY, |
| 1273 | 0o700), 'w') as fh: |
| 1274 | fh.write(cls.member_client_ca_cert.public_bytes( |
| 1275 | serialization.Encoding.PEM).decode('utf-8')) |
| 1276 | fh.flush() |
| 1277 | |
| 1278 | # For security, we don't want to use a shell that can glob |
| 1279 | # the file names, so iterate over them. |
| 1280 | subprocess_args = {'stdout': subprocess.PIPE, |
| 1281 | 'stderr': subprocess.STDOUT, |
| 1282 | 'cwd': None} |
Gregory Thiemonge | a2c234e | 2021-11-02 17:08:29 +0100 | [diff] [blame] | 1283 | ssh_extra_args = ( |
| 1284 | "-o PubkeyAcceptedKeyTypes=+ssh-rsa") |
| 1285 | if cls._need_scp_protocol(): |
| 1286 | ssh_extra_args += " -O" |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 1287 | cmd = ("scp -v -o UserKnownHostsFile=/dev/null " |
Gregory Thiemonge | a2c234e | 2021-11-02 17:08:29 +0100 | [diff] [blame] | 1288 | "{9} " |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 1289 | "-o StrictHostKeyChecking=no " |
| 1290 | "-o ConnectTimeout={0} -o ConnectionAttempts={1} " |
| 1291 | "-i {2} {3} {4} {5} {6}@{7}:{8}").format( |
| 1292 | CONF.load_balancer.scp_connection_timeout, |
| 1293 | CONF.load_balancer.scp_connection_attempts, |
| 1294 | ssh_key.name, cert_filename, key_filename, client_ca_filename, |
Gregory Thiemonge | a2c234e | 2021-11-02 17:08:29 +0100 | [diff] [blame] | 1295 | CONF.validation.image_ssh_user, ip_address, const.DEV_SHM_PATH, |
| 1296 | ssh_extra_args) |
Michael Johnson | baf12e0 | 2020-10-27 16:10:28 -0700 | [diff] [blame] | 1297 | args = shlex.split(cmd) |
| 1298 | proc = subprocess.Popen(args, **subprocess_args) |
| 1299 | stdout, stderr = proc.communicate() |
| 1300 | if proc.returncode != 0: |
| 1301 | raise exceptions.CommandFailed(proc.returncode, cmd, |
| 1302 | stdout, stderr) |