Prevent the delete floating IP API from deleting reserved floating ips
If a floating IP is reserved by any reservations, the delete floating IP API shouldn't delete the floating IP. This patch changes the delete floating IP API to check allocations associated to the floating IP, then if there is any allocation the API doesn't delete the floating IP. Partially Implements: blueprint floatingip-reservation Change-Id: I0c48eaa4084ea65b658cb568358b4c9bcf5178f2
This commit is contained in:
parent
f781eedcae
commit
6c2053f530
|
@ -215,9 +215,12 @@ class FloatingIpPlugin(base.BasePlugin):
|
|||
if fip is None:
|
||||
raise manager_ex.FloatingIPNotFound(floatingip=fip_id)
|
||||
|
||||
# TODO(masahito): Check no allocation exists for the floating ip here
|
||||
# once this plugin supports reserve_resource method.
|
||||
|
||||
allocations = db_api.fip_allocation_get_all_by_values(
|
||||
floatingip_id=fip_id)
|
||||
if allocations:
|
||||
msg = 'Floating IP id %s is allocated by reservations.' % fip_id
|
||||
LOG.info(msg)
|
||||
raise manager_ex.CantDeleteFloatingIP(floatingip=fip_id, msg=msg)
|
||||
try:
|
||||
db_api.floatingip_destroy(fip_id)
|
||||
except db_ex.BlazarDBException as e:
|
||||
|
|
|
@ -144,14 +144,42 @@ class FloatingIpPluginTest(tests.TestCase):
|
|||
}
|
||||
patch_fip_get = self.patch(db_api, 'floatingip_get')
|
||||
patch_fip_get.return_value = fip_row
|
||||
patch_fip_alloc = self.patch(db_api,
|
||||
'fip_allocation_get_all_by_values')
|
||||
patch_fip_alloc.return_value = []
|
||||
patch_fip_destroy = self.patch(db_api, 'floatingip_destroy')
|
||||
|
||||
fip_plugin = floatingip_plugin.FloatingIpPlugin()
|
||||
fip_plugin.delete_floatingip('fip-id')
|
||||
|
||||
patch_fip_get.assert_called_once_with('fip-id')
|
||||
patch_fip_alloc.assert_called_once_with(floatingip_id='fip-id')
|
||||
patch_fip_destroy.assert_called_once_with('fip-id')
|
||||
|
||||
def test_delete_floatingip_with_reservations(self):
|
||||
fip_row = {
|
||||
'id': 'fip-id',
|
||||
'network_id': 'net-id',
|
||||
'subnet_id': 'subnet-id',
|
||||
'floating_ip_address': '172.24.4.100',
|
||||
'reservable': True
|
||||
}
|
||||
patch_fip_get = self.patch(db_api, 'floatingip_get')
|
||||
patch_fip_get.return_value = fip_row
|
||||
patch_fip_alloc = self.patch(db_api,
|
||||
'fip_allocation_get_all_by_values')
|
||||
patch_fip_alloc.return_value = [
|
||||
{
|
||||
'id': 'alloc-id1',
|
||||
'floatingip_id': 'fip-id',
|
||||
'reservation_id': 'reservations-id1'
|
||||
}
|
||||
]
|
||||
fip_plugin = floatingip_plugin.FloatingIpPlugin()
|
||||
self.assertRaises(mgr_exceptions.CantDeleteFloatingIP,
|
||||
fip_plugin.delete_floatingip,
|
||||
'fip-id1')
|
||||
|
||||
def test_delete_floatingip_with_no_exist(self):
|
||||
patch_fip_get = self.patch(db_api, 'floatingip_get')
|
||||
patch_fip_get.return_value = None
|
||||
|
|
Loading…
Reference in New Issue