Fix updating allocation_pools on subnet update

Reference IPAM driver skipped subnet_update processing
if allocation_pools in subnet request are blank.

Built-in ipam implementation allows to update allocation pools
to blank value (i.e. clean up allocation pools for subnet).
To make Reference ipam driver consistent with built-in ipam
implementation allocation_pool check was removed.

Included UT to verify that allocation pools can be updated to blank
value now.

Change-Id: I0654e46d4bc60f6cf51ffddeead238dd4f064db2
Closes-Bug: #1605277
This commit is contained in:
Pavel Bondar 2016-07-21 17:51:54 +03:00 committed by Carl Baldwin
parent 2a64fabd52
commit de2a70165c
2 changed files with 23 additions and 6 deletions

View File

@ -291,7 +291,7 @@ class NeutronDbPool(subnet_alloc.SubnetAllocator):
raise ipam_exc.InvalidSubnetRequest(
reason=_("An identifier must be specified when updating "
"a subnet"))
if not subnet_request.allocation_pools:
if subnet_request.allocation_pools is None:
LOG.debug("Update subnet request for subnet %s did not specify "
"new allocation pools, there is nothing to do",
subnet_request.subnet_id)

View File

@ -142,22 +142,39 @@ class TestNeutronDbIpamPool(testlib_api.SqlTestCase,
ipam_req.AnySubnetRequest(self._tenant_id, 'meh',
constants.IPv4, 24))
def test_update_subnet_pools(self):
def _test_update_subnet_pools(self, allocation_pools, expected_pools=None):
if expected_pools is None:
expected_pools = allocation_pools
cidr = '10.0.0.0/24'
subnet, subnet_req = self._prepare_specific_subnet_request(cidr)
self.ipam_pool.allocate_subnet(subnet_req)
allocation_pools = [netaddr.IPRange('10.0.0.100', '10.0.0.150'),
netaddr.IPRange('10.0.0.200', '10.0.0.250')]
update_subnet_req = ipam_req.SpecificSubnetRequest(
self._tenant_id,
subnet['id'],
cidr,
gateway_ip=subnet['gateway_ip'],
allocation_pools=allocation_pools)
ipam_subnet = self.ipam_pool.update_subnet(update_subnet_req)
self.ipam_pool.update_subnet(update_subnet_req)
ipam_subnet = self.ipam_pool.get_subnet(subnet['id'])
self._verify_ipam_subnet_details(
ipam_subnet,
cidr, self._tenant_id, subnet['gateway_ip'], allocation_pools)
cidr, self._tenant_id, subnet['gateway_ip'], expected_pools)
def test_update_subnet_pools(self):
allocation_pools = [netaddr.IPRange('10.0.0.100', '10.0.0.150'),
netaddr.IPRange('10.0.0.200', '10.0.0.250')]
self._test_update_subnet_pools(allocation_pools)
def test_update_subnet_pools_with_blank_pools(self):
allocation_pools = []
self._test_update_subnet_pools(allocation_pools)
def test_update_subnet_pools_with_none_pools(self):
allocation_pools = None
expected_pools = [netaddr.IPRange('10.0.0.2', '10.0.0.254')]
# Pools should not be changed on update
self._test_update_subnet_pools(allocation_pools,
expected_pools=expected_pools)
def test_get_subnet(self):
cidr = '10.0.0.0/24'