When deleting floating IP catch PortNotFound

If we try to delete a VM and to delete the floating IP
associated with the VM at the same time, depending
on the order according to which these requests are processed
Neutron might fail in the deletion of the floating IP,
raising a PortNotFound error. This happens because Neutron
notifies Nova of the network change event and it tries to get
the port to which the FIP is associated. If the port is not there,
Neutron shouldn't raise, it shouldn't send any notification.

Conflicts:
	neutron/notifiers/nova.py
	neutron/tests/unit/notifiers/test_nova.py

Closes-bug: #1586931
Change-Id: Ic72313ad1f787b3cb528e806c843f1fd01eb12f2
(cherry picked from commit 6e275e3857)
This commit is contained in:
rossella 2016-07-02 18:15:32 +00:00 committed by Rossella Sblendido
parent 49f0432cf3
commit d39d45ab4b
2 changed files with 19 additions and 1 deletions

View File

@ -24,6 +24,7 @@ from oslo_utils import uuidutils
from sqlalchemy.orm import attributes as sql_attr
from neutron.common import constants
from neutron.common import exceptions as exc
from neutron import context
from neutron.i18n import _LE, _LI, _LW
from neutron import manager
@ -177,7 +178,12 @@ class Notifier(object):
return
ctx = context.get_admin_context()
port = self._plugin.get_port(ctx, port_id)
try:
port = self._plugin.get_port(ctx, port_id)
except exc.PortNotFound:
LOG.debug("Port %s was deleted, no need to send any "
"notification", port_id)
return
if port and self._is_compute_port(port):
if action == 'delete_port':

View File

@ -22,6 +22,7 @@ from sqlalchemy.orm import attributes as sql_attr
from oslo_config import cfg
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.db import models_v2
from neutron.notifiers import nova
from neutron.tests import base
@ -172,6 +173,17 @@ class TestNovaNotify(base.BaseTestCase):
'delete_floatingip', {}, returned_obj)
self.assertEqual(expected_event, event)
def test_delete_floatingip_deleted_port_no_notify(self):
port_id = 'bee50827-bcee-4cc8-91c1-a27b0ce54222'
with mock.patch.object(
self.nova_notifier._plugin_ref, 'get_port',
side_effect=n_exc.PortNotFound(port_id=port_id)):
returned_obj = {'floatingip':
{'port_id': port_id}}
event = self.nova_notifier.create_port_changed_event(
'delete_floatingip', {}, returned_obj)
self.assertIsNone(event)
def test_delete_floatingip_no_port_id_no_notify(self):
returned_obj = {'floatingip':
{'port_id': None}}