Utils: make delete_port_on_error more informative

When under load the port may have been deleted by another process.
Here we will log the port that was not found. This will help
debug.

Change-Id: I2556c54584c84cbdb777a4fa366b18a9195b60c5
Closes-bug: #1694389
(cherry picked from commit 99d0ff92e8)
changes/32/470632/1
Gary Kotton 6 years ago committed by garyk
parent 8dbbc0c17f
commit 28a14b79d7
  1. 2
      neutron/plugins/common/utils.py
  2. 12
      neutron/tests/unit/plugins/common/test_utils.py

@ -192,6 +192,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)

@ -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()

Loading…
Cancel
Save