]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Don't update port with host id of None
authorKevin Benton <blak111@gmail.com>
Fri, 17 Apr 2015 11:09:48 +0000 (04:09 -0700)
committerKevin Benton <blak111@gmail.com>
Sat, 25 Apr 2015 17:17:07 +0000 (10:17 -0700)
In the L3 RPC code if the host for a port is not
present, it ends up calling update_port with the
host_id set to None. This does not update the host
id at all because it's treated as an unset attribute
which leads to the same thing happening on the next
iteration. These pointless update calls are expensive
because they involve a semaphore and calls to mechanism
drivers.

This patch adjusts the logic to only send a port
update if it actually has a host to ensure is on
the port.

Change-Id: Ic55496dd2ba3abcef0a2de9fc8699c391b79fa51
Partial-Bug: #1445412

neutron/api/rpc/handlers/l3_rpc.py
neutron/tests/unit/extensions/test_l3.py

index 23ccb3205c4ad6a8d780eb39456dd3d6f459c15f..936bf0b27e516a11e36f4f9c1c4aefa4fad678c9 100644 (file)
@@ -115,7 +115,7 @@ class L3RpcCallback(object):
                                               router['id'])
 
     def _ensure_host_set_on_port(self, context, host, port, router_id=None):
-        if (port and
+        if (port and host is not None and
             (port.get('device_owner') !=
              constants.DEVICE_OWNER_DVR_INTERFACE and
              port.get(portbindings.HOST_ID) != host or
index 8c824d6c07831049220a95ee7c9569ada500c07d..8630d55292fcc4fe74f53225a77e9fd971cc1480 100644 (file)
@@ -2574,6 +2574,11 @@ class L3RpcCallbackTestCase(base.BaseTestCase):
             'l3plugin', new_callable=mock.PropertyMock).start()
         self.l3_rpc_cb = l3_rpc.L3RpcCallback()
 
+    def test__ensure_host_set_on_port_host_id_none(self):
+        port = {'id': 'id', portbindings.HOST_ID: 'somehost'}
+        self.l3_rpc_cb._ensure_host_set_on_port(None, None, port)
+        self.assertFalse(self.l3_rpc_cb.plugin.update_port.called)
+
     def test__ensure_host_set_on_port_update_on_concurrent_delete(self):
         port_id = 'foo_port_id'
         port = {