]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Notifier: Catch NotFound error from nova
authorAaron Rosen <aaronorosen@gmail.com>
Thu, 17 Apr 2014 20:42:39 +0000 (13:42 -0700)
committerAaron Rosen <aaronorosen@gmail.com>
Thu, 17 Apr 2014 20:51:09 +0000 (13:51 -0700)
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.

Change-Id: I909025503fc88a92201d5247ae5223e4516e8707
Closes-bug: #1309187

neutron/notifiers/nova.py
neutron/tests/unit/notifiers/test_notifiers_nova.py

index 4d268ec3299639f304637a354b293330a43610e9..8633c990c76cd0894665c3db79975e3bd97bd7b0 100644 (file)
@@ -13,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+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
@@ -186,6 +187,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)
index 1fbdabf25af8532ae44bf9342dd607fe044c861f..eb32aef6dff24f7c84913154cc3c61583fac3a89 100644 (file)
@@ -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,