Merge pull request #88 from asadoughi/dealloc_ip_fix
Bugfix: deallocate_ip_address in-loop deletion
This commit is contained in:
@@ -147,13 +147,11 @@ class QuarkIpam(object):
|
|||||||
return address
|
return address
|
||||||
|
|
||||||
def deallocate_ip_address(self, context, port, **kwargs):
|
def deallocate_ip_address(self, context, port, **kwargs):
|
||||||
for address in port["ip_addresses"]:
|
for addr in port["ip_addresses"]:
|
||||||
# Only disassociate from port, don't automatically deallocate
|
# Note: only deallocate ip if this is the only port mapped to it
|
||||||
address["ports"].remove(port)
|
if len(addr["ports"]) == 1:
|
||||||
if len(address["ports"]) > 0:
|
addr["deallocated"] = 1
|
||||||
continue
|
port["ip_addresses"] = []
|
||||||
|
|
||||||
address["deallocated"] = 1
|
|
||||||
|
|
||||||
def deallocate_mac_address(self, context, address):
|
def deallocate_mac_address(self, context, address):
|
||||||
mac = db_api.mac_address_find(context, address=address,
|
mac = db_api.mac_address_find(context, address=address,
|
||||||
|
@@ -176,17 +176,20 @@ class QuarkIPAddressDeallocation(QuarkIpamBaseTest):
|
|||||||
addr = dict(ports=[port])
|
addr = dict(ports=[port])
|
||||||
port["ip_addresses"].append(addr)
|
port["ip_addresses"].append(addr)
|
||||||
self.ipam.deallocate_ip_address(self.context, port)
|
self.ipam.deallocate_ip_address(self.context, port)
|
||||||
self.assertEqual(len(addr["ports"]), 0)
|
# ORM takes care of other model if one model is modified
|
||||||
self.assertEqual(addr["deallocated"], True)
|
self.assertTrue(len(addr["ports"]) == 0 or
|
||||||
|
len(port["ip_addresses"]) == 0)
|
||||||
|
self.assertTrue(addr["deallocated"])
|
||||||
|
|
||||||
def test_deallocate_ip_address_multiple_ports_no_deallocation(self):
|
def test_deallocate_ip_address_multiple_ports_no_deallocation(self):
|
||||||
port = dict(ip_addresses=[])
|
port = dict(ip_addresses=[])
|
||||||
addr = dict(ports=[port, 2], deallocated=False)
|
addr = dict(ports=[port, 2], deallocated=False)
|
||||||
port["ip_addresses"].append(addr)
|
port["ip_addresses"].append(addr)
|
||||||
|
|
||||||
self.ipam.deallocate_ip_address(self.context, port)
|
self.ipam.deallocate_ip_address(self.context, port)
|
||||||
self.assertEqual(len(addr["ports"]), 1)
|
# ORM takes care of other model if one model is modified
|
||||||
self.assertEqual(addr["deallocated"], False)
|
self.assertTrue(len(addr["ports"]) == 1 or
|
||||||
|
len(port["ip_addresses"]) == 0)
|
||||||
|
self.assertFalse(addr["deallocated"])
|
||||||
|
|
||||||
|
|
||||||
class QuarkNewIPAddressAllocation(QuarkIpamBaseTest):
|
class QuarkNewIPAddressAllocation(QuarkIpamBaseTest):
|
||||||
|
Reference in New Issue
Block a user