]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fix event_send for re-assign floating ip
authorlzklibj <lzklibj@cn.ibm.com>
Tue, 21 Oct 2014 06:55:53 +0000 (23:55 -0700)
committerAaron Rosen <aaronorosen@gmail.com>
Wed, 12 Nov 2014 15:57:43 +0000 (07:57 -0800)
Neutron can associate a floating ip to a new port
without disassociate from original instance port.
This situation will send network changed event only
for new instance port, and that event object contains
the new instance's id.

In this case nova will update new instance's info
but not original one's in nova's database table
instance_info_caches. For nova can get new instance's
id from the above event. So in table instance_info_caches,
both original instance and new instance will have the
same floating ip in their records. And this make it
possible that, in most situation, after your re-assign
floating ip, run "nova list" will return incorrect info,
multiple instances have a same floating ip, and this may
confuse users.

Nova will sync data in table instance_info_caches, but it
may take dozens of seconds.
The new added code will send network changed event for the
original instance, and this will make nova update instance_
_info_caches table in a few seconds.

Change-Id: If3ee11535f649fc51bf1a52806008c1c5c0e73b6
Closes-Bug: 1381886
(cherry picked from commit add8944d4dba2a69e8f7da47f120d5dc63952f77)

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

index aa4f1b53e11811ada9e9f48052d323d3a9d3dce3..1db6bc097ecf40ae3a4e9a6198a30704e9593140 100644 (file)
@@ -128,6 +128,18 @@ class Notifier(object):
         if not cfg.CONF.notify_nova_on_port_data_changes:
             return
 
+        # When neutron re-assigns floating ip from an original instance
+        # port to a new instance port without disassociate it first, an
+        # event should be sent for original instance, that will make nova
+        # know original instance's info, and update database for it.
+        if (action == 'update_floatingip'
+                and returned_obj['floatingip'].get('port_id')
+                and original_obj.get('port_id')):
+            disassociate_returned_obj = {'floatingip': {'port_id': None}}
+            event = self.create_port_changed_event(action, original_obj,
+                                                   disassociate_returned_obj)
+            self.queue_event(event)
+
         event = self.create_port_changed_event(action, original_obj,
                                                returned_obj)
         self.queue_event(event)
index 7972ebf55a975cd9839b8ae7beeb5427a3093d34..db9bc79c31d7f97f72844b33666e2d42d156e6a3 100644 (file)
@@ -303,3 +303,20 @@ class TestNovaNotify(base.BaseTestCase):
                 self.nova_notifier.queue_event(mock.Mock())
                 self.assertFalse(self.nova_notifier._waiting_to_send)
                 send_events.assert_called_once_with()
+
+    def test_reassociate_floatingip_without_disassociate_event(self):
+        returned_obj = {'floatingip':
+                        {'port_id': 'f5348a16-609a-4971-b0f0-4b8def5235fb'}}
+        original_obj = {'port_id': '5a39def4-3d3f-473d-9ff4-8e90064b9cc1'}
+        self.nova_notifier._waiting_to_send = True
+        self.nova_notifier.send_network_change(
+            'update_floatingip', original_obj, returned_obj)
+        self.assertEqual(2, len(self.nova_notifier.pending_events))
+
+        returned_obj_non = {'floatingip': {'port_id': None}}
+        event_dis = self.nova_notifier.create_port_changed_event(
+            'update_floatingip', original_obj, returned_obj_non)
+        event_assoc = self.nova_notifier.create_port_changed_event(
+            'update_floatingip', original_obj, returned_obj)
+        self.assertEqual(self.nova_notifier.pending_events[0], event_dis)
+        self.assertEqual(self.nova_notifier.pending_events[1], event_assoc)