Sink - Delete record on floatingip.delete event

Closes-Bug: #1270124

Change-Id: I1f1b9be771815cb089189b52a4f6ab7f3e19279a
This commit is contained in:
Endre Karlson 2014-01-21 12:08:07 +01:00 committed by Gerrit Code Review
parent 74d7e3ddc5
commit 8d59ad9d0b
5 changed files with 74 additions and 13 deletions

View File

@ -47,6 +47,7 @@ class NeutronFloatingHandler(BaseAddressHandler):
def get_event_types(self):
return [
'floatingip.update.end',
'floatingip.delete.start'
]
def process_notification(self, event_type, payload):
@ -56,16 +57,21 @@ class NeutronFloatingHandler(BaseAddressHandler):
# FIXME: Neutron doesn't send ipv in the payload, should maybe
# determine this?
if event_type not in self.get_event_types():
raise ValueError('NovaFixedHandler recieved an invalid event type')
msg = '%s recieved an invalid event type %s' % (
self, event_type)
raise ValueError(msg)
floating = payload['floatingip']
if floating['fixed_ip_address']:
address = {
'version': 4,
'address': floating['floating_ip_address']}
self._create([address], payload, resource_id=floating['id'],
resource_type='floatingip')
elif not floating['fixed_ip_address']:
self._delete(resource_id=payload['floatingip']['id'],
if event_type.startswith('floatingip.delete'):
self._delete(resource_id=payload['floatingip_id'],
resource_type='floatingip')
elif event_type.startswith('floatingip.update'):
if payload['floatingip']['fixed_ip_address']:
address = {
'version': 4,
'address': payload['floatingip']['floating_ip_address']}
self._create([address], payload,
resource_id=payload['floatingip']['id'],
resource_type='floatingip')
elif not payload['floatingip']['fixed_ip_address']:
self._delete(resource_id=payload['floatingip']['id'],
resource_type='floatingip')

View File

@ -0,0 +1,27 @@
{
"_context_roles": [
"Member",
"anotherrole"
],
"_context_request_id": "req-e905e3d8-7c3b-4d0b-a5aa-7c0f14b0b9df",
"_context_read_deleted": "no",
"event_type": "floatingip.delete.start",
"_context_user_name": "demo",
"_context_project_name": "demo",
"timestamp": "2014-01-17 11:30:41.456481",
"_context_tenant_name": "demo",
"_context_tenant": "c97027dd880d4c129ae7a4ba7edade05",
"message_id": "9d30a752-5121-4cf0-bce4-86c2260dbbbc",
"_unique_id": "8eca7bd4402c44449123f0b20eda2c2d",
"_context_is_admin": false,
"_context_timestamp": "2014-01-17 11:30:41.452922",
"_context_project_id": "c97027dd880d4c129ae7a4ba7edade05",
"_context_tenant_id": "c97027dd880d4c129ae7a4ba7edade05",
"_context_user": "5e0e5ccd874044ff9f5eb9017bf9be5e",
"_context_user_id": "5e0e5ccd874044ff9f5eb9017bf9be5e",
"publisher_id": "network.i-00000cac",
"payload": {
"floatingip_id": "f38ff2b6-cd4d-433e-8a9c-9e00dfc05b1e"
},
"priority": "INFO"
}

View File

@ -18,7 +18,7 @@
"router_id" : "62c1fd2b-8149-4222-8d6b-e581c55e5264",
"port_id" : "289ed46b-274c-444d-9fd4-bddf8acc7d7c",
"floating_ip_address" : "192.168.5.201",
"id" : "19b93b6b-8396-4800-b711-f810fc214722"
"id" : "f38ff2b6-cd4d-433e-8a9c-9e00dfc05b1e"
}
},
"_context_timestamp" : "2012-11-18 01:29:29.443215",

View File

@ -18,7 +18,7 @@
"router_id" : null,
"port_id" : null,
"floating_ip_address" : "192.168.5.201",
"id" : "19b93b6b-8396-4800-b711-f810fc214722"
"id" : "f38ff2b6-cd4d-433e-8a9c-9e00dfc05b1e"
}
},
"_context_timestamp" : "2012-11-18 01:35:08.281731",

View File

@ -85,3 +85,31 @@ class NeutronFloatingHandlerTest(TestCase, NotificationHandlerMixin):
criterion)
self.assertEqual(0, len(records))
def test_floatingip_delete(self):
start_event_type = 'floatingip.update.end'
start_fixture = self.get_notification_fixture(
'neutron', start_event_type + '_associate')
self.plugin.process_notification(start_event_type,
start_fixture['payload'])
event_type = 'floatingip.delete.start'
fixture = self.get_notification_fixture(
'neutron', event_type)
self.assertIn(event_type, self.plugin.get_event_types())
criterion = {'domain_id': self.domain_id}
# Ensure we start with at least 1 record
records = self.central_service.find_records(self.admin_context,
criterion)
self.assertEqual(1, len(records))
self.plugin.process_notification(event_type, fixture['payload'])
# Ensure we now have exactly 0 records
records = self.central_service.find_records(self.admin_context,
criterion)
self.assertEqual(0, len(records))