Browse Source

Remove delete_default_gateway from create_router

This change removes the delete_default_gateway function from
create_router call path and updates the synchronize function to update
proper VRF default gateways only when needed.

Change-Id: I874b3f15f39e914282d7b92a07af9024c39e916f
tags/2018.1.13^0
Alin Iorga 3 months ago
parent
commit
a00fbcd512
3 changed files with 85 additions and 17 deletions
  1. +10
    -5
      networking_arista/l3Plugin/arista_l3_driver.py
  2. +60
    -8
      networking_arista/l3Plugin/l3_arista.py
  3. +15
    -4
      networking_arista/tests/unit/l3Plugin/test_arista_l3_driver.py

+ 10
- 5
networking_arista/l3Plugin/arista_l3_driver.py View File

@@ -180,9 +180,17 @@ class AristaL3Driver(object):
self.add_router_interface(ctx, router_info)
self._setup_default_gateway(router_info)

def _reset_network_default_route(self, network_id):
router_info = self._prepare_network_default_gateway(network_id)
if router_info:
router_name = self._arista_router_name(router_info['id'],
router_info['name'])
self._delete_default_gateway(router_name)
self._add_network_default_gateway(network_id)

def update_network(self, resource, event, trigger, **kwargs):
network_info = kwargs['network']
self._add_network_default_gateway(network_info['id'])
self._reset_network_default_route(network_info['id'])

def _prepare_network_default_gateway(self, network_id):
router_info = db_lib.get_network_gateway_ipv4(network_id)
@@ -204,9 +212,6 @@ class AristaL3Driver(object):
router_info = self._prepare_network_default_gateway(network_id)
if router_info:
ctx = nctx.get_admin_context()
router_name = self._arista_router_name(router_info['id'],
router_info['name'])
self._delete_default_gateway(router_name)
self.add_router_interface(ctx, router_info)
self._setup_default_gateway(router_info)

@@ -490,7 +495,7 @@ class AristaL3Driver(object):

network_id = ext_gateway.get('network_id')
if network_id:
self._add_network_default_gateway(network_id)
self._reset_network_default_route(network_id)

def _setup_default_gateway(self, router_info):
mlag_peer_failed = False


+ 60
- 8
networking_arista/l3Plugin/l3_arista.py View File

@@ -49,6 +49,7 @@ class AristaL3SyncWorker(worker.BaseWorker):
self._protected_vlans = driver._protected_vlans
self._servers = driver._servers
self._use_vrf = driver._use_vrf
self._vrf_default_route = driver._vrf_default_route
self._loop = None
super(AristaL3SyncWorker, self).__init__(worker_process_count=0)

@@ -87,7 +88,8 @@ class AristaL3SyncWorker(worker.BaseWorker):
ctx,
filters={
'device_id': [r['id']],
'device_owner': [n_const.DEVICE_OWNER_ROUTER_INTF]}) or []
'device_owner': [n_const.DEVICE_OWNER_ROUTER_INTF,
n_const.DEVICE_OWNER_ROUTER_GW]}) or []
for p in ports:
router_interface = r.copy()
net_id = p['network_id']
@@ -99,12 +101,20 @@ class AristaL3SyncWorker(worker.BaseWorker):
router_interface['seg_id'] = seg_id
router_interface['cidr'] = subnet['cidr']
router_interface['gip'] = subnet['gateway_ip']
if p['id'] == r['gw_port_id']:
r['gip'] = subnet['gateway_ip']
router_interface['fixed_ip'] = p['fixed_ips'][0]['ip_address']
router_interface['ip_version'] = subnet['ip_version']
router_interface['subnet_id'] = subnet_id
router_interfaces.append(router_interface)
return routers, router_interfaces

def _get_ext_gateway_ip(self, router):
if ('external_gateway_info' not in router or
router['external_gateway_info'] is None):
return None
return router.get('gip')

