Merge "Utils: make delete_port_on_error more informative"

This commit is contained in:
Jenkins 2017-06-02 18:51:03 +00:00 committed by Gerrit Code Review
commit 2faa7af19d
2 changed files with 14 additions and 0 deletions

View File

@ -193,6 +193,8 @@ def delete_port_on_error(core_plugin, context, port_id):
try:
core_plugin.delete_port(context, port_id,
l3_port_check=False)
except exceptions.PortNotFound:
LOG.debug("Port %s not found", port_id)
except Exception:
LOG.exception(_LE("Failed to delete port: %s"), port_id)

View File

@ -16,6 +16,7 @@ import hashlib
import mock
from neutron_lib import constants
from neutron_lib import exceptions
import testtools
from neutron.db import l3_db
@ -92,6 +93,17 @@ class TestUtils(base.BaseTestCase):
core_plugin.delete_port.assert_called_once_with(context, port_id,
l3_port_check=False)
def test_delete_port_on_error_port_does_not_exist(self):
core_plugin, context = mock.Mock(), mock.Mock()
port_id = 'pid'
core_plugin.delete_port.side_effect = exceptions.PortNotFound(
port_id=port_id)
with testtools.ExpectedException(exceptions.PortNotFound):
with utils.delete_port_on_error(core_plugin, context, port_id):
raise exceptions.PortNotFound(port_id=port_id)
core_plugin.delete_port.assert_called_once_with(context, port_id,
l3_port_check=False)
@mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_check_router_port')
def test_update_port_on_error(self, mock_check):
core_plugin, context = mock.Mock(), mock.Mock()