From 94546a3294fbaed49dff8bab61a0b29354d2484f Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Thu, 17 Apr 2014 13:42:39 -0700 Subject: [PATCH] Notifier: Catch NotFound error from nova If neutron sends a single event to nova and the server_uuid isn't found in nova. The python-novaclient will raise a 404 error. This patch ensures we explicitly catch that exception and use LOG.warning instead of LOG.exception as this is not an error and can happen when deleting an instance if neutron detects that the port_status goes down before the port is deleted because nova first unplugs the vif and then deletes it from neutron. Closes-bug: #1309187 (cherry picked from commit c049583e80d9b2234557a11b77d843549f1efa65) Conflicts: neutron/notifiers/nova.py Change-Id: I7e72da61ccf4c1a3ccc48feb0fdf3d165cdda388 --- neutron/notifiers/nova.py | 4 ++++ neutron/tests/unit/notifiers/test_notifiers_nova.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index 2deb76c67e..883bccae79 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -14,6 +14,7 @@ # under the License. import eventlet +from novaclient import exceptions as nova_exceptions import novaclient.v1_1.client as nclient from novaclient.v1_1.contrib import server_external_events from oslo.config import cfg @@ -231,6 +232,9 @@ class Notifier(object): try: response = self.nclient.server_external_events.create( batched_events) + except nova_exceptions.NotFound: + LOG.warning(_("Nova returned NotFound for event: %s"), + batched_events) except Exception: LOG.exception(_("Failed to notify nova on events: %s"), batched_events) diff --git a/neutron/tests/unit/notifiers/test_notifiers_nova.py b/neutron/tests/unit/notifiers/test_notifiers_nova.py index e38b4c97ec..db9bc79c31 100644 --- a/neutron/tests/unit/notifiers/test_notifiers_nova.py +++ b/neutron/tests/unit/notifiers/test_notifiers_nova.py @@ -15,6 +15,7 @@ import mock +from novaclient import exceptions as nova_exceptions from sqlalchemy.orm import attributes as sql_attr from oslo.config import cfg @@ -219,6 +220,13 @@ class TestNovaNotify(base.BaseTestCase): nclient_create.return_value = 'i am a string!' self.nova_notifier.send_events() + def test_nova_send_event_rasies_404(self): + with mock.patch.object( + self.nova_notifier.nclient.server_external_events, + 'create') as nclient_create: + nclient_create.side_effect = nova_exceptions.NotFound + self.nova_notifier.send_events() + def test_nova_send_events_raises(self): with mock.patch.object( self.nova_notifier.nclient.server_external_events,