]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Catch StaleDataError in update_device_down
authorAnn Kamyshnikova <akamyshnikova@mirantis.com>
Wed, 24 Dec 2014 11:46:27 +0000 (14:46 +0300)
committerAnn Kamyshnikova <akamyshnikova@mirantis.com>
Mon, 12 Jan 2015 12:39:07 +0000 (15:39 +0300)
For some reason sometimes at the same time for the same port
delete_port and update_device_down commands have been executed.
This arise StaleDataError in update_device_down. In other situations
these commands are executed one after another and the error doesn't
appear.

This errors does not show anything broken, but to avoid confusion
it will be skipped.

Closes-bug: #1405379

Change-Id: I4e5a3d1f1866b9cfba44d3cb7ccc5b2dee1d9633

neutron/plugins/ml2/rpc.py
neutron/tests/unit/ml2/test_rpcapi.py

index 6efa6dabdd59570c9a7deebaa958b9e5102e5e86..a612ed6a194cf306e3a567828141abb3e4189f62 100644 (file)
@@ -14,6 +14,7 @@
 #    under the License.
 
 from oslo import messaging
+from sqlalchemy.orm import exc
 
 from neutron.agent import securitygroups_rpc as sg_rpc
 from neutron.api.rpc.handlers import dvr_rpc
@@ -135,9 +136,13 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin):
             return {'device': device,
                     'exists': port_exists}
 
-        port_exists = bool(plugin.update_port_status(rpc_context, port_id,
-                                                     q_const.PORT_STATUS_DOWN,
-                                                     host))
+        try:
+            port_exists = bool(plugin.update_port_status(
+                rpc_context, port_id, q_const.PORT_STATUS_DOWN, host))
+        except exc.StaleDataError:
+            port_exists = False
+            LOG.debug("delete_port and update_device_down are being executed "
+                      "concurrently. Ignoring StaleDataError.")
 
         return {'device': device,
                 'exists': port_exists}
index 2acf8dd1c2eebf6c15e74fd75d1eaed3f736a29f..8ed1c9c0fa5a9b7ffe551ec4c0b08b644a98e90d 100644 (file)
@@ -22,6 +22,7 @@ import contextlib
 
 import mock
 from oslo_context import context as oslo_context
+from sqlalchemy.orm import exc
 
 from neutron.agent import rpc as agent_rpc
 from neutron.common import constants
@@ -162,6 +163,12 @@ class RpcCallbacksTestCase(base.BaseTestCase):
             'fake_context', 'fake_port_id', constants.PORT_STATUS_DOWN,
             'fake_host')
 
+    def test_update_device_down_call_update_port_status_failed(self):
+        self.plugin.update_port_status.side_effect = exc.StaleDataError
+        self.assertEqual({'device': 'fake_device', 'exists': False},
+                         self.callbacks.update_device_down(
+                             'fake_context', device='fake_device'))
+
 
 class RpcApiTestCase(base.BaseTestCase):