Catch PortNotFound exception during get_dhcp_port

Close-bug: 1252437

Change-Id: I3a7954b869b4f5b909c806f8e47180e1ba6ba374
This commit is contained in:
armando-migliaccio 2013-11-18 12:13:36 -08:00
parent f1b9ac5a54
commit cbe91fda7b
2 changed files with 15 additions and 5 deletions

View File

@ -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.

View File

@ -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]