Merge "Catch PortNotFound exception during get_dhcp_port"

This commit is contained in:
Jenkins 2013-11-22 03:08:38 +00:00 committed by Gerrit Code Review
commit 67fa30ff8f
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]