def synchronize(self):
"""Synchronizes Router DB from Neturon DB with EOS.

@@ -120,14 +130,23 @@ class AristaL3SyncWorker(worker.BaseWorker):
self.driver._update_vrf_commands()

routers, router_interfaces = self.get_routers_and_interfaces()
expected_vrfs = set()
if self._use_vrf:
expected_vrfs.update(self.driver._arista_router_name(
r['id'], r['name']) for r in routers)
expected_vlans = set(r['seg_id'] for r in router_interfaces)
if self._enable_cleanup:
expected_vrfs = set()
expected_vrf_default_routes = set()
if self._use_vrf:
expected_vrfs.update(self.driver._arista_router_name(
r['id'], r['name']) for r in routers)
if self._vrf_default_route:
expected_vrf_default_routes.update(
(self.driver._arista_router_name(router['id'],
router['name']),
self._get_ext_gateway_ip(router))
for router in routers)

expected_vlans = set(r['seg_id'] for r in router_interfaces)
LOG.info(_LI('Syncing Neutron Router DB - cleanup'))
self.do_cleanup(expected_vrfs, expected_vlans)
self.do_cleanup(expected_vrfs, expected_vlans,
expected_vrf_default_routes)
LOG.info(_LI('Syncing Neutron Router DB - creating routers'))
self.create_routers(routers)
LOG.info(_LI('Syncing Neutron Router DB - creating interfaces'))
@@ -162,7 +181,31 @@ class AristaL3SyncWorker(worker.BaseWorker):
if not info['dynamic'])
return eos_vlans

def do_cleanup(self, expected_vrfs, expected_vlans):
def _get_vrf_default_route(self, vrf, vrf_routes):
if (not vrf_routes or
'routes' not in vrf_routes or
'0.0.0.0/0' not in vrf_routes['routes'] or
'vias' not in vrf_routes['routes']['0.0.0.0/0']):
return set()
result = set()
for via in vrf_routes['routes']['0.0.0.0/0']['vias']:
result.add((vrf, via.get('nexthopAddr')))
return result

def get_vrf_default_routes(self, server):
ret = self.driver._run_eos_cmds(['show ip route vrf all'], server)
if len(ret or []) != 1 or 'vrfs' not in ret[0].keys():
return set()

eos_vrf_gateway = set()
for vrf, vrf_route in ret[0]['vrfs'].items():
if '__OpenStack__' in vrf:
eos_vrf_gateway.update(self._get_vrf_default_route(vrf,
vrf_route))
return eos_vrf_gateway

def do_cleanup(self, expected_vrfs, expected_vlans,
expected_vrf_default_routes):
for server in self._servers:
eos_svis = self.get_svis(server)
eos_vlans = self.get_vlans(server)
@@ -181,6 +224,15 @@ class AristaL3SyncWorker(worker.BaseWorker):
delete_cmds.extend([c.format(vrf)
for c in self.driver.routerDict['delete']
for vrf in vrfs_to_delete])
if self._vrf_default_route:
eos_vrf_gateway = self.get_vrf_default_routes(server)

vrf_gw_to_delete = (eos_vrf_gateway -
expected_vrf_default_routes)

delete_cmds.extend(
'no ip route vrf %s 0.0.0.0/0' % vrf
for (vrf, _) in vrf_gw_to_delete)
if delete_cmds:
self.driver._run_config_cmds(delete_cmds, server)



+ 15
- 4
networking_arista/tests/unit/l3Plugin/test_arista_l3_driver.py View File

@@ -1131,10 +1131,21 @@ class AristaL3SyncWorkerCleanupTestCases(AristaL3SyncWorkerTestBase):
self.driver._create_gw_port(self.context, router['id'], router_model,
net['id'], ext_ips)
self.sync_worker.synchronize()
self.assertEqual(self.switch1._svis, {})
self.assertEqual(self.switch2._svis, {})
self.assertEqual(self.switch1._vlans, {})
self.assertEqual(self.switch2._vlans, {})
switch1_svi = {'vlan 100':
{'ip': '10.0.0.254',
'mask': '24',
'vip': '10.0.0.2'}
}
switch2_svi = {'vlan 100':
{'ip': '10.0.0.253',
'mask': '24',
'vip': '10.0.0.2'}
}
switch_vlan = {'100': {'dynamic': False}}
self.assertEqual(self.switch1._svis, switch1_svi)
self.assertEqual(self.switch2._svis, switch2_svi)
self.assertEqual(self.switch1._vlans, switch_vlan)
self.assertEqual(self.switch2._vlans, switch_vlan)


class AristaL3SyncWorkerNoCleanupTestCases(AristaL3SyncWorkerTestBase):


Loading…
Cancel
Save