Add VIF_DELETED notification event to Nova
It's possible to delete a neutron port that is currently associated with an instance. When it happens, neutron should notify nova of the port deletion event so that Nova can take proper actions. Refer to I998b6bb80cc0a81d665b61b8c4a424d7219c666f for the nova patch that handles the event. Change-Id: Iff88cd12ae18017ef3e776821bcf3ecf3b4f052f Related-Bug: #1333365 Related-Bug: #1448148
This commit is contained in:
parent
2aa336aeb8
commit
0ace88fd4a
|
@ -35,6 +35,7 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
VIF_UNPLUGGED = 'network-vif-unplugged'
|
||||
VIF_PLUGGED = 'network-vif-plugged'
|
||||
VIF_DELETED = 'network-vif-deleted'
|
||||
NEUTRON_NOVA_EVENT_STATUS_MAP = {constants.PORT_STATUS_ACTIVE: 'completed',
|
||||
constants.PORT_STATUS_ERROR: 'failed',
|
||||
constants.PORT_STATUS_DOWN: 'completed'}
|
||||
|
@ -121,6 +122,11 @@ class Notifier(object):
|
|||
return {'name': 'network-changed',
|
||||
'server_uuid': device_id}
|
||||
|
||||
def _get_port_delete_event(self, port):
|
||||
return {'server_uuid': port['device_id'],
|
||||
'name': VIF_DELETED,
|
||||
'tag': port['id']}
|
||||
|
||||
@property
|
||||
def _plugin(self):
|
||||
# NOTE(arosen): this cannot be set in __init__ currently since
|
||||
|
@ -160,7 +166,7 @@ class Notifier(object):
|
|||
|
||||
def create_port_changed_event(self, action, original_obj, returned_obj):
|
||||
port = None
|
||||
if action == 'update_port':
|
||||
if action in ['update_port', 'delete_port']:
|
||||
port = returned_obj['port']
|
||||
|
||||
elif action in ['update_floatingip', 'create_floatingip',
|
||||
|
@ -178,7 +184,10 @@ class Notifier(object):
|
|||
port = self._plugin.get_port(ctx, port_id)
|
||||
|
||||
if port and self._is_compute_port(port):
|
||||
return self._get_network_changed_event(port['device_id'])
|
||||
if action == 'delete_port':
|
||||
return self._get_port_delete_event(port)
|
||||
else:
|
||||
return self._get_network_changed_event(port['device_id'])
|
||||
|
||||
def record_port_status_changed(self, port, current_port_status,
|
||||
previous_port_status, initiator):
|
||||
|
|
|
@ -290,3 +290,18 @@ class TestNovaNotify(base.BaseTestCase):
|
|||
self.nova_notifier.batch_notifier.pending_events[0], event_dis)
|
||||
self.assertEqual(
|
||||
self.nova_notifier.batch_notifier.pending_events[1], event_assoc)
|
||||
|
||||
def test_delete_port_notify(self):
|
||||
device_id = '32102d7b-1cf4-404d-b50a-97aae1f55f87'
|
||||
port_id = 'bee50827-bcee-4cc8-91c1-a27b0ce54222'
|
||||
returned_obj = {'port':
|
||||
{'device_owner': 'compute:dfd',
|
||||
'id': port_id,
|
||||
'device_id': device_id}}
|
||||
|
||||
expected_event = {'server_uuid': device_id,
|
||||
'name': nova.VIF_DELETED,
|
||||
'tag': port_id}
|
||||
event = self.nova_notifier.create_port_changed_event('delete_port',
|
||||
{}, returned_obj)
|
||||
self.assertEqual(expected_event, event)
|
||||
|
|
Loading…
Reference in New Issue