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 |
| 16 | import pkg_resources |
| 17 | import random |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 18 | import requests |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 19 | import shlex |
| 20 | import six |
| 21 | import string |
| 22 | import subprocess |
| 23 | import tempfile |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 24 | import time |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 25 | |
| 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 | |
| 35 | from octavia_tempest_plugin import clients |
| 36 | from octavia_tempest_plugin.common import constants as const |
| 37 | from octavia_tempest_plugin.tests import validators |
| 38 | from octavia_tempest_plugin.tests import waiters |
| 39 | |
| 40 | CONF = config.CONF |
| 41 | LOG = logging.getLogger(__name__) |
| 42 | |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 43 | RETRY_ATTEMPTS = 15 |
| 44 | RETRY_INITIAL_DELAY = 1 |
| 45 | RETRY_BACKOFF = 1 |
| 46 | RETRY_MAX = 5 |
| 47 | |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 48 | |
| 49 | class LoadBalancerBaseTest(test.BaseTestCase): |
| 50 | """Base class for load balancer tests.""" |
| 51 | |
| 52 | # Setup cls.os_roles_lb_member. cls.os_primary, cls.os_roles_lb_member, |
| 53 | # and cls.os_roles_lb_admin credentials. |
| 54 | credentials = ['admin', 'primary', |
| 55 | ['lb_member', CONF.load_balancer.member_role], |
| 56 | ['lb_member2', CONF.load_balancer.member_role], |
| 57 | ['lb_admin', CONF.load_balancer.admin_role]] |
| 58 | |
| 59 | client_manager = clients.ManagerV2 |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 60 | webserver1_response = 1 |
| 61 | webserver2_response = 5 |
Michael Johnson | dfd818a | 2018-08-21 20:54:54 -0700 | [diff] [blame] | 62 | used_ips = [] |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 63 | |
| 64 | @classmethod |
| 65 | def skip_checks(cls): |
| 66 | """Check if we should skip all of the children tests.""" |
| 67 | super(LoadBalancerBaseTest, cls).skip_checks() |
| 68 | |
| 69 | service_list = { |
| 70 | 'load_balancer': CONF.service_available.load_balancer, |
| 71 | } |
| 72 | |
| 73 | live_service_list = { |
| 74 | 'compute': CONF.service_available.nova, |
| 75 | 'image': CONF.service_available.glance, |
| 76 | 'neutron': CONF.service_available.neutron |
| 77 | } |
| 78 | |
| 79 | if not CONF.load_balancer.test_with_noop: |
| 80 | service_list.update(live_service_list) |
| 81 | |
| 82 | for service, available in service_list.items(): |
| 83 | if not available: |
zhangzs | 2a6cf67 | 2018-11-10 16:13:11 +0800 | [diff] [blame] | 84 | skip_msg = ("{0} skipped as {1} service is not " |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 85 | "available.".format(cls.__name__, service)) |
| 86 | raise cls.skipException(skip_msg) |
| 87 | |
| 88 | # We must be able to reach our VIP and instances |
| 89 | if not (CONF.network.project_networks_reachable |
| 90 | or CONF.network.public_network_id): |
| 91 | msg = ('Either project_networks_reachable must be "true", or ' |
| 92 | 'public_network_id must be defined.') |
| 93 | raise cls.skipException(msg) |
| 94 | |
| 95 | @classmethod |
| 96 | def setup_credentials(cls): |
| 97 | """Setup test credentials and network resources.""" |
| 98 | # Do not auto create network resources |
| 99 | cls.set_network_resources() |
| 100 | super(LoadBalancerBaseTest, cls).setup_credentials() |
| 101 | |
| 102 | @classmethod |
| 103 | def setup_clients(cls): |
| 104 | """Setup client aliases.""" |
| 105 | super(LoadBalancerBaseTest, cls).setup_clients() |
| 106 | cls.lb_mem_float_ip_client = cls.os_roles_lb_member.floating_ips_client |
| 107 | cls.lb_mem_keypairs_client = cls.os_roles_lb_member.keypairs_client |
| 108 | cls.lb_mem_net_client = cls.os_roles_lb_member.networks_client |
| 109 | cls.lb_mem_ports_client = cls.os_roles_lb_member.ports_client |
| 110 | cls.lb_mem_routers_client = cls.os_roles_lb_member.routers_client |
| 111 | cls.lb_mem_SG_client = cls.os_roles_lb_member.security_groups_client |
| 112 | cls.lb_mem_SGr_client = ( |
| 113 | cls.os_roles_lb_member.security_group_rules_client) |
| 114 | cls.lb_mem_servers_client = cls.os_roles_lb_member.servers_client |
| 115 | cls.lb_mem_subnet_client = cls.os_roles_lb_member.subnets_client |
| 116 | cls.mem_lb_client = cls.os_roles_lb_member.loadbalancer_client |
Jude Cross | fbbd2b4 | 2017-08-09 15:21:04 -0700 | [diff] [blame] | 117 | cls.mem_listener_client = cls.os_roles_lb_member.listener_client |
Adam Harwell | 8ffce3e | 2018-05-01 21:18:44 -0700 | [diff] [blame] | 118 | cls.mem_pool_client = cls.os_roles_lb_member.pool_client |
Adam Harwell | de3e054 | 2018-05-03 18:21:06 -0700 | [diff] [blame] | 119 | cls.mem_member_client = cls.os_roles_lb_member.member_client |
Adam Harwell | 60ed9d9 | 2018-05-10 13:23:13 -0700 | [diff] [blame] | 120 | cls.mem_healthmonitor_client = ( |
| 121 | cls.os_roles_lb_member.healthmonitor_client) |
Adam Harwell | 446f8be | 2018-05-24 16:51:03 -0700 | [diff] [blame] | 122 | cls.mem_l7policy_client = cls.os_roles_lb_member.l7policy_client |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 123 | cls.mem_l7rule_client = cls.os_roles_lb_member.l7rule_client |
Michael Johnson | 2b10e0a | 2019-01-25 15:42:13 -0800 | [diff] [blame] | 124 | cls.lb_admin_amphora_client = cls.os_roles_lb_admin.amphora_client |
Michael Johnson | aff2e86 | 2019-01-11 16:38:00 -0800 | [diff] [blame] | 125 | cls.lb_admin_flavor_profile_client = ( |
| 126 | cls.os_roles_lb_admin.flavor_profile_client) |
Michael Johnson | a2d0307 | 2019-01-14 17:18:21 -0800 | [diff] [blame] | 127 | cls.lb_admin_flavor_client = cls.os_roles_lb_admin.flavor_client |
| 128 | cls.mem_flavor_client = cls.os_roles_lb_member.flavor_client |
Michael Johnson | fc223fe | 2019-01-15 16:40:05 -0800 | [diff] [blame] | 129 | cls.mem_provider_client = cls.os_roles_lb_member.provider_client |
Carlos Goncalves | c2e1216 | 2019-02-14 23:57:44 +0100 | [diff] [blame] | 130 | cls.os_admin_servers_client = cls.os_admin.servers_client |
Michael Johnson | 77df032 | 2019-01-15 18:27:58 -0800 | [diff] [blame] | 131 | cls.lb_admin_capabilities_client = ( |
| 132 | cls.os_roles_lb_admin.flavor_capabilities_client) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 133 | |
| 134 | @classmethod |
| 135 | def resource_setup(cls): |
| 136 | """Setup resources needed by the tests.""" |
| 137 | super(LoadBalancerBaseTest, cls).resource_setup() |
| 138 | |
| 139 | conf_lb = CONF.load_balancer |
| 140 | |
Michael Johnson | dfd818a | 2018-08-21 20:54:54 -0700 | [diff] [blame] | 141 | cls.api_version = cls.mem_lb_client.get_max_api_version() |
| 142 | |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 143 | if conf_lb.test_subnet_override and not conf_lb.test_network_override: |
| 144 | raise exceptions.InvalidConfiguration( |
| 145 | "Configuration value test_network_override must be " |
| 146 | "specified if test_subnet_override is used.") |
| 147 | |
| 148 | show_subnet = cls.lb_mem_subnet_client.show_subnet |
| 149 | if CONF.load_balancer.test_with_noop: |
| 150 | cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()} |
| 151 | cls.lb_member_vip_subnet = {'id': uuidutils.generate_uuid()} |
| 152 | cls.lb_member_1_net = {'id': uuidutils.generate_uuid()} |
| 153 | cls.lb_member_1_subnet = {'id': uuidutils.generate_uuid()} |
| 154 | cls.lb_member_2_net = {'id': uuidutils.generate_uuid()} |
| 155 | cls.lb_member_2_subnet = {'id': uuidutils.generate_uuid()} |
| 156 | if CONF.load_balancer.test_with_ipv6: |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 157 | cls.lb_member_vip_ipv6_net = {'id': uuidutils.generate_uuid()} |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 158 | cls.lb_member_vip_ipv6_subnet = {'id': |
| 159 | uuidutils.generate_uuid()} |
| 160 | cls.lb_member_1_ipv6_subnet = {'id': uuidutils.generate_uuid()} |
| 161 | cls.lb_member_2_ipv6_subnet = {'id': uuidutils.generate_uuid()} |
Michael Johnson | 590fbe1 | 2019-07-03 14:30:01 -0700 | [diff] [blame] | 162 | cls.lb_member_vip_ipv6_subnet_stateful = True |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 163 | return |
| 164 | elif CONF.load_balancer.test_network_override: |
| 165 | if conf_lb.test_subnet_override: |
| 166 | override_subnet = show_subnet(conf_lb.test_subnet_override) |
| 167 | else: |
| 168 | override_subnet = None |
| 169 | |
| 170 | show_net = cls.lb_mem_net_client.show_network |
| 171 | override_network = show_net(conf_lb.test_network_override) |
| 172 | override_network = override_network.get('network') |
| 173 | |
| 174 | cls.lb_member_vip_net = override_network |
| 175 | cls.lb_member_vip_subnet = override_subnet |
| 176 | cls.lb_member_1_net = override_network |
| 177 | cls.lb_member_1_subnet = override_subnet |
| 178 | cls.lb_member_2_net = override_network |
| 179 | cls.lb_member_2_subnet = override_subnet |
| 180 | |
| 181 | if (CONF.load_balancer.test_with_ipv6 and |
| 182 | conf_lb.test_IPv6_subnet_override): |
| 183 | override_ipv6_subnet = show_subnet( |
| 184 | conf_lb.test_IPv6_subnet_override) |
| 185 | cls.lb_member_vip_ipv6_subnet = override_ipv6_subnet |
| 186 | cls.lb_member_1_ipv6_subnet = override_ipv6_subnet |
| 187 | cls.lb_member_2_ipv6_subnet = override_ipv6_subnet |
Michael Johnson | 590fbe1 | 2019-07-03 14:30:01 -0700 | [diff] [blame] | 188 | cls.lb_member_vip_ipv6_subnet_stateful = False |
| 189 | if (override_ipv6_subnet[0]['ipv6_address_mode'] == |
| 190 | 'dhcpv6-stateful'): |
| 191 | cls.lb_member_vip_ipv6_subnet_stateful = True |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 192 | else: |
| 193 | cls.lb_member_vip_ipv6_subnet = None |
| 194 | cls.lb_member_1_ipv6_subnet = None |
| 195 | cls.lb_member_2_ipv6_subnet = None |
| 196 | else: |
| 197 | cls._create_networks() |
| 198 | |
| 199 | LOG.debug('Octavia Setup: lb_member_vip_net = {}'.format( |
| 200 | cls.lb_member_vip_net[const.ID])) |
| 201 | if cls.lb_member_vip_subnet: |
| 202 | LOG.debug('Octavia Setup: lb_member_vip_subnet = {}'.format( |
| 203 | cls.lb_member_vip_subnet[const.ID])) |
| 204 | LOG.debug('Octavia Setup: lb_member_1_net = {}'.format( |
| 205 | cls.lb_member_1_net[const.ID])) |
| 206 | if cls.lb_member_1_subnet: |
| 207 | LOG.debug('Octavia Setup: lb_member_1_subnet = {}'.format( |
| 208 | cls.lb_member_1_subnet[const.ID])) |
| 209 | LOG.debug('Octavia Setup: lb_member_2_net = {}'.format( |
| 210 | cls.lb_member_2_net[const.ID])) |
| 211 | if cls.lb_member_2_subnet: |
| 212 | LOG.debug('Octavia Setup: lb_member_2_subnet = {}'.format( |
| 213 | cls.lb_member_2_subnet[const.ID])) |
Michael Johnson | 124ba8b | 2018-08-30 16:06:05 -0700 | [diff] [blame] | 214 | if CONF.load_balancer.test_with_ipv6: |
| 215 | if cls.lb_member_vip_ipv6_subnet: |
| 216 | LOG.debug('Octavia Setup: lb_member_vip_ipv6_subnet = ' |
| 217 | '{}'.format(cls.lb_member_vip_ipv6_subnet[const.ID])) |
| 218 | if cls.lb_member_1_ipv6_subnet: |
| 219 | LOG.debug('Octavia Setup: lb_member_1_ipv6_subnet = {}'.format( |
| 220 | cls.lb_member_1_ipv6_subnet[const.ID])) |
| 221 | if cls.lb_member_2_ipv6_subnet: |
| 222 | LOG.debug('Octavia Setup: lb_member_2_ipv6_subnet = {}'.format( |
| 223 | cls.lb_member_2_ipv6_subnet[const.ID])) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 224 | |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 225 | @classmethod |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 226 | # Neutron can be slow to clean up ports from the subnets/networks. |
| 227 | # Retry this delete a few times if we get a "Conflict" error to give |
| 228 | # neutron time to fully cleanup the ports. |
| 229 | @tenacity.retry( |
| 230 | retry=tenacity.retry_if_exception_type(exceptions.Conflict), |
| 231 | wait=tenacity.wait_incrementing( |
| 232 | RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX), |
| 233 | stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS)) |
| 234 | def _logging_delete_network(cls, net_id): |
| 235 | try: |
| 236 | cls.lb_mem_net_client.delete_network(net_id) |
| 237 | except Exception: |
| 238 | LOG.error('Unable to delete network {}. Active ports:'.format( |
| 239 | net_id)) |
| 240 | LOG.error(cls.lb_mem_ports_client.list_ports()) |
| 241 | raise |
| 242 | |
| 243 | @classmethod |
| 244 | # Neutron can be slow to clean up ports from the subnets/networks. |
| 245 | # Retry this delete a few times if we get a "Conflict" error to give |
| 246 | # neutron time to fully cleanup the ports. |
| 247 | @tenacity.retry( |
| 248 | retry=tenacity.retry_if_exception_type(exceptions.Conflict), |
| 249 | wait=tenacity.wait_incrementing( |
| 250 | RETRY_INITIAL_DELAY, RETRY_BACKOFF, RETRY_MAX), |
| 251 | stop=tenacity.stop_after_attempt(RETRY_ATTEMPTS)) |
| 252 | def _logging_delete_subnet(cls, subnet_id): |
| 253 | try: |
| 254 | cls.lb_mem_subnet_client.delete_subnet(subnet_id) |
| 255 | except Exception: |
| 256 | LOG.error('Unable to delete subnet {}. Active ports:'.format( |
| 257 | subnet_id)) |
| 258 | LOG.error(cls.lb_mem_ports_client.list_ports()) |
| 259 | raise |
| 260 | |
| 261 | @classmethod |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 262 | def _create_networks(cls): |
| 263 | """Creates networks, subnets, and routers used in tests. |
| 264 | |
| 265 | The following are expected to be defined and available to the tests: |
| 266 | cls.lb_member_vip_net |
| 267 | cls.lb_member_vip_subnet |
| 268 | cls.lb_member_vip_ipv6_subnet (optional) |
| 269 | cls.lb_member_1_net |
| 270 | cls.lb_member_1_subnet |
| 271 | cls.lb_member_1_ipv6_subnet (optional) |
| 272 | cls.lb_member_2_net |
| 273 | cls.lb_member_2_subnet |
| 274 | cls.lb_member_2_ipv6_subnet (optional) |
| 275 | """ |
| 276 | |
| 277 | # Create tenant VIP network |
| 278 | network_kwargs = { |
| 279 | 'name': data_utils.rand_name("lb_member_vip_network")} |
| 280 | if CONF.network_feature_enabled.port_security: |
| 281 | # Note: Allowed Address Pairs requires port security |
| 282 | network_kwargs['port_security_enabled'] = True |
| 283 | result = cls.lb_mem_net_client.create_network(**network_kwargs) |
| 284 | cls.lb_member_vip_net = result['network'] |
| 285 | LOG.info('lb_member_vip_net: {}'.format(cls.lb_member_vip_net)) |
| 286 | cls.addClassResourceCleanup( |
| 287 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 288 | cls._logging_delete_network, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 289 | cls.lb_mem_net_client.show_network, |
| 290 | cls.lb_member_vip_net['id']) |
| 291 | |
| 292 | # Create tenant VIP subnet |
| 293 | subnet_kwargs = { |
| 294 | 'name': data_utils.rand_name("lb_member_vip_subnet"), |
| 295 | 'network_id': cls.lb_member_vip_net['id'], |
| 296 | 'cidr': CONF.load_balancer.vip_subnet_cidr, |
| 297 | 'ip_version': 4} |
| 298 | result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs) |
| 299 | cls.lb_member_vip_subnet = result['subnet'] |
| 300 | LOG.info('lb_member_vip_subnet: {}'.format(cls.lb_member_vip_subnet)) |
| 301 | cls.addClassResourceCleanup( |
| 302 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 303 | cls._logging_delete_subnet, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 304 | cls.lb_mem_subnet_client.show_subnet, |
| 305 | cls.lb_member_vip_subnet['id']) |
| 306 | |
| 307 | # Create tenant VIP IPv6 subnet |
| 308 | if CONF.load_balancer.test_with_ipv6: |
Adam Harwell | 2b9432f | 2019-05-02 13:56:09 -0600 | [diff] [blame] | 309 | # See if ipv6-private-subnet exists and use it if so. |
| 310 | priv_ipv6_subnet = cls.os_admin.subnets_client.list_subnets( |
| 311 | name='ipv6-private-subnet')['subnets'] |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 312 | |
Michael Johnson | 590fbe1 | 2019-07-03 14:30:01 -0700 | [diff] [blame] | 313 | cls.lb_member_vip_ipv6_subnet_stateful = False |
| 314 | if (priv_ipv6_subnet[0]['ipv6_address_mode'] == |
| 315 | 'dhcpv6-stateful'): |
| 316 | cls.lb_member_vip_ipv6_subnet_stateful = True |
Adam Harwell | 2b9432f | 2019-05-02 13:56:09 -0600 | [diff] [blame] | 317 | if len(priv_ipv6_subnet) == 1: |
| 318 | cls.lb_member_vip_ipv6_subnet = priv_ipv6_subnet[0] |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 319 | cls.lb_member_vip_ipv6_net = { |
Adam Harwell | 2b9432f | 2019-05-02 13:56:09 -0600 | [diff] [blame] | 320 | 'id': priv_ipv6_subnet[0]['network_id']} |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 321 | else: |
| 322 | subnet_kwargs = { |
| 323 | 'name': data_utils.rand_name("lb_member_vip_ipv6_subnet"), |
| 324 | 'network_id': cls.lb_member_vip_net['id'], |
| 325 | 'cidr': CONF.load_balancer.vip_ipv6_subnet_cidr, |
| 326 | 'ip_version': 6} |
| 327 | result = cls.lb_mem_subnet_client.create_subnet( |
| 328 | **subnet_kwargs) |
Michael Johnson | 7c5b901 | 2019-05-28 11:02:29 -0700 | [diff] [blame] | 329 | cls.lb_member_vip_ipv6_net = cls.lb_member_vip_net |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 330 | cls.lb_member_vip_ipv6_subnet = result['subnet'] |
| 331 | cls.addClassResourceCleanup( |
| 332 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 333 | cls._logging_delete_subnet, |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 334 | cls.lb_mem_subnet_client.show_subnet, |
| 335 | cls.lb_member_vip_ipv6_subnet['id']) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 336 | LOG.info('lb_member_vip_ipv6_subnet: {}'.format( |
| 337 | cls.lb_member_vip_ipv6_subnet)) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 338 | |
| 339 | # Create tenant member 1 network |
| 340 | network_kwargs = { |
| 341 | 'name': data_utils.rand_name("lb_member_1_network")} |
| 342 | if CONF.network_feature_enabled.port_security: |
| 343 | if CONF.load_balancer.enable_security_groups: |
| 344 | network_kwargs['port_security_enabled'] = True |
| 345 | else: |
| 346 | network_kwargs['port_security_enabled'] = False |
| 347 | result = cls.lb_mem_net_client.create_network(**network_kwargs) |
| 348 | cls.lb_member_1_net = result['network'] |
| 349 | LOG.info('lb_member_1_net: {}'.format(cls.lb_member_1_net)) |
| 350 | cls.addClassResourceCleanup( |
| 351 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 352 | cls._logging_delete_network, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 353 | cls.lb_mem_net_client.show_network, |
| 354 | cls.lb_member_1_net['id']) |
| 355 | |
| 356 | # Create tenant member 1 subnet |
| 357 | subnet_kwargs = { |
| 358 | 'name': data_utils.rand_name("lb_member_1_subnet"), |
| 359 | 'network_id': cls.lb_member_1_net['id'], |
| 360 | 'cidr': CONF.load_balancer.member_1_ipv4_subnet_cidr, |
| 361 | 'ip_version': 4} |
| 362 | result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs) |
| 363 | cls.lb_member_1_subnet = result['subnet'] |
| 364 | LOG.info('lb_member_1_subnet: {}'.format(cls.lb_member_1_subnet)) |
| 365 | cls.addClassResourceCleanup( |
| 366 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 367 | cls._logging_delete_subnet, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 368 | cls.lb_mem_subnet_client.show_subnet, |
| 369 | cls.lb_member_1_subnet['id']) |
| 370 | |
| 371 | # Create tenant member 1 ipv6 subnet |
| 372 | if CONF.load_balancer.test_with_ipv6: |
| 373 | subnet_kwargs = { |
| 374 | 'name': data_utils.rand_name("lb_member_1_ipv6_subnet"), |
| 375 | 'network_id': cls.lb_member_1_net['id'], |
| 376 | 'cidr': CONF.load_balancer.member_1_ipv6_subnet_cidr, |
| 377 | 'ip_version': 6} |
| 378 | result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs) |
Michael Johnson | bf916df | 2018-10-17 10:59:28 -0700 | [diff] [blame] | 379 | cls.lb_member_1_subnet_prefix = ( |
| 380 | CONF.load_balancer.member_1_ipv6_subnet_cidr.rpartition('/')[2] |
| 381 | ) |
| 382 | assert(cls.lb_member_1_subnet_prefix.isdigit()) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 383 | cls.lb_member_1_ipv6_subnet = result['subnet'] |
| 384 | LOG.info('lb_member_1_ipv6_subnet: {}'.format( |
| 385 | cls.lb_member_1_ipv6_subnet)) |
| 386 | cls.addClassResourceCleanup( |
| 387 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 388 | cls._logging_delete_subnet, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 389 | cls.lb_mem_subnet_client.show_subnet, |
| 390 | cls.lb_member_1_ipv6_subnet['id']) |
| 391 | |
| 392 | # Create tenant member 2 network |
| 393 | network_kwargs = { |
| 394 | 'name': data_utils.rand_name("lb_member_2_network")} |
| 395 | if CONF.network_feature_enabled.port_security: |
| 396 | if CONF.load_balancer.enable_security_groups: |
| 397 | network_kwargs['port_security_enabled'] = True |
| 398 | else: |
| 399 | network_kwargs['port_security_enabled'] = False |
| 400 | result = cls.lb_mem_net_client.create_network(**network_kwargs) |
| 401 | cls.lb_member_2_net = result['network'] |
| 402 | LOG.info('lb_member_2_net: {}'.format(cls.lb_member_2_net)) |
| 403 | cls.addClassResourceCleanup( |
| 404 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 405 | cls._logging_delete_network, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 406 | cls.lb_mem_net_client.show_network, |
| 407 | cls.lb_member_2_net['id']) |
| 408 | |
| 409 | # Create tenant member 2 subnet |
| 410 | subnet_kwargs = { |
| 411 | 'name': data_utils.rand_name("lb_member_2_subnet"), |
| 412 | 'network_id': cls.lb_member_2_net['id'], |
| 413 | 'cidr': CONF.load_balancer.member_2_ipv4_subnet_cidr, |
| 414 | 'ip_version': 4} |
| 415 | result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs) |
| 416 | cls.lb_member_2_subnet = result['subnet'] |
| 417 | LOG.info('lb_member_2_subnet: {}'.format(cls.lb_member_2_subnet)) |
| 418 | cls.addClassResourceCleanup( |
| 419 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 420 | cls._logging_delete_subnet, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 421 | cls.lb_mem_subnet_client.show_subnet, |
| 422 | cls.lb_member_2_subnet['id']) |
| 423 | |
| 424 | # Create tenant member 2 ipv6 subnet |
| 425 | if CONF.load_balancer.test_with_ipv6: |
| 426 | subnet_kwargs = { |
| 427 | 'name': data_utils.rand_name("lb_member_2_ipv6_subnet"), |
| 428 | 'network_id': cls.lb_member_2_net['id'], |
| 429 | 'cidr': CONF.load_balancer.member_2_ipv6_subnet_cidr, |
| 430 | 'ip_version': 6} |
| 431 | result = cls.lb_mem_subnet_client.create_subnet(**subnet_kwargs) |
Michael Johnson | bf916df | 2018-10-17 10:59:28 -0700 | [diff] [blame] | 432 | cls.lb_member_2_subnet_prefix = ( |
| 433 | CONF.load_balancer.member_2_ipv6_subnet_cidr.rpartition('/')[2] |
| 434 | ) |
| 435 | assert(cls.lb_member_2_subnet_prefix.isdigit()) |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 436 | cls.lb_member_2_ipv6_subnet = result['subnet'] |
| 437 | LOG.info('lb_member_2_ipv6_subnet: {}'.format( |
| 438 | cls.lb_member_2_ipv6_subnet)) |
| 439 | cls.addClassResourceCleanup( |
| 440 | waiters.wait_for_not_found, |
Michael Johnson | 04dc5cb | 2019-01-20 11:03:50 -0800 | [diff] [blame] | 441 | cls._logging_delete_subnet, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 442 | cls.lb_mem_subnet_client.show_subnet, |
| 443 | cls.lb_member_2_ipv6_subnet['id']) |
| 444 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 445 | @classmethod |
Michael Johnson | 07c9a63 | 2018-06-07 13:27:42 -0700 | [diff] [blame] | 446 | def _setup_lb_network_kwargs(cls, lb_kwargs, ip_version=None, |
| 447 | use_fixed_ip=False): |
Adam Harwell | 60ed9d9 | 2018-05-10 13:23:13 -0700 | [diff] [blame] | 448 | if not ip_version: |
| 449 | ip_version = 6 if CONF.load_balancer.test_with_ipv6 else 4 |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 450 | 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] | 451 | ip_index = data_utils.rand_int_id(start=10, end=100) |
Michael Johnson | dfd818a | 2018-08-21 20:54:54 -0700 | [diff] [blame] | 452 | while ip_index in cls.used_ips: |
| 453 | ip_index = data_utils.rand_int_id(start=10, end=100) |
| 454 | cls.used_ips.append(ip_index) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 455 | if ip_version == 4: |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 456 | subnet_id = cls.lb_member_vip_subnet[const.ID] |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 457 | if CONF.load_balancer.test_with_noop: |
| 458 | lb_vip_address = '198.18.33.33' |
| 459 | else: |
| 460 | subnet = cls.os_admin.subnets_client.show_subnet(subnet_id) |
| 461 | network = ipaddress.IPv4Network(subnet['subnet']['cidr']) |
| 462 | lb_vip_address = str(network[ip_index]) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 463 | else: |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 464 | subnet_id = cls.lb_member_vip_ipv6_subnet[const.ID] |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 465 | if CONF.load_balancer.test_with_noop: |
| 466 | lb_vip_address = '2001:db8:33:33:33:33:33:33' |
| 467 | else: |
| 468 | subnet = cls.os_admin.subnets_client.show_subnet(subnet_id) |
| 469 | network = ipaddress.IPv6Network(subnet['subnet']['cidr']) |
| 470 | lb_vip_address = str(network[ip_index]) |
Michael Johnson | 590fbe1 | 2019-07-03 14:30:01 -0700 | [diff] [blame] | 471 | # If the subnet is IPv6 slaac or dhcpv6-stateless |
| 472 | # neutron does not allow a fixed IP |
| 473 | if not cls.lb_member_vip_ipv6_subnet_stateful: |
| 474 | use_fixed_ip = False |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 475 | lb_kwargs[const.VIP_SUBNET_ID] = subnet_id |
Michael Johnson | 07c9a63 | 2018-06-07 13:27:42 -0700 | [diff] [blame] | 476 | if use_fixed_ip: |
| 477 | lb_kwargs[const.VIP_ADDRESS] = lb_vip_address |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 478 | if CONF.load_balancer.test_with_noop: |
| 479 | lb_kwargs[const.VIP_NETWORK_ID] = ( |
| 480 | cls.lb_member_vip_net[const.ID]) |
| 481 | else: |
| 482 | lb_kwargs[const.VIP_NETWORK_ID] = cls.lb_member_vip_net[const.ID] |
| 483 | lb_kwargs[const.VIP_SUBNET_ID] = None |
| 484 | |
| 485 | |
| 486 | class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest): |
| 487 | @classmethod |
| 488 | def resource_setup(cls): |
| 489 | super(LoadBalancerBaseTestWithCompute, cls).resource_setup() |
| 490 | # If validation is disabled in this cloud, we won't be able to |
| 491 | # start the webservers, so don't even boot them. |
| 492 | if not CONF.validation.run_validation: |
| 493 | return |
| 494 | |
| 495 | # Create a keypair for the webservers |
| 496 | keypair_name = data_utils.rand_name('lb_member_keypair') |
| 497 | result = cls.lb_mem_keypairs_client.create_keypair( |
| 498 | name=keypair_name) |
| 499 | cls.lb_member_keypair = result['keypair'] |
| 500 | LOG.info('lb_member_keypair: {}'.format(cls.lb_member_keypair)) |
| 501 | cls.addClassResourceCleanup( |
| 502 | waiters.wait_for_not_found, |
| 503 | cls.lb_mem_keypairs_client.delete_keypair, |
| 504 | cls.lb_mem_keypairs_client.show_keypair, |
| 505 | keypair_name) |
| 506 | |
| 507 | if (CONF.load_balancer.enable_security_groups and |
| 508 | CONF.network_feature_enabled.port_security): |
| 509 | # Set up the security group for the webservers |
| 510 | SG_name = data_utils.rand_name('lb_member_SG') |
| 511 | cls.lb_member_sec_group = ( |
| 512 | cls.lb_mem_SG_client.create_security_group( |
| 513 | name=SG_name)['security_group']) |
| 514 | cls.addClassResourceCleanup( |
| 515 | waiters.wait_for_not_found, |
| 516 | cls.lb_mem_SG_client.delete_security_group, |
| 517 | cls.lb_mem_SG_client.show_security_group, |
| 518 | cls.lb_member_sec_group['id']) |
| 519 | |
| 520 | # Create a security group rule to allow 80-81 (test webservers) |
| 521 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 522 | direction='ingress', |
| 523 | security_group_id=cls.lb_member_sec_group['id'], |
| 524 | protocol='tcp', |
| 525 | ethertype='IPv4', |
| 526 | port_range_min=80, |
| 527 | port_range_max=81)['security_group_rule'] |
| 528 | cls.addClassResourceCleanup( |
| 529 | waiters.wait_for_not_found, |
| 530 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 531 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 532 | SGr['id']) |
| 533 | # Create a security group rule to allow 22 (ssh) |
| 534 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 535 | direction='ingress', |
| 536 | security_group_id=cls.lb_member_sec_group['id'], |
| 537 | protocol='tcp', |
| 538 | ethertype='IPv4', |
| 539 | port_range_min=22, |
| 540 | port_range_max=22)['security_group_rule'] |
| 541 | cls.addClassResourceCleanup( |
| 542 | waiters.wait_for_not_found, |
| 543 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 544 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 545 | SGr['id']) |
| 546 | if CONF.load_balancer.test_with_ipv6: |
| 547 | # Create a security group rule to allow 80-81 (test webservers) |
| 548 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 549 | direction='ingress', |
| 550 | security_group_id=cls.lb_member_sec_group['id'], |
| 551 | protocol='tcp', |
| 552 | ethertype='IPv6', |
| 553 | port_range_min=80, |
| 554 | port_range_max=81)['security_group_rule'] |
| 555 | cls.addClassResourceCleanup( |
| 556 | waiters.wait_for_not_found, |
| 557 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 558 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 559 | SGr['id']) |
| 560 | # Create a security group rule to allow 22 (ssh) |
| 561 | SGr = cls.lb_mem_SGr_client.create_security_group_rule( |
| 562 | direction='ingress', |
| 563 | security_group_id=cls.lb_member_sec_group['id'], |
| 564 | protocol='tcp', |
| 565 | ethertype='IPv6', |
| 566 | port_range_min=22, |
| 567 | port_range_max=22)['security_group_rule'] |
| 568 | cls.addClassResourceCleanup( |
| 569 | waiters.wait_for_not_found, |
| 570 | cls.lb_mem_SGr_client.delete_security_group_rule, |
| 571 | cls.lb_mem_SGr_client.show_security_group_rule, |
| 572 | SGr['id']) |
| 573 | |
| 574 | LOG.info('lb_member_sec_group: {}'.format(cls.lb_member_sec_group)) |
| 575 | |
| 576 | # Create webserver 1 instance |
| 577 | server_details = cls._create_webserver('lb_member_webserver1', |
| 578 | cls.lb_member_1_net) |
| 579 | |
| 580 | cls.lb_member_webserver1 = server_details['server'] |
| 581 | cls.webserver1_ip = server_details.get('ipv4_address') |
| 582 | cls.webserver1_ipv6 = server_details.get('ipv6_address') |
| 583 | cls.webserver1_public_ip = server_details['public_ipv4_address'] |
| 584 | |
| 585 | LOG.debug('Octavia Setup: lb_member_webserver1 = {}'.format( |
| 586 | cls.lb_member_webserver1[const.ID])) |
| 587 | LOG.debug('Octavia Setup: webserver1_ip = {}'.format( |
| 588 | cls.webserver1_ip)) |
| 589 | LOG.debug('Octavia Setup: webserver1_ipv6 = {}'.format( |
| 590 | cls.webserver1_ipv6)) |
| 591 | LOG.debug('Octavia Setup: webserver1_public_ip = {}'.format( |
| 592 | cls.webserver1_public_ip)) |
| 593 | |
| 594 | # Create webserver 2 instance |
| 595 | server_details = cls._create_webserver('lb_member_webserver2', |
| 596 | cls.lb_member_2_net) |
| 597 | |
| 598 | cls.lb_member_webserver2 = server_details['server'] |
| 599 | cls.webserver2_ip = server_details.get('ipv4_address') |
| 600 | cls.webserver2_ipv6 = server_details.get('ipv6_address') |
| 601 | cls.webserver2_public_ip = server_details['public_ipv4_address'] |
| 602 | |
| 603 | LOG.debug('Octavia Setup: lb_member_webserver2 = {}'.format( |
| 604 | cls.lb_member_webserver2[const.ID])) |
| 605 | LOG.debug('Octavia Setup: webserver2_ip = {}'.format( |
| 606 | cls.webserver2_ip)) |
| 607 | LOG.debug('Octavia Setup: webserver2_ipv6 = {}'.format( |
| 608 | cls.webserver2_ipv6)) |
| 609 | LOG.debug('Octavia Setup: webserver2_public_ip = {}'.format( |
| 610 | cls.webserver2_public_ip)) |
| 611 | |
Michael Johnson | bf916df | 2018-10-17 10:59:28 -0700 | [diff] [blame] | 612 | if CONF.load_balancer.test_with_ipv6: |
| 613 | # Enable the IPv6 nic in webserver 1 |
| 614 | cls._enable_ipv6_nic_webserver( |
| 615 | cls.webserver1_public_ip, cls.lb_member_keypair['private_key'], |
| 616 | cls.webserver1_ipv6, cls.lb_member_1_subnet_prefix) |
| 617 | |
| 618 | # Enable the IPv6 nic in webserver 2 |
| 619 | cls._enable_ipv6_nic_webserver( |
| 620 | cls.webserver2_public_ip, cls.lb_member_keypair['private_key'], |
| 621 | cls.webserver2_ipv6, cls.lb_member_2_subnet_prefix) |
| 622 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 623 | # Set up serving on webserver 1 |
| 624 | cls._install_start_webserver(cls.webserver1_public_ip, |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 625 | cls.lb_member_keypair['private_key'], |
| 626 | cls.webserver1_response) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 627 | |
| 628 | # Validate webserver 1 |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 629 | cls._validate_webserver(cls.webserver1_public_ip, |
| 630 | cls.webserver1_response) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 631 | |
| 632 | # Set up serving on webserver 2 |
| 633 | cls._install_start_webserver(cls.webserver2_public_ip, |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 634 | cls.lb_member_keypair['private_key'], |
| 635 | cls.webserver2_response) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 636 | |
| 637 | # Validate webserver 2 |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 638 | cls._validate_webserver(cls.webserver2_public_ip, |
| 639 | cls.webserver2_response) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 640 | |
| 641 | @classmethod |
| 642 | def _create_networks(cls): |
| 643 | super(LoadBalancerBaseTestWithCompute, cls)._create_networks() |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 644 | # Create a router for the subnets (required for the floating IP) |
| 645 | router_name = data_utils.rand_name("lb_member_router") |
| 646 | result = cls.lb_mem_routers_client.create_router( |
| 647 | name=router_name, admin_state_up=True, |
| 648 | external_gateway_info=dict( |
| 649 | network_id=CONF.network.public_network_id)) |
| 650 | cls.lb_member_router = result['router'] |
| 651 | LOG.info('lb_member_router: {}'.format(cls.lb_member_router)) |
| 652 | cls.addClassResourceCleanup( |
| 653 | waiters.wait_for_not_found, |
| 654 | cls.lb_mem_routers_client.delete_router, |
| 655 | cls.lb_mem_routers_client.show_router, |
| 656 | cls.lb_member_router['id']) |
| 657 | |
| 658 | # Add VIP subnet to router |
| 659 | cls.lb_mem_routers_client.add_router_interface( |
| 660 | cls.lb_member_router['id'], |
| 661 | subnet_id=cls.lb_member_vip_subnet['id']) |
| 662 | cls.addClassResourceCleanup( |
| 663 | waiters.wait_for_not_found, |
| 664 | cls.lb_mem_routers_client.remove_router_interface, |
| 665 | cls.lb_mem_routers_client.remove_router_interface, |
| 666 | cls.lb_member_router['id'], |
| 667 | subnet_id=cls.lb_member_vip_subnet['id']) |
| 668 | |
| 669 | # Add member subnet 1 to router |
| 670 | cls.lb_mem_routers_client.add_router_interface( |
| 671 | cls.lb_member_router['id'], |
| 672 | subnet_id=cls.lb_member_1_subnet['id']) |
| 673 | cls.addClassResourceCleanup( |
| 674 | waiters.wait_for_not_found, |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 675 | cls.lb_mem_routers_client.remove_router_interface, |
| 676 | cls.lb_mem_routers_client.remove_router_interface, |
| 677 | cls.lb_member_router['id'], subnet_id=cls.lb_member_1_subnet['id']) |
| 678 | |
| 679 | # Add member subnet 2 to router |
| 680 | cls.lb_mem_routers_client.add_router_interface( |
| 681 | cls.lb_member_router['id'], |
| 682 | subnet_id=cls.lb_member_2_subnet['id']) |
| 683 | cls.addClassResourceCleanup( |
| 684 | waiters.wait_for_not_found, |
| 685 | cls.lb_mem_routers_client.remove_router_interface, |
| 686 | cls.lb_mem_routers_client.remove_router_interface, |
| 687 | cls.lb_member_router['id'], subnet_id=cls.lb_member_2_subnet['id']) |
| 688 | |
| 689 | @classmethod |
| 690 | def _create_webserver(cls, name, network): |
| 691 | """Creates a webserver with two ports. |
| 692 | |
| 693 | webserver_details dictionary contains: |
| 694 | server - The compute server object |
| 695 | ipv4_address - The IPv4 address for the server (optional) |
| 696 | ipv6_address - The IPv6 address for the server (optional) |
| 697 | public_ipv4_address - The publicly accessible IPv4 address for the |
| 698 | server, this may be a floating IP (optional) |
| 699 | |
| 700 | :param name: The name of the server to create. |
| 701 | :param network: The network to boot the server on. |
| 702 | :returns: webserver_details dictionary. |
| 703 | """ |
| 704 | server_kwargs = { |
| 705 | 'name': data_utils.rand_name(name), |
| 706 | 'flavorRef': CONF.compute.flavor_ref, |
| 707 | 'imageRef': CONF.compute.image_ref, |
| 708 | 'key_name': cls.lb_member_keypair['name']} |
| 709 | if (CONF.load_balancer.enable_security_groups and |
| 710 | CONF.network_feature_enabled.port_security): |
| 711 | server_kwargs['security_groups'] = [ |
| 712 | {'name': cls.lb_member_sec_group['name']}] |
| 713 | if not CONF.load_balancer.disable_boot_network: |
| 714 | server_kwargs['networks'] = [{'uuid': network['id']}] |
| 715 | |
| 716 | # Replace the name for clouds that have limitations |
| 717 | if CONF.load_balancer.random_server_name_length: |
| 718 | r = random.SystemRandom() |
| 719 | server_kwargs['name'] = "m{}".format("".join( |
| 720 | [r.choice(string.ascii_uppercase + string.digits) |
| 721 | for _ in range( |
| 722 | CONF.load_balancer.random_server_name_length - 1)] |
| 723 | )) |
| 724 | if CONF.load_balancer.availability_zone: |
| 725 | server_kwargs['availability_zone'] = ( |
| 726 | CONF.load_balancer.availability_zone) |
| 727 | |
| 728 | server = cls.lb_mem_servers_client.create_server( |
| 729 | **server_kwargs)['server'] |
| 730 | cls.addClassResourceCleanup( |
| 731 | waiters.wait_for_not_found, |
| 732 | cls.lb_mem_servers_client.delete_server, |
| 733 | cls.lb_mem_servers_client.show_server, |
| 734 | server['id']) |
| 735 | server = waiters.wait_for_status( |
| 736 | cls.lb_mem_servers_client.show_server, |
| 737 | server['id'], 'status', 'ACTIVE', |
| 738 | CONF.load_balancer.build_interval, |
| 739 | CONF.load_balancer.build_timeout, |
| 740 | root_tag='server') |
| 741 | webserver_details = {'server': server} |
| 742 | LOG.info('Created server: {}'.format(server)) |
| 743 | |
| 744 | addresses = server['addresses'] |
| 745 | if CONF.load_balancer.disable_boot_network: |
| 746 | instance_network = addresses.values()[0] |
| 747 | else: |
| 748 | instance_network = addresses[network['name']] |
| 749 | for addr in instance_network: |
| 750 | if addr['version'] == 4: |
| 751 | webserver_details['ipv4_address'] = addr['addr'] |
| 752 | if addr['version'] == 6: |
| 753 | webserver_details['ipv6_address'] = addr['addr'] |
| 754 | |
| 755 | if CONF.validation.connect_method == 'floating': |
| 756 | result = cls.lb_mem_ports_client.list_ports( |
| 757 | network_id=network['id'], |
| 758 | mac_address=instance_network[0]['OS-EXT-IPS-MAC:mac_addr']) |
| 759 | port_id = result['ports'][0]['id'] |
| 760 | result = cls.lb_mem_float_ip_client.create_floatingip( |
| 761 | floating_network_id=CONF.network.public_network_id, |
| 762 | port_id=port_id) |
| 763 | floating_ip = result['floatingip'] |
| 764 | LOG.info('webserver1_floating_ip: {}'.format(floating_ip)) |
| 765 | cls.addClassResourceCleanup( |
| 766 | waiters.wait_for_not_found, |
| 767 | cls.lb_mem_float_ip_client.delete_floatingip, |
| 768 | cls.lb_mem_float_ip_client.show_floatingip, |
| 769 | floatingip_id=floating_ip['id']) |
| 770 | webserver_details['public_ipv4_address'] = ( |
| 771 | floating_ip['floating_ip_address']) |
| 772 | else: |
| 773 | webserver_details['public_ipv4_address'] = ( |
| 774 | instance_network[0]['addr']) |
| 775 | |
| 776 | return webserver_details |
| 777 | |
| 778 | @classmethod |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 779 | def _install_start_webserver(cls, ip_address, ssh_key, start_id): |
| 780 | local_file = pkg_resources.resource_filename( |
| 781 | 'octavia_tempest_plugin.contrib.httpd', 'httpd.bin') |
| 782 | dest_file = '/dev/shm/httpd.bin' |
| 783 | |
| 784 | linux_client = remote_client.RemoteClient( |
| 785 | ip_address, CONF.validation.image_ssh_user, pkey=ssh_key) |
| 786 | linux_client.validate_authentication() |
| 787 | |
| 788 | with tempfile.NamedTemporaryFile() as key: |
| 789 | key.write(ssh_key.encode('utf-8')) |
| 790 | key.flush() |
| 791 | cmd = ("scp -v -o UserKnownHostsFile=/dev/null " |
| 792 | "-o StrictHostKeyChecking=no " |
| 793 | "-o ConnectTimeout={0} -o ConnectionAttempts={1} " |
| 794 | "-i {2} {3} {4}@{5}:{6}").format( |
| 795 | CONF.load_balancer.scp_connection_timeout, |
| 796 | CONF.load_balancer.scp_connection_attempts, |
| 797 | key.name, local_file, CONF.validation.image_ssh_user, |
| 798 | ip_address, dest_file) |
| 799 | args = shlex.split(cmd) |
| 800 | subprocess_args = {'stdout': subprocess.PIPE, |
| 801 | 'stderr': subprocess.STDOUT, |
| 802 | 'cwd': None} |
| 803 | proc = subprocess.Popen(args, **subprocess_args) |
| 804 | stdout, stderr = proc.communicate() |
| 805 | if proc.returncode != 0: |
| 806 | raise exceptions.CommandFailed(proc.returncode, cmd, |
| 807 | stdout, stderr) |
Gregory Thiemonge | f72a886 | 2019-08-06 17:25:42 +0200 | [diff] [blame^] | 808 | |
| 809 | # Enabling memory overcommit allows to run golang static binaries |
| 810 | # compiled with a recent golang toolchain (>=1.11). Those binaries |
| 811 | # allocate a large amount of virtual memory at init time, and this |
| 812 | # allocation fails in tempest's nano flavor (64MB of RAM) |
| 813 | # (golang issue reported in https://github.com/golang/go/issues/28114, |
| 814 | # follow-up: https://github.com/golang/go/issues/28081) |
| 815 | # TODO(gthiemonge): Remove this call when golang issue is resolved. |
| 816 | linux_client.exec_command('sudo sh -c "echo 1 > ' |
| 817 | '/proc/sys/vm/overcommit_memory"') |
| 818 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 819 | linux_client.exec_command('sudo screen -d -m {0} -port 80 ' |
| 820 | '-id {1}'.format(dest_file, start_id)) |
| 821 | linux_client.exec_command('sudo screen -d -m {0} -port 81 ' |
| 822 | '-id {1}'.format(dest_file, start_id + 1)) |
| 823 | |
Michael Johnson | bf916df | 2018-10-17 10:59:28 -0700 | [diff] [blame] | 824 | # Cirros does not configure the assigned IPv6 address by default |
| 825 | # so enable it manually like tempest does here: |
| 826 | # tempest/scenario/test_netowrk_v6.py turn_nic6_on() |
| 827 | @classmethod |
| 828 | def _enable_ipv6_nic_webserver(cls, ip_address, ssh_key, |
| 829 | ipv6_address, ipv6_prefix): |
| 830 | linux_client = remote_client.RemoteClient( |
| 831 | ip_address, CONF.validation.image_ssh_user, pkey=ssh_key) |
| 832 | linux_client.validate_authentication() |
| 833 | |
| 834 | linux_client.exec_command('sudo ip address add {0}/{1} dev ' |
| 835 | 'eth0'.format(ipv6_address, ipv6_prefix)) |
| 836 | |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 837 | @classmethod |
Jude Cross | 986e3f5 | 2017-07-24 14:57:20 -0700 | [diff] [blame] | 838 | def _validate_webserver(cls, ip_address, start_id): |
| 839 | URL = 'http://{0}'.format(ip_address) |
| 840 | validators.validate_URL_response(URL, expected_body=str(start_id)) |
| 841 | URL = 'http://{0}:81'.format(ip_address) |
| 842 | validators.validate_URL_response(URL, expected_body=str(start_id + 1)) |
| 843 | |
Michael Johnson | 0a0f9b3 | 2019-01-02 16:58:21 -0800 | [diff] [blame] | 844 | def _wait_for_lb_functional(self, vip_address, |
| 845 | protocol='http', verify=True): |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 846 | session = requests.Session() |
| 847 | start = time.time() |
| 848 | |
| 849 | while time.time() - start < CONF.load_balancer.build_timeout: |
| 850 | try: |
Michael Johnson | 0a0f9b3 | 2019-01-02 16:58:21 -0800 | [diff] [blame] | 851 | session.get("{0}://{1}".format(protocol, vip_address), |
| 852 | timeout=2, verify=verify) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 853 | time.sleep(1) |
| 854 | return |
| 855 | except Exception: |
| 856 | LOG.warning('Server is not passing initial traffic. Waiting.') |
| 857 | time.sleep(1) |
| 858 | LOG.error('Server did not begin passing traffic within the timeout ' |
| 859 | 'period. Failing test.') |
| 860 | raise Exception() |
| 861 | |
Michael Johnson | 0a0f9b3 | 2019-01-02 16:58:21 -0800 | [diff] [blame] | 862 | def check_members_balanced(self, vip_address, traffic_member_count=2, |
| 863 | protocol='http', verify=True): |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 864 | session = requests.Session() |
| 865 | response_counts = {} |
| 866 | |
Michael Johnson | 5a16ad3 | 2018-10-18 14:49:11 -0700 | [diff] [blame] | 867 | if ipaddress.ip_address(vip_address).version == 6: |
| 868 | vip_address = '[{}]'.format(vip_address) |
| 869 | |
Michael Johnson | 0a0f9b3 | 2019-01-02 16:58:21 -0800 | [diff] [blame] | 870 | self._wait_for_lb_functional(vip_address, protocol, verify) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 871 | |
| 872 | # Send a number requests to lb vip |
| 873 | for i in range(20): |
| 874 | try: |
Michael Johnson | 0a0f9b3 | 2019-01-02 16:58:21 -0800 | [diff] [blame] | 875 | r = session.get('{0}://{1}'.format(protocol, vip_address), |
| 876 | timeout=2, verify=verify) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 877 | |
| 878 | if r.content in response_counts: |
| 879 | response_counts[r.content] += 1 |
| 880 | else: |
| 881 | response_counts[r.content] = 1 |
| 882 | |
| 883 | except Exception: |
| 884 | LOG.exception('Failed to send request to loadbalancer vip') |
| 885 | raise Exception('Failed to connect to lb') |
| 886 | |
| 887 | LOG.debug('Loadbalancer response totals: %s', response_counts) |
| 888 | # Ensure the correct number of members |
Adam Harwell | 60ed9d9 | 2018-05-10 13:23:13 -0700 | [diff] [blame] | 889 | self.assertEqual(traffic_member_count, len(response_counts)) |
Adam Harwell | cd72b56 | 2018-05-07 11:37:22 -0700 | [diff] [blame] | 890 | |
| 891 | # Ensure both members got the same number of responses |
| 892 | self.assertEqual(1, len(set(response_counts.values()))) |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 893 | |
| 894 | def assertConsistentResponse(self, response, url, method='GET', repeat=10, |
| 895 | redirect=False, timeout=2, **kwargs): |
| 896 | """Assert that a request to URL gets the expected response. |
| 897 | |
| 898 | :param response: Expected response in format (status_code, content). |
| 899 | :param url: The URL to request. |
| 900 | :param method: The HTTP method to use (GET, POST, PUT, etc) |
| 901 | :param repeat: How many times to test the response. |
| 902 | :param data: Optional data to send in the request. |
| 903 | :param headers: Optional headers to send in the request. |
| 904 | :param cookies: Optional cookies to send in the request. |
| 905 | :param redirect: Is the request a redirect? If true, assume the passed |
| 906 | content should be the next URL in the chain. |
Carlos Goncalves | c451ff9 | 2018-12-19 19:11:53 +0100 | [diff] [blame] | 907 | :param timeout: Optional seconds to wait for the server to send data. |
| 908 | |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 909 | :return: boolean success status |
| 910 | |
| 911 | :raises: testtools.matchers.MismatchError |
| 912 | """ |
| 913 | session = requests.Session() |
| 914 | response_code, response_content = response |
| 915 | |
| 916 | for i in range(0, repeat): |
| 917 | req = session.request(method, url, allow_redirects=not redirect, |
| 918 | timeout=timeout, **kwargs) |
| 919 | if response_code: |
| 920 | self.assertEqual(response_code, req.status_code) |
| 921 | if redirect: |
| 922 | self.assertTrue(req.is_redirect) |
Carlos Goncalves | c451ff9 | 2018-12-19 19:11:53 +0100 | [diff] [blame] | 923 | self.assertEqual(response_content, |
| 924 | session.get_redirect_target(req)) |
Adam Harwell | e029af2 | 2018-05-24 17:13:28 -0700 | [diff] [blame] | 925 | elif response_content: |
| 926 | self.assertEqual(six.text_type(response_content), req.text) |