Fix regression with unbound ports and l2pop

When l2pop is enabled and an unbound port is deleted l2pop mech
driver raises an exception as a result of patch:
https://review.openstack.org/#/c/263471/

As a result of the same patch, when an unbound port's IP
address is changed l2pop sends a fanout RPC message needlessly.

Change-Id: Ia81c03dcdf7aef9528c9c2b9527399251fa6aad7
Closes-Bug: #1533013
This commit is contained in:
Assaf Muller 2016-01-11 21:58:30 -05:00
parent 80a9783077
commit 2540c84c76
2 changed files with 42 additions and 0 deletions

View File

@ -73,6 +73,9 @@ class L2populationMechanismDriver(api.MechanismDriver,
else:
agent_host = context.original_host
if not agent_host:
return
agent_ip = self.get_agent_ip_by_host(db_api.get_session(), agent_host)
orig_mac_ip = [l2pop_rpc.PortInfo(mac_address=port['mac_address'],
@ -248,6 +251,9 @@ class L2populationMechanismDriver(api.MechanismDriver,
other_fdb_entries)
def _get_agent_fdb(self, context, port, agent_host):
if not agent_host:
return
network_id = port['network_id']
session = db_api.get_session()
@ -256,6 +262,9 @@ class L2populationMechanismDriver(api.MechanismDriver,
agent = self.get_agent_by_host(db_api.get_session(), agent_host)
segment = self._get_and_validate_segment(context, port['id'], agent)
if not segment:
return
agent_ip = self.get_agent_ip(agent)
other_fdb_entries = self._get_fdb_entries_template(
segment, agent_ip, port['network_id'])

View File

@ -792,6 +792,39 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
l2pop_mech.delete_port_postcommit(mock.Mock())
self.assertTrue(upd_port_down.called)
def test_delete_unbound_port(self):
l2pop_mech = l2pop_mech_driver.L2populationMechanismDriver()
l2pop_mech.initialize()
with self.port() as port:
port_context = driver_context.PortContext(
self.driver, self.context, port['port'],
self.driver.get_network(
self.context, port['port']['network_id']),
None, None)
# The point is to provide coverage and to assert that no exceptions
# are raised.
l2pop_mech.delete_port_postcommit(port_context)
def test_fixed_ips_change_unbound_port_no_rpc(self):
l2pop_mech = l2pop_mech_driver.L2populationMechanismDriver()
l2pop_mech.initialize()
l2pop_mech.L2populationAgentNotify = mock.Mock()
with self.port() as port:
port_context = driver_context.PortContext(
self.driver, self.context, port['port'],
self.driver.get_network(
self.context, port['port']['network_id']),
None, None)
l2pop_mech._fixed_ips_changed(
port_context, None, port['port'], (set(['10.0.0.1']), set()))
# There's no need to send an RPC update if the IP address for an
# unbound port changed.
self.assertFalse(
l2pop_mech.L2populationAgentNotify.update_fdb_entries.called)
class TestL2PopulationMechDriver(base.BaseTestCase):