From 2540c84c7624892cd64514a5864731433f3889bb Mon Sep 17 00:00:00 2001 From: Assaf Muller Date: Mon, 11 Jan 2016 21:58:30 -0500 Subject: [PATCH] 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 --- .../plugins/ml2/drivers/l2pop/mech_driver.py | 9 +++++ .../ml2/drivers/l2pop/test_mech_driver.py | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py index c577261c6..6e3baaaf7 100644 --- a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py +++ b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py @@ -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']) diff --git a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py index c45f9a337..9fb4282b5 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py @@ -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): -- 2.45.2