]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix regression with unbound ports and l2pop
authorAssaf Muller <amuller@redhat.com>
Tue, 12 Jan 2016 02:58:30 +0000 (21:58 -0500)
committerAssaf Muller <amuller@redhat.com>
Tue, 12 Jan 2016 13:23:57 +0000 (08:23 -0500)
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

neutron/plugins/ml2/drivers/l2pop/mech_driver.py
neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py

index c577261c66dfe7f36f5e2839c4f90dccfd2e9ba9..6e3baaaf7b57a46853df4fa89ebd2289dce3118f 100644 (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'])
index c45f9a337daa7232a516967d6b9c10a6b77a74a1..9fb4282b50bbcfc81a7172db4618619caf564424 100644 (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):