| 1 |
# Copyright (c) 2017 Midokura SARL |
| 2 |
# All Rights Reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
|
| 16 |
import netaddr |
| 17 |
from oslo_config import cfg |
| 18 |
import testtools |
| 19 |
|
| 20 |
from neutron_lib.utils import test |
| 21 |
from tempest.common import utils |
| 22 |
from tempest.common import waiters |
| 23 |
from tempest.lib.common import ssh |
| 24 |
from tempest.lib.common.utils import data_utils |
| 25 |
from tempest.lib import decorators |
| 26 |
|
| 27 |
from neutron_tempest_plugin import config |
| 28 |
from neutron_tempest_plugin.scenario import constants |
| 29 |
from neutron_tempest_plugin.vpnaas.scenario import base_vpnaas as base |
| 30 |
|
| 31 |
|
| 32 |
CONF = config.CONF |
| 33 |
|
| 34 |
# NOTE(huntxu): This is a workaround due to a upstream bug [1]. |
| 35 |
# VPNaaS 4in6 and 6in4 is not working properly with LibreSwan 3.19+. |
| 36 |
# In OpenStack zuul checks the base CentOS 7 node is using Libreswan 3.20 on |
| 37 |
# CentOS 7.4. So we need to provide a way to skip the 4in6 and 6in4 test cases |
| 38 |
# for zuul. |
| 39 |
# |
| 40 |
# Once the upstream bug gets fixed and the base node uses a newer version of |
| 41 |
# Libreswan with that fix, we can remove this. |
| 42 |
# |
| 43 |
# [1] https://github.com/libreswan/libreswan/issues/175 |
| 44 |
CONF.register_opt( |
| 45 |
cfg.BoolOpt('skip_4in6_6in4_tests', |
| 46 |
default=False, |
| 47 |
help='Whether to skip 4in6 and 6in4 test cases.'), |
| 48 |
'neutron_vpnaas_plugin_options' |
| 49 |
) |
| 50 |
|
| 51 |
# The VPNaaS drivers for OVN don't support IPv6 VMs |
| 52 |
CONF.register_opt( |
| 53 |
cfg.BoolOpt('skip_6in4_tests', |
| 54 |
default=False, |
| 55 |
help='Whether to skip 6in4 test cases.'), |
| 56 |
'neutron_vpnaas_plugin_options' |
| 57 |
) |
| 58 |
CONF.register_opt( |
| 59 |
cfg.BoolOpt('skip_6in6_tests', |
| 60 |
default=False, |
| 61 |
help='Whether to skip 6in6 test cases.'), |
| 62 |
'neutron_vpnaas_plugin_options' |
| 63 |
) |
| 64 |
|
| 65 |
|
| 66 |
class Vpnaas(base.BaseTempestTestCase): |
| 67 |
"""Test the following topology |
| 68 |
|
| 69 |
.. code-block:: HTML |
| 70 |
|
| 71 |
+-------------------+ |
| 72 |
| public | |
| 73 |
| network | |
| 74 |
| | |
| 75 |
+-+---------------+-+ |
| 76 |
| | |
| 77 |
| | |
| 78 |
+-------+-+ +-+-------+ |
| 79 |
| LEFT | | RIGHT | |
| 80 |
| router | <--VPN--> | router | |
| 81 |
| | | | |
| 82 |
+----+----+ +----+----+ |
| 83 |
| | |
| 84 |
+----+----+ +----+----+ |
| 85 |
| LEFT | | RIGHT | |
| 86 |
| network | | network | |
| 87 |
| | | | |
| 88 |
+---------+ +---------+ |
| 89 |
""" |
| 90 |
|
| 91 |
credentials = ['primary', 'admin'] |
| 92 |
inner_ipv6 = False |
| 93 |
outer_ipv6 = False |
| 94 |
|
| 95 |
@classmethod |
| 96 |
@utils.requires_ext(extension="vpnaas", service="network") |
| 97 |
def resource_setup(cls): |
| 98 |
super(Vpnaas, cls).resource_setup() |
| 99 |
|
| 100 |
# common |
| 101 |
cls.keypair = cls.create_keypair() |
| 102 |
cls.secgroup = cls.os_primary.network_client.create_security_group( |
| 103 |
name=data_utils.rand_name('secgroup-'))['security_group'] |
| 104 |
cls.security_groups.append(cls.secgroup) |
| 105 |
cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id']) |
| 106 |
cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id']) |
| 107 |
cls.ikepolicy = cls.create_ikepolicy( |
| 108 |
data_utils.rand_name("ike-policy-")) |
| 109 |
cls.ipsecpolicy = cls.create_ipsecpolicy( |
| 110 |
data_utils.rand_name("ipsec-policy-")) |
| 111 |
|
| 112 |
cls.extra_subnet_attributes = {} |
| 113 |
if cls.inner_ipv6: |
| 114 |
cls.create_v6_pingable_secgroup_rule( |
| 115 |
secgroup_id=cls.secgroup['id']) |
| 116 |
cls.extra_subnet_attributes['ipv6_address_mode'] = 'slaac' |
| 117 |
cls.extra_subnet_attributes['ipv6_ra_mode'] = 'slaac' |
| 118 |
|
| 119 |
# LEFT |
| 120 |
cls.router = cls.create_router( |
| 121 |
data_utils.rand_name('left-router'), |
| 122 |
admin_state_up=True, |
| 123 |
external_network_id=CONF.network.public_network_id) |
| 124 |
cls.network = cls.create_network(network_name='left-network') |
| 125 |
ip_version = 6 if cls.inner_ipv6 else 4 |
| 126 |
v4_cidr = netaddr.IPNetwork('10.20.0.0/24') |
| 127 |
v6_cidr = netaddr.IPNetwork('2001:db8:0:2::/64') |
| 128 |
cidr = v6_cidr if cls.inner_ipv6 else v4_cidr |
| 129 |
cls.subnet = cls.create_subnet( |
| 130 |
cls.network, ip_version=ip_version, cidr=cidr, name='left-subnet', |
| 131 |
**cls.extra_subnet_attributes) |
| 132 |
cls.create_router_interface(cls.router['id'], cls.subnet['id']) |
| 133 |
|
| 134 |
# Gives an internal IPv4 subnet for floating IP to the left server, |
| 135 |
# we use it to ssh into the left server. |
| 136 |
if cls.inner_ipv6: |
| 137 |
v4_subnet = cls.create_subnet( |
| 138 |
cls.network, ip_version=4, name='left-v4-subnet') |
| 139 |
cls.create_router_interface(cls.router['id'], v4_subnet['id']) |
| 140 |
|
| 141 |
# RIGHT |
| 142 |
cls._right_network, cls._right_subnet, cls._right_router = \ |
| 143 |
cls._create_right_network() |
| 144 |
|
| 145 |
@classmethod |
| 146 |
def create_v6_pingable_secgroup_rule(cls, secgroup_id=None, client=None): |
| 147 |
# NOTE(huntxu): This method should be moved into the base class, along |
| 148 |
# with the v4 version. |
| 149 |
"""This rule is intended to permit inbound ping6""" |
| 150 |
|
| 151 |
rule_list = [{'protocol': 'ipv6-icmp', |
| 152 |
'direction': 'ingress', |
| 153 |
'port_range_min': 128, # type |
| 154 |
'port_range_max': 0, # code |
| 155 |
'ethertype': 'IPv6', |
| 156 |
'remote_ip_prefix': '::/0'}] |
| 157 |
client = client or cls.os_primary.network_client |
| 158 |
cls.create_secgroup_rules(rule_list, client=client, |
| 159 |
secgroup_id=secgroup_id) |
| 160 |
|
| 161 |
@classmethod |
| 162 |
def _create_right_network(cls): |
| 163 |
router = cls.create_router( |
| 164 |
data_utils.rand_name('right-router'), |
| 165 |
admin_state_up=True, |
| 166 |
external_network_id=CONF.network.public_network_id) |
| 167 |
network = cls.create_network(network_name='right-network') |
| 168 |
v4_cidr = netaddr.IPNetwork('10.10.0.0/24') |
| 169 |
v6_cidr = netaddr.IPNetwork('2001:db8:0:1::/64') |
| 170 |
cidr = v6_cidr if cls.inner_ipv6 else v4_cidr |
| 171 |
ip_version = 6 if cls.inner_ipv6 else 4 |
| 172 |
subnet = cls.create_subnet( |
| 173 |
network, ip_version=ip_version, cidr=cidr, name='right-subnet', |
| 174 |
**cls.extra_subnet_attributes) |
| 175 |
cls.create_router_interface(router['id'], subnet['id']) |
| 176 |
|
| 177 |
return network, subnet, router |
| 178 |
|
| 179 |
def _create_server(self, create_floating_ip=True, network=None): |
| 180 |
if network is None: |
| 181 |
network = self.network |
| 182 |
port = self.create_port(network, security_groups=[self.secgroup['id']]) |
| 183 |
if create_floating_ip: |
| 184 |
fip = self.create_and_associate_floatingip(port['id']) |
| 185 |
else: |
| 186 |
fip = None |
| 187 |
server = self.create_server( |
| 188 |
flavor_ref=CONF.compute.flavor_ref, |
| 189 |
image_ref=CONF.compute.image_ref, |
| 190 |
key_name=self.keypair['name'], |
| 191 |
networks=[{'port': port['id']}])['server'] |
| 192 |
waiters.wait_for_server_status(self.os_primary.servers_client, |
| 193 |
server['id'], |
| 194 |
constants.SERVER_STATUS_ACTIVE) |
| 195 |
return {'port': port, 'fip': fip, 'server': server} |
| 196 |
|
| 197 |
def _setup_vpn(self): |
| 198 |
sites = [ |
| 199 |
dict(name="left", network=self.network, subnet=self.subnet, |
| 200 |
router=self.router), |
| 201 |
dict(name="right", network=self._right_network, |
| 202 |
subnet=self._right_subnet, router=self._right_router), |
| 203 |
] |
| 204 |
psk = data_utils.rand_name('mysecret') |
| 205 |
for i in range(0, 2): |
| 206 |
site = sites[i] |
| 207 |
site['vpnservice'] = self.create_vpnservice( |
| 208 |
site['subnet']['id'], site['router']['id'], |
| 209 |
name=data_utils.rand_name('%s-vpnservice' % site['name'])) |
| 210 |
for i in range(0, 2): |
| 211 |
site = sites[i] |
| 212 |
vpnservice = site['vpnservice'] |
| 213 |
peer = sites[1 - i] |
| 214 |
if self.outer_ipv6: |
| 215 |
peer_address = peer['vpnservice']['external_v6_ip'] |
| 216 |
if not peer_address: |
| 217 |
msg = "Public network must have an IPv6 subnet." |
| 218 |
raise self.skipException(msg) |
| 219 |
else: |
| 220 |
peer_address = peer['vpnservice']['external_v4_ip'] |
| 221 |
self.create_ipsec_site_connection( |
| 222 |
self.ikepolicy['id'], |
| 223 |
self.ipsecpolicy['id'], |
| 224 |
vpnservice['id'], |
| 225 |
peer_address=peer_address, |
| 226 |
peer_id=peer_address, |
| 227 |
peer_cidrs=[peer['subnet']['cidr']], |
| 228 |
psk=psk, |
| 229 |
name=data_utils.rand_name( |
| 230 |
'%s-ipsec-site-connection' % site['name'])) |
| 231 |
|
| 232 |
def _get_ip_on_subnet_for_port(self, port, subnet_id): |
| 233 |
for fixed_ip in port['fixed_ips']: |
| 234 |
if fixed_ip['subnet_id'] == subnet_id: |
| 235 |
return fixed_ip['ip_address'] |
| 236 |
msg = "Cannot get IP address on specified subnet %s for port %r." % ( |
| 237 |
subnet_id, port) |
| 238 |
raise self.fail(msg) |
| 239 |
|
| 240 |
@test.unstable_test("bug 1882220") |
| 241 |
def _test_vpnaas(self): |
| 242 |
# RIGHT |
| 243 |
right_server = self._create_server(network=self._right_network, |
| 244 |
create_floating_ip=False) |
| 245 |
right_ip = self._get_ip_on_subnet_for_port( |
| 246 |
right_server['port'], self._right_subnet['id']) |
| 247 |
|
| 248 |
# LEFT |
| 249 |
left_server = self._create_server() |
| 250 |
ssh_client = ssh.Client(left_server['fip']['floating_ip_address'], |
| 251 |
CONF.validation.image_ssh_user, |
| 252 |
pkey=self.keypair['private_key'], |
| 253 |
ssh_key_type=CONF.validation.ssh_key_type) |
| 254 |
|
| 255 |
# check LEFT -> RIGHT connectivity via VPN |
| 256 |
self.check_remote_connectivity(ssh_client, right_ip, |
| 257 |
should_succeed=False) |
| 258 |
self._setup_vpn() |
| 259 |
self.check_remote_connectivity(ssh_client, right_ip) |
| 260 |
|
| 261 |
# Test VPN traffic and floating IP traffic don't interfere each other. |
| 262 |
if not self.inner_ipv6: |
| 263 |
# Assign a floating-ip and check connectivity. |
| 264 |
# This is NOT via VPN. |
| 265 |
fip = self.create_and_associate_floatingip( |
| 266 |
right_server['port']['id']) |
| 267 |
self.check_remote_connectivity(ssh_client, |
| 268 |
fip['floating_ip_address']) |
| 269 |
|
| 270 |
# check LEFT -> RIGHT connectivity via VPN again, to ensure |
| 271 |
# the above floating-ip doesn't interfere the traffic. |
| 272 |
self.check_remote_connectivity(ssh_client, right_ip) |
| 273 |
|
| 274 |
|
| 275 |
class Vpnaas4in4(Vpnaas): |
| 276 |
|
| 277 |
@decorators.idempotent_id('aa932ab2-63aa-49cf-a2a0-8ae71ac2bc24') |
| 278 |
def test_vpnaas(self): |
| 279 |
self._test_vpnaas() |
| 280 |
|
| 281 |
|
| 282 |
class Vpnaas4in6(Vpnaas): |
| 283 |
outer_ipv6 = True |
| 284 |
|
| 285 |
@decorators.idempotent_id('2d5f18dc-6186-4deb-842b-051325bd0466') |
| 286 |
@testtools.skipUnless(CONF.network_feature_enabled.ipv6, |
| 287 |
'IPv6 tests are disabled.') |
| 288 |
@testtools.skipIf( |
| 289 |
CONF.neutron_vpnaas_plugin_options.skip_4in6_6in4_tests, |
| 290 |
'VPNaaS 4in6 test is skipped.') |
| 291 |
def test_vpnaas_4in6(self): |
| 292 |
self._test_vpnaas() |
| 293 |
|
| 294 |
|
| 295 |
class Vpnaas6in4(Vpnaas): |
| 296 |
inner_ipv6 = True |
| 297 |
|
| 298 |
@decorators.idempotent_id('10febf33-c5b7-48af-aa13-94b4fb585a55') |
| 299 |
@testtools.skipUnless(CONF.network_feature_enabled.ipv6, |
| 300 |
'IPv6 tests are disabled.') |
| 301 |
@testtools.skipIf( |
| 302 |
CONF.neutron_vpnaas_plugin_options.skip_4in6_6in4_tests, |
| 303 |
'VPNaaS 6in4 test is skipped.') |
| 304 |
@testtools.skipIf( |
| 305 |
CONF.neutron_vpnaas_plugin_options.skip_6in4_tests, |
| 306 |
'VPNaaS 6in4 test is skipped.') |
| 307 |
def test_vpnaas_6in4(self): |
| 308 |
self._test_vpnaas() |
| 309 |
|
| 310 |
|
| 311 |
class Vpnaas6in6(Vpnaas): |
| 312 |
inner_ipv6 = True |
| 313 |
outer_ipv6 = True |
| 314 |
|
| 315 |
@decorators.idempotent_id('8b503ffc-aeb0-4938-8dba-73c7323e276d') |
| 316 |
@testtools.skipUnless(CONF.network_feature_enabled.ipv6, |
| 317 |
'IPv6 tests are disabled.') |
| 318 |
@testtools.skipIf( |
| 319 |
CONF.neutron_vpnaas_plugin_options.skip_6in6_tests, |
| 320 |
'VPNaaS 6in6 test is skipped.') |
| 321 |
def test_vpnaas_6in6(self): |
| 322 |
self._test_vpnaas() |