| 1 |
# 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 |
from unittest import mock |
| 16 |
|
| 17 |
import netaddr |
| 18 |
from neutron.agent.linux import ip_lib |
| 19 |
from neutron.common import config as common_config |
| 20 |
from neutron.common.ovn import constants as ovn_const |
| 21 |
from neutron.conf.agent import common as agent_conf |
| 22 |
from neutron.conf import common as common_conf |
| 23 |
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf |
| 24 |
from neutron.conf.plugins.ml2.drivers import ovs_conf |
| 25 |
from neutron.tests.common import net_helpers |
| 26 |
from neutron.tests.functional import base |
| 27 |
from neutron_lib import constants as lib_constants |
| 28 |
from neutron_lib.plugins import constants as plugin_constants |
| 29 |
from neutron_lib.plugins import directory |
| 30 |
from neutron_lib.utils import helpers |
| 31 |
from oslo_config import cfg |
| 32 |
from ovsdbapp.backend.ovs_idl import event |
| 33 |
|
| 34 |
from neutron_vpnaas.agent.ovn.vpn import agent |
| 35 |
from neutron_vpnaas.agent.ovn.vpn import ovsdb |
| 36 |
from neutron_vpnaas.services.vpn.common import constants as vpn_const |
| 37 |
from neutron_vpnaas.services.vpn.device_drivers import ipsec |
| 38 |
from neutron_vpnaas.services.vpn import ovn_agent |
| 39 |
from neutron_vpnaas.services.vpn.service_drivers import ovn_ipsec |
| 40 |
|
| 41 |
|
| 42 |
OVS_INTERFACE_DRIVER = 'neutron.agent.linux.interface.OVSInterfaceDriver' |
| 43 |
IPSEC_SERVICE_PROVIDER = ('VPN:ovn:neutron_vpnaas.services.vpn.' |
| 44 |
'service_drivers.ovn_ipsec.IPsecOvnVPNDriver:' |
| 45 |
'default') |
| 46 |
VPN_PLUGIN = 'neutron_vpnaas.services.vpn.ovn_plugin.VPNOVNDriverPlugin' |
| 47 |
|
| 48 |
PUBLIC_NET = netaddr.IPNetwork('19.4.4.0/24') |
| 49 |
LOCAL_NETS = list(netaddr.IPNetwork('10.0.0.0/16').subnet(24)) |
| 50 |
PEER_NET = netaddr.IPNetwork('10.1.0.0/16') |
| 51 |
PEER_ADDR = '19.4.5.6' |
| 52 |
|
| 53 |
|
| 54 |
class VPNAgentHealthEvent(event.WaitEvent): |
| 55 |
event_name = 'VPNAgentHealthEvent' |
| 56 |
|
| 57 |
def __init__(self, chassis, sb_cfg, table, timeout=5): |
| 58 |
self.chassis = chassis |
| 59 |
self.sb_cfg = sb_cfg |
| 60 |
super().__init__( |
| 61 |
(self.ROW_UPDATE,), table, (('name', '=', self.chassis),), |
| 62 |
timeout=timeout) |
| 63 |
|
| 64 |
def matches(self, event, row, old=None): |
| 65 |
if not super().matches(event, row, old): |
| 66 |
return False |
| 67 |
return int(row.external_ids.get( |
| 68 |
vpn_const.OVN_AGENT_VPN_SB_CFG_KEY, 0)) >= self.sb_cfg |
| 69 |
|
| 70 |
|
| 71 |
class OvnSiteInfo: |
| 72 |
def __init__(self, parent, index, ext_net, ext_sub): |
| 73 |
self.ext_net = ext_net |
| 74 |
self.ext_sub = ext_sub |
| 75 |
self.parent = parent |
| 76 |
self.context = parent.context |
| 77 |
self.fmt = parent.fmt |
| 78 |
self.index = index |
| 79 |
|
| 80 |
def create_base(self): |
| 81 |
router_data = { |
| 82 |
'name': 'r%d' % self.index, |
| 83 |
'admin_state_up': True, |
| 84 |
'project_id': self.parent._tenant_id, |
| 85 |
'external_gateway_info': { |
| 86 |
'enable_snat': True, |
| 87 |
'network_id': self.ext_net['id'], |
| 88 |
'external_fixed_ips': [ |
| 89 |
{'ip_address': str(PUBLIC_NET[4 + 2 * self.index]), |
| 90 |
'subnet_id': self.ext_sub['id']} |
| 91 |
] |
| 92 |
} |
| 93 |
} |
| 94 |
self.router = self.parent.l3_plugin.create_router( |
| 95 |
self.context, {'router': router_data}) |
| 96 |
|
| 97 |
# local subnet |
| 98 |
private_net = LOCAL_NETS[self.index] |
| 99 |
self.local_cidr = str(private_net) |
| 100 |
|
| 101 |
net = self.parent._make_network(self.fmt, 'local%d' % self.index, True) |
| 102 |
self.local_net = net['network'] |
| 103 |
sub = self.parent._make_subnet(self.fmt, net, private_net[1], |
| 104 |
self.local_cidr, enable_dhcp=False) |
| 105 |
self.local_sub = sub['subnet'] |
| 106 |
interface_info = {'subnet_id': self.local_sub['id']} |
| 107 |
self.parent.l3_plugin.add_router_interface( |
| 108 |
self.context, self.router['id'], interface_info) |
| 109 |
|
| 110 |
def create_vpnservice(self): |
| 111 |
plugin = self.parent.vpn_plugin |
| 112 |
data = { |
| 113 |
'tenant_id': self.parent._tenant_id, |
| 114 |
'name': 'my-service', |
| 115 |
'description': 'new service', |
| 116 |
'subnet_id': self.local_sub['id'], |
| 117 |
'router_id': self.router['id'], |
| 118 |
'flavor_id': None, |
| 119 |
'admin_state_up': True, |
| 120 |
} |
| 121 |
self.vpnservice = plugin.create_vpnservice(self.context, |
| 122 |
{'vpnservice': data}) |
| 123 |
self.local_addr = self.vpnservice['external_v4_ip'] |
| 124 |
|
| 125 |
data = { |
| 126 |
'tenant_id': self.parent._tenant_id, |
| 127 |
'name': 'ikepolicy%d' % self.index, |
| 128 |
'description': '', |
| 129 |
'auth_algorithm': 'sha1', |
| 130 |
'encryption_algorithm': 'aes-128', |
| 131 |
'phase1_negotiation_mode': 'main', |
| 132 |
'ike_version': 'v1', |
| 133 |
'pfs': 'group5', |
| 134 |
'lifetime': {'units': 'seconds', 'value': 3600}, |
| 135 |
} |
| 136 |
self.ikepolicy = plugin.create_ikepolicy(self.context, |
| 137 |
{'ikepolicy': data}) |
| 138 |
|
| 139 |
data = { |
| 140 |
'tenant_id': self.parent._tenant_id, |
| 141 |
'name': 'ipsecpolicy%d' % self.index, |
| 142 |
'description': '', |
| 143 |
'transform_protocol': 'esp', |
| 144 |
'auth_algorithm': 'sha1', |
| 145 |
'encryption_algorithm': 'aes-128', |
| 146 |
'encapsulation_mode': 'tunnel', |
| 147 |
'pfs': 'group5', |
| 148 |
'lifetime': {'units': 'seconds', 'value': 3600}, |
| 149 |
} |
| 150 |
self.ipsecpolicy = plugin.create_ipsecpolicy(self.context, |
| 151 |
{'ipsecpolicy': data}) |
| 152 |
|
| 153 |
def create_site_connection(self, peer_addr, peer_cidr): |
| 154 |
data = { |
| 155 |
'tenant_id': self.parent._tenant_id, |
| 156 |
'name': 'conn%d' % self.index, |
| 157 |
'description': '', |
| 158 |
'local_id': self.local_addr, |
| 159 |
'peer_address': peer_addr, |
| 160 |
'peer_id': peer_addr, |
| 161 |
'peer_cidrs': [peer_cidr], |
| 162 |
'mtu': 1500, |
| 163 |
'initiator': 'bi-directional', |
| 164 |
'auth_mode': 'psk', |
| 165 |
'psk': 'secret', |
| 166 |
'dpd': { |
| 167 |
'action': 'hold', |
| 168 |
'interval': 30, |
| 169 |
'timeout': 120, |
| 170 |
}, |
| 171 |
'admin_state_up': True, |
| 172 |
'vpnservice_id': self.vpnservice['id'], |
| 173 |
'ikepolicy_id': self.ikepolicy['id'], |
| 174 |
'ipsecpolicy_id': self.ipsecpolicy['id'], |
| 175 |
'local_ep_group_id': None, |
| 176 |
'peer_ep_group_id': None, |
| 177 |
} |
| 178 |
self.siteconn = self.parent.vpn_plugin.create_ipsec_site_connection( |
| 179 |
self.context, {'ipsec_site_connection': data}) |
| 180 |
|
| 181 |
|
| 182 |
class TestOvnVPNAgentBase(base.TestOVNFunctionalBase): |
| 183 |
FAKE_CHASSIS_HOST = 'ovn-host-fake' |
| 184 |
|
| 185 |
def setUp(self): |
| 186 |
self.skipTest('This test is skipped after the eventlet removal and ' |
| 187 |
'needs to be refactored') |
| 188 |
cfg.CONF.set_override('service_provider', [IPSEC_SERVICE_PROVIDER], |
| 189 |
group='service_providers') |
| 190 |
service_plugins = {'vpnaas_plugin': VPN_PLUGIN} |
| 191 |
super().setUp(service_plugins=service_plugins) |
| 192 |
common_config.register_common_config_options() |
| 193 |
|
| 194 |
self.mock_ovsdb_idl = mock.Mock() |
| 195 |
mock_instance = mock.Mock() |
| 196 |
mock_instance.start.return_value = self.mock_ovsdb_idl |
| 197 |
mock_ovs_idl = mock.patch.object(ovsdb, 'VPNAgentOvsIdl').start() |
| 198 |
mock_ovs_idl.return_value = mock_instance |
| 199 |
|
| 200 |
self.vpn_plugin = directory.get_plugin(plugin_constants.VPN) |
| 201 |
# normally called in post_for_initialize |
| 202 |
self.vpn_plugin.watch_agent_events() |
| 203 |
self.vpn_service_driver = self.vpn_plugin.drivers['ovn'] |
| 204 |
|
| 205 |
self.handler = self.sb_api.idl.notify_handler |
| 206 |
self.agent = self._start_vpn_agent() |
| 207 |
self.agent_driver = self.agent.device_drivers[0] |
| 208 |
|
| 209 |
def _start_vpn_agent(self): |
| 210 |
# Set up a ConfigOpts separate to cfg.CONF in order to avoid conflicts |
| 211 |
# with other tests. |
| 212 |
# The OVN VPN agent registers a different variant of |
| 213 |
# vpnagent.vpn_device_drivers than the L3 agent extension. |
| 214 |
conf = agent_conf.setup_conf() |
| 215 |
conf.register_opts(ovn_conf.ovn_opts, group='ovn') |
| 216 |
conf.register_opts(ipsec.ipsec_opts, 'ipsec') |
| 217 |
common_conf.register_core_common_config_opts(conf) |
| 218 |
ovs_conf.register_ovs_opts(conf) |
| 219 |
ovn_agent.register_opts(conf) |
| 220 |
agent_conf.register_process_monitor_opts(conf) |
| 221 |
agent_conf.setup_privsep() |
| 222 |
|
| 223 |
conf.set_override('state_path', self.get_default_temp_dir().path) |
| 224 |
conf.set_override('interface_driver', OVS_INTERFACE_DRIVER) |
| 225 |
conf.set_override('vpn_device_driver', [self.VPN_DEVICE_DRIVER], |
| 226 |
group='vpnagent') |
| 227 |
|
| 228 |
ovn_sb_db = self.ovsdb_server_mgr.get_ovsdb_connection_path('sb') |
| 229 |
conf.set_override('ovn_sb_connection', ovn_sb_db, group='ovn') |
| 230 |
|
| 231 |
self.chassis_name = self.add_fake_chassis(self.FAKE_CHASSIS_HOST) |
| 232 |
mock.patch.object(agent.OvnVpnAgent, |
| 233 |
'_get_own_chassis_name', |
| 234 |
return_value=self.chassis_name).start() |
| 235 |
conf.set_override('host', self.FAKE_CHASSIS_HOST) |
| 236 |
|
| 237 |
self.br_int = self.useFixture(net_helpers.OVSBridgeFixture()).bridge |
| 238 |
conf.set_override('integration_bridge', self.br_int.br_name, 'OVS') |
| 239 |
|
| 240 |
# name prefix for namespaces managed by vpn agent |
| 241 |
# will be patched into device driver to make sure concurrent |
| 242 |
# tests don't interfere with each other |
| 243 |
# (a vpn agent will normally remove all unknown qvpn- namespaces) |
| 244 |
self.ns_prefix = 'qvpn-test-%s-' % helpers.get_random_string(8) |
| 245 |
|
| 246 |
agt = agent.OvnVpnAgent(conf) |
| 247 |
driver = agt.device_drivers[0] |
| 248 |
driver.agent_rpc = mock.Mock() |
| 249 |
# let initial sync get an empty list of vpnservices |
| 250 |
driver.agent_rpc.get_vpn_services_on_host.return_value = [] |
| 251 |
driver.devmgr.plugin = driver.agent_rpc |
| 252 |
driver.devmgr.OVN_NS_PREFIX = self.ns_prefix |
| 253 |
|
| 254 |
agt.start() |
| 255 |
self.addCleanup(agt.ovs_idl.ovsdb_connection.stop) |
| 256 |
self.addCleanup(agt.sb_idl.ovsdb_connection.stop) |
| 257 |
# let agent remove remaining vpn namespaces in cleanup |
| 258 |
self.addCleanup(driver._cleanup_stale_vpn_processes, []) |
| 259 |
|
| 260 |
return agt |
| 261 |
|
| 262 |
@property |
| 263 |
def agent_chassis_table(self): |
| 264 |
if self.agent.has_chassis_private: |
| 265 |
return 'Chassis_Private' |
| 266 |
return 'Chassis' |
| 267 |
|
| 268 |
def _make_ext_network(self): |
| 269 |
network = self._make_network( |
| 270 |
self.fmt, 'external-net', True, as_admin=True, |
| 271 |
arg_list=('router:external', |
| 272 |
'provider:network_type', |
| 273 |
'provider:physical_network'), |
| 274 |
**{'router:external': True, |
| 275 |
'provider:network_type': 'flat', |
| 276 |
'provider:physical_network': 'public'}) |
| 277 |
|
| 278 |
pools = [{'start': PUBLIC_NET[2], 'end': PUBLIC_NET[253]}] |
| 279 |
gateway = PUBLIC_NET[1] |
| 280 |
cidr = str(PUBLIC_NET) |
| 281 |
subnet = self._make_subnet(self.fmt, network, gateway, cidr, |
| 282 |
allocation_pools=pools, |
| 283 |
enable_dhcp=False) |
| 284 |
return network['network'], subnet['subnet'] |
| 285 |
|
| 286 |
def _find_lswitch_by_neutron_name(self, name): |
| 287 |
for row in self.nb_api._tables['Logical_Switch'].rows.values(): |
| 288 |
if (row.external_ids.get( |
| 289 |
ovn_const.OVN_NETWORK_NAME_EXT_ID_KEY) == name): |
| 290 |
return row |
| 291 |
|
| 292 |
def _find_transit_lswitch(self, router_id): |
| 293 |
name = ovn_ipsec.TRANSIT_NETWORK_PREFIX + router_id |
| 294 |
return self._find_lswitch_by_neutron_name(name) |
| 295 |
|
| 296 |
def _match_extids(self, row, expected): |
| 297 |
for key, value in expected.items(): |
| 298 |
if row.external_ids.get(key) != value: |
| 299 |
return False |
| 300 |
return True |
| 301 |
|
| 302 |
def _find_transit_ns_port(self, router_id, ports): |
| 303 |
name = ovn_ipsec.TRANSIT_PORT_PREFIX + router_id |
| 304 |
extids = {ovn_const.OVN_PORT_NAME_EXT_ID_KEY: name} |
| 305 |
|
| 306 |
for row in ports: |
| 307 |
if self._match_extids(row, extids): |
| 308 |
return row |
| 309 |
|
| 310 |
def _find_transit_router_port(self, router_id, network_name, ports): |
| 311 |
extids = { |
| 312 |
ovn_const.OVN_DEVID_EXT_ID_KEY: router_id, |
| 313 |
ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY: 'network:router_interface', |
| 314 |
ovn_const.OVN_NETWORK_NAME_EXT_ID_KEY: network_name, |
| 315 |
} |
| 316 |
for row in ports: |
| 317 |
if self._match_extids(row, extids): |
| 318 |
return row |
| 319 |
|
| 320 |
def _find_vpn_gw_port(self, router_id, ports): |
| 321 |
name = ovn_ipsec.VPN_GW_PORT_PREFIX + router_id |
| 322 |
extids = {ovn_const.OVN_PORT_NAME_EXT_ID_KEY: name} |
| 323 |
|
| 324 |
for row in ports: |
| 325 |
if self._match_extids(row, extids): |
| 326 |
return row |
| 327 |
|
| 328 |
def _find_lrouter_by_neutron_id(self, router_id): |
| 329 |
for row in self.nb_api._tables['Logical_Router'].rows.values(): |
| 330 |
if row.name == "neutron-" + router_id: |
| 331 |
return row |
| 332 |
|
| 333 |
def test_agent(self): |
| 334 |
chassis_row = self.sb_api.db_find( |
| 335 |
self.agent_chassis_table, |
| 336 |
('name', '=', self.chassis_name)).execute( |
| 337 |
check_error=True)[0] |
| 338 |
|
| 339 |
# Assert that, prior to creating a resource the VPN agent |
| 340 |
# didn't populate the external_ids from the Chassis |
| 341 |
self.assertNotIn(vpn_const.OVN_AGENT_VPN_SB_CFG_KEY, |
| 342 |
chassis_row['external_ids']) |
| 343 |
|
| 344 |
# Let's list the agents to force the nb_cfg to be bumped on NB |
| 345 |
# db, which will automatically increment the nb_cfg counter on |
| 346 |
# NB_Global and make ovn-controller copy it over to SB_Global. Upon |
| 347 |
# this event, VPN agent will update the external_ids on its |
| 348 |
# Chassis row to signal that it's healthy. |
| 349 |
|
| 350 |
row_event = VPNAgentHealthEvent(self.chassis_name, 1, |
| 351 |
self.agent_chassis_table) |
| 352 |
self.handler.watch_event(row_event) |
| 353 |
self.new_list_request('agents').get_response(self.api) |
| 354 |
|
| 355 |
# If we do not time out waiting for the event, then we are assured |
| 356 |
# that the VPN agent has populated the external_ids from the |
| 357 |
# chassis with the nb_cfg, 1 revisions when listing the agents. |
| 358 |
self.assertTrue(row_event.wait()) |
| 359 |
|
| 360 |
def test_service(self): |
| 361 |
r = self.new_list_request('agents').get_response(self.api) |
| 362 |
ext_net, ext_sub = self._make_ext_network() |
| 363 |
|
| 364 |
server = ovn_ipsec.IPsecVpnOvnDriverCallBack(self.vpn_service_driver) |
| 365 |
|
| 366 |
# Mock the controller side RPC client (prepare and cast) |
| 367 |
# to be able to check that "vpnservice_updated" will be called |
| 368 |
prepare_mock = mock.Mock() |
| 369 |
prepared_mock = mock.Mock() |
| 370 |
self.vpn_service_driver.agent_rpc.client.prepare = prepare_mock |
| 371 |
prepare_mock.return_value = prepared_mock |
| 372 |
|
| 373 |
# Create a site (router, network, subnet, vpnservice, site conn) |
| 374 |
site = OvnSiteInfo(self, 1, ext_net, ext_sub) |
| 375 |
site.create_base() |
| 376 |
site.create_vpnservice() |
| 377 |
site.create_site_connection(PEER_ADDR, str(PEER_NET)) |
| 378 |
|
| 379 |
# Check that the vpnservice_updated RPC was triggered towards |
| 380 |
# the agent |
| 381 |
prepare_mock.assert_called_once_with( |
| 382 |
server=self.FAKE_CHASSIS_HOST, |
| 383 |
version=self.vpn_service_driver.agent_rpc.target.version) |
| 384 |
prepared_mock.cast.assert_called_once_with( |
| 385 |
self.context, 'vpnservice_updated', |
| 386 |
router={'id': site.router['id']}) |
| 387 |
|
| 388 |
# Mock the agent->controller RPCs. Let them return data from the |
| 389 |
# actual VPN plugin |
| 390 |
def get_vpn_services_on_host(ctx, host): |
| 391 |
r = server.get_vpn_services_on_host(self.context, host) |
| 392 |
return r |
| 393 |
|
| 394 |
def get_vpn_transit_network_details(router_id): |
| 395 |
return server.get_vpn_transit_network_details( |
| 396 |
self.context, router_id) |
| 397 |
|
| 398 |
def get_subnet_info(subnet_id): |
| 399 |
return server.get_subnet_info(self.context, subnet_id) |
| 400 |
|
| 401 |
r = self.agent_driver.agent_rpc |
| 402 |
r.get_vpn_services_on_host.side_effect = get_vpn_services_on_host |
| 403 |
r.get_vpn_transit_network_details.side_effect = \ |
| 404 |
get_vpn_transit_network_details |
| 405 |
r.get_subnet_info.side_effect = get_subnet_info |
| 406 |
|
| 407 |
# Call the agent's vpnservice_updated as if it was coming from |
| 408 |
# the controller. |
| 409 |
for driver in self.agent.device_drivers: |
| 410 |
driver.vpnservice_updated(driver.context, |
| 411 |
router={'id': site.router['id']}) |
| 412 |
|
| 413 |
# Check that transit network and VPN gateway port are set up correctly |
| 414 |
# - transit network exists |
| 415 |
# - router port in transit network exists |
| 416 |
# - transit network port to be bound to chassis exists and |
| 417 |
# host is assigned |
| 418 |
# - VPN gateway port exists and host is assigned |
| 419 |
# - static route exists towards peer CIDR |
| 420 |
|
| 421 |
# expect transit network in NB |
| 422 |
transit_row = self._find_transit_lswitch(site.router['id']) |
| 423 |
self.assertIsNotNone(transit_row) |
| 424 |
|
| 425 |
# check the transit network router port exists |
| 426 |
transit_router_port = self._find_transit_router_port( |
| 427 |
site.router['id'], transit_row.name, transit_row.ports) |
| 428 |
self.assertIsNotNone(transit_router_port) |
| 429 |
|
| 430 |
# check that the namespace port in the transit network exists |
| 431 |
transit_ns_port = self._find_transit_ns_port(site.router['id'], |
| 432 |
transit_row.ports) |
| 433 |
self.assertIsNotNone(transit_ns_port) |
| 434 |
|
| 435 |
# check that the port has the requested-host option |
| 436 |
requested_host = transit_ns_port.options.get( |
| 437 |
ovn_const.LSP_OPTIONS_REQUESTED_CHASSIS_KEY) |
| 438 |
self.assertEqual(requested_host, self.FAKE_CHASSIS_HOST) |
| 439 |
|
| 440 |
# get vpn gateway port via external network lswitch |
| 441 |
ext_row = self._find_lswitch_by_neutron_name("external-net") |
| 442 |
self.assertIsNotNone(ext_row) |
| 443 |
|
| 444 |
vpn_gw_port = self._find_vpn_gw_port(site.router['id'], ext_row.ports) |
| 445 |
self.assertIsNotNone(vpn_gw_port) |
| 446 |
# check that vpn gateway port has the requested-host option |
| 447 |
requested_host = vpn_gw_port.options.get( |
| 448 |
ovn_const.LSP_OPTIONS_REQUESTED_CHASSIS_KEY) |
| 449 |
self.assertEqual(requested_host, self.FAKE_CHASSIS_HOST) |
| 450 |
|
| 451 |
# check that static route towards peer cidr is set |
| 452 |
router_row = self._find_lrouter_by_neutron_id(site.router['id']) |
| 453 |
self.assertIsNotNone(router_row) |
| 454 |
for r in router_row.static_routes: |
| 455 |
if r.ip_prefix == str(PEER_NET): |
| 456 |
route = r |
| 457 |
break |
| 458 |
else: |
| 459 |
route = None |
| 460 |
|
| 461 |
self.assertIsNotNone(route) |
| 462 |
self.assertEqual(route.nexthop, ovn_ipsec.VPN_TRANSIT_RIP) |
| 463 |
|
| 464 |
# Check agent side |
| 465 |
# - network namespace |
| 466 |
# - routes towards transit network's gateway IP |
| 467 |
# - devices and their IP addresses in the namespace |
| 468 |
ns_name = self.ns_prefix + site.router['id'] |
| 469 |
devlen = lib_constants.LINUX_DEV_LEN |
| 470 |
transit_dev = ('vr' + transit_ns_port.name)[:devlen] |
| 471 |
gw_dev = ('vg' + vpn_gw_port.name)[:devlen] |
| 472 |
self.assertTrue(ip_lib.network_namespace_exists(ns_name)) |
| 473 |
device = ip_lib.IPDevice(None, namespace=ns_name) |
| 474 |
routes = device.route.list_routes(lib_constants.IP_VERSION_4, |
| 475 |
proto='static', |
| 476 |
via=ovn_ipsec.VPN_TRANSIT_LIP) |
| 477 |
self.assertEqual(len(routes), 1) |
| 478 |
self.assertEqual(routes[0]['via'], ovn_ipsec.VPN_TRANSIT_LIP) |
| 479 |
self.assertEqual(routes[0]['cidr'], site.local_cidr) |
| 480 |
self.assertEqual(routes[0]['device'], transit_dev) |
| 481 |
|
| 482 |
# check addresses in namespace |
| 483 |
addrs = device.addr.list(ip_version=lib_constants.IP_VERSION_4) |
| 484 |
addrs_dict = {a['name']: a for a in addrs} |
| 485 |
self.assertIn(transit_dev, addrs_dict) |
| 486 |
self.assertEqual( |
| 487 |
addrs_dict[transit_dev]['cidr'], |
| 488 |
transit_ns_port.external_ids[ovn_const.OVN_CIDRS_EXT_ID_KEY]) |
| 489 |
|
| 490 |
self.assertIn(gw_dev, addrs_dict) |
| 491 |
self.assertEqual( |
| 492 |
addrs_dict[gw_dev]['cidr'], |
| 493 |
vpn_gw_port.external_ids[ovn_const.OVN_CIDRS_EXT_ID_KEY]) |