From cbe91fda7b416717a23cf7b29adf8201a8c14822 Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Mon, 18 Nov 2013 12:13:36 -0800 Subject: [PATCH] Catch PortNotFound exception during get_dhcp_port Close-bug: 1252437 Change-Id: I3a7954b869b4f5b909c806f8e47180e1ba6ba374 --- neutron/db/dhcp_rpc_base.py | 5 ++--- neutron/tests/unit/test_db_rpc_base.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/neutron/db/dhcp_rpc_base.py b/neutron/db/dhcp_rpc_base.py index 5953be13673..bf7a3d07ef3 100644 --- a/neutron/db/dhcp_rpc_base.py +++ b/neutron/db/dhcp_rpc_base.py @@ -14,7 +14,6 @@ # limitations under the License. from oslo.config import cfg -from sqlalchemy.orm import exc from neutron.api.v2 import attributes from neutron.common import constants @@ -138,8 +137,8 @@ class DhcpRpcCallbackMixin(object): retval = plugin.update_port(context, port['id'], dict(port=port)) - except exc.NoResultFound: - pass + except n_exc.NotFound as e: + LOG.warning(e) if retval is None: # No previous port exists, so create a new one. diff --git a/neutron/tests/unit/test_db_rpc_base.py b/neutron/tests/unit/test_db_rpc_base.py index 9e7a3e87b8d..e9f4a78be1a 100644 --- a/neutron/tests/unit/test_db_rpc_base.py +++ b/neutron/tests/unit/test_db_rpc_base.py @@ -80,7 +80,10 @@ class TestDhcpRpcCallackMixin(base.BaseTestCase): self.plugin.get_ports.return_value = [port_retval] else: self.plugin.get_ports.return_value = [] - self.plugin.update_port.return_value = update_port + if isinstance(update_port, n_exc.NotFound): + self.plugin.update_port.side_effect = update_port + else: + self.plugin.update_port.return_value = update_port self.plugin.create_port.return_value = create_port retval = self.callbacks.get_dhcp_port(mock.Mock(), @@ -135,7 +138,7 @@ class TestDhcpRpcCallackMixin(base.BaseTestCase): self._test_get_dhcp_port_with_failures( raise_create_port=n_exc.SubnetNotFound(subnet_id='b')) - def test_get_dhcp_port_create_new(self): + def _test_get_dhcp_port_create_new(self, update_port=None): self.plugin.get_network.return_value = dict(tenant_id='tenantid') create_spec = dict(tenant_id='tenantid', device_id='devid', network_id='netid', name='', @@ -153,10 +156,18 @@ class TestDhcpRpcCallackMixin(base.BaseTestCase): mock.call.create_port(mock.ANY, dict(port=create_spec))] retval = self._test_get_dhcp_port_helper(None, expectations, + update_port=update_port, create_port=create_retval) self.assertEqual(create_retval, retval) self.assertEqual(len(self.log.mock_calls), 2) + def test_get_dhcp_port_create_new(self): + self._test_get_dhcp_port_create_new() + + def test_get_dhcp_port_create_new_with_failure_on_port_update(self): + self._test_get_dhcp_port_create_new( + update_port=n_exc.PortNotFound(port_id='foo')) + def test_release_dhcp_port(self): port_retval = dict(id='port_id', fixed_ips=[dict(subnet_id='a')]) self.plugin.get_ports.return_value = [port_retval]