Merge "Catch StaleDataError in update_device_down"

This commit is contained in:
Jenkins 2015-01-20 22:35:02 +00:00 committed by Gerrit Code Review
commit b3278570ed
2 changed files with 15 additions and 3 deletions

View 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}

View 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):