From 9726a00c908341654f4cdeb444adf2ce5c717b80 Mon Sep 17 00:00:00 2001 From: Armando Migliaccio Date: Wed, 31 Aug 2016 01:04:42 +0000 Subject: [PATCH] Narrow down DBError to DBReferenceError in DHCP action handler Commit 85ed7017ff22dd24ef7558010e62598483561354 removed the DBError handling to let the retry decorator do its magic, however the full implications of this change were not evaluated. As a result, DBReferenceError (which derives from DBError) is not processed correctly and that caused a regression of the existing logic. Rather than bloat the retry's responsibility even further, this patch partially reverts commit 85ed7017f by narrowing down the exception handling to DBReferenceError only. Related-bug: #1618216 Change-Id: Icf4e5e4145dcdcdc710b8e42044467913ed01ec1 --- neutron/api/rpc/handlers/dhcp_rpc.py | 4 +++- neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/neutron/api/rpc/handlers/dhcp_rpc.py b/neutron/api/rpc/handlers/dhcp_rpc.py index 72bf76aae6d..c8c8e3b5a9d 100644 --- a/neutron/api/rpc/handlers/dhcp_rpc.py +++ b/neutron/api/rpc/handlers/dhcp_rpc.py @@ -20,6 +20,7 @@ import operator from neutron_lib import constants from neutron_lib import exceptions from oslo_config import cfg +from oslo_db import exception as db_exc from oslo_log import log as logging import oslo_messaging from oslo_utils import excutils @@ -100,7 +101,8 @@ class DhcpRpcCallback(object): else: msg = _('Unrecognized action') raise exceptions.Invalid(message=msg) - except (exceptions.NetworkNotFound, + except (db_exc.DBReferenceError, + exceptions.NetworkNotFound, exceptions.SubnetNotFound, exceptions.IpAddressGenerationFailure) as e: with excutils.save_and_reraise_exception(reraise=False) as ctxt: diff --git a/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py index af99fb2b89e..9a6a179fe92 100644 --- a/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py +++ b/neutron/tests/unit/api/rpc/handlers/test_dhcp_rpc.py @@ -16,6 +16,7 @@ import mock from neutron_lib import constants from neutron_lib import exceptions as n_exc +from oslo_db import exception as db_exc from neutron.api.rpc.handlers import dhcp_rpc from neutron.callbacks import resources @@ -139,6 +140,11 @@ class TestDhcpRpcCallback(base.BaseTestCase): exc=n_exc.SubnetNotFound(subnet_id='foo_subnet_id'), action='create_port') + def test_create_port_catch_db_reference_error(self): + self._test__port_action_with_failures( + exc=db_exc.DBReferenceError('a', 'b', 'c', 'd'), + action='create_port') + def test_create_port_catch_ip_generation_failure_reraise(self): self.assertRaises( n_exc.IpAddressGenerationFailure,