Merge "Add VIF_DELETED notification event to Nova"

This commit is contained in:
Jenkins 2015-06-02 22:33:42 +00:00 committed by Gerrit Code Review
commit 0fae34f2a2
2 changed files with 26 additions and 2 deletions

View File

@ -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):

View File

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