fix event_send for re-assign floating ip

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
This commit is contained in:
lzklibj 2014-10-20 23:55:53 -07:00
parent 6db9fac938
commit add8944d4d
2 changed files with 29 additions and 0 deletions

View File

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

View 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)