Ensure there are fdb_entries before iterating
_get_agent_fdb may return None so we need to check for that before we try to iterate over a key inside of it in delete_port_postcommit. Closes-Bug: #1622996 Change-Id: I2256df0e08380e550f32248fb9589ee43b0923ff
This commit is contained in:
parent
adee80ea90
commit
6e0b8c176c
|
@ -72,8 +72,8 @@ class L2populationMechanismDriver(api.MechanismDriver):
|
|||
agent_host = context.host
|
||||
fdb_entries = self._get_agent_fdb(context.bottom_bound_segment,
|
||||
port, agent_host)
|
||||
session = db_api.get_session()
|
||||
if port['device_owner'] in l2pop_db.HA_ROUTER_PORTS:
|
||||
if port['device_owner'] in l2pop_db.HA_ROUTER_PORTS and fdb_entries:
|
||||
session = db_api.get_session()
|
||||
network_id = port['network_id']
|
||||
other_fdb_ports = self._get_ha_port_agents_fdb(
|
||||
session, network_id, port['device_id'])
|
||||
|
|
|
@ -1076,6 +1076,21 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
|
|||
def test_host_changed_twice(self):
|
||||
self._test_host_changed(twice=True)
|
||||
|
||||
def test_delete_port_no_fdb_entries_with_ha_port(self):
|
||||
l2pop_mech = l2pop_mech_driver.L2populationMechanismDriver()
|
||||
l2pop_mech.L2PopulationAgentNotify = mock.Mock()
|
||||
l2pop_mech.rpc_ctx = mock.Mock()
|
||||
port = {'device_owner': l2pop_db.HA_ROUTER_PORTS[0]}
|
||||
context = mock.Mock()
|
||||
context.current = port
|
||||
with mock.patch.object(l2pop_mech,
|
||||
'_get_agent_fdb',
|
||||
return_value=None) as upd_port_down,\
|
||||
mock.patch.object(l2pop_mech.L2PopulationAgentNotify,
|
||||
'remove_fdb_entries'):
|
||||
l2pop_mech.delete_port_postcommit(context)
|
||||
self.assertTrue(upd_port_down.called)
|
||||
|
||||
def test_delete_port_invokes_update_device_down(self):
|
||||
l2pop_mech = l2pop_mech_driver.L2populationMechanismDriver()
|
||||
l2pop_mech.L2PopulationAgentNotify = mock.Mock()
|
||||
|
|
Loading…
Reference in New Issue