From 6d35f5fa91faf24694cf22bf9290f4743175b051 Mon Sep 17 00:00:00 2001 From: Tomoaki Sato Date: Mon, 29 Jun 2015 10:02:20 +0900 Subject: [PATCH] Fix subnet updating failure on valid allocation pools Currently subnet updating with both allocation-pool and gateway_ip options is failing because of wrong parameter check. The check always checks gateway_ip against allocation pools in db, even when the allocation_pool parameter is given.The fix checks if given parameter of gateway_ip option doesn't conflict with given parameters of allocation-pool. Change-Id: Ia568aa1645b3160ab90a6010efd9a2b9b0d31ac8 Closes-Bug: #1469573 --- neutron/db/db_base_plugin_v2.py | 9 +++++++-- neutron/tests/unit/db/test_db_base_plugin_v2.py | 13 ++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 9ca165e5b..7a953983a 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -586,8 +586,13 @@ class NeutronDbPluginV2(ipam_non_pluggable_backend.IpamNonPluggableBackend, self._validate_subnet(context, s, cur_subnet=db_subnet) if s.get('gateway_ip') is not None: - allocation_pools = [{'start': p['first_ip'], 'end': p['last_ip']} - for p in db_subnet.allocation_pools] + if s.get('allocation_pools') is not None: + allocation_pools = [{'start': p['start'], 'end': p['end']} + for p in s['allocation_pools']] + else: + allocation_pools = [{'start': p['first_ip'], + 'end': p['last_ip']} + for p in db_subnet.allocation_pools] self._validate_gw_out_of_pools(s["gateway_ip"], allocation_pools) with context.session.begin(subtransactions=True): diff --git a/neutron/tests/unit/db/test_db_base_plugin_v2.py b/neutron/tests/unit/db/test_db_base_plugin_v2.py index fbc20d27c..241c6e90a 100644 --- a/neutron/tests/unit/db/test_db_base_plugin_v2.py +++ b/neutron/tests/unit/db/test_db_base_plugin_v2.py @@ -4070,7 +4070,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): self.assertEqual(res.status_int, webob.exc.HTTPClientError.code) - def test_update_subnet_allocation_pools(self): + def _test_update_subnet_allocation_pools(self, with_gateway_ip=False): """Test that we can successfully update with sane params. This will create a subnet with specified allocation_pools @@ -4086,6 +4086,8 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): data = {'subnet': {'allocation_pools': [ {'start': '192.168.0.10', 'end': '192.168.0.20'}, {'start': '192.168.0.30', 'end': '192.168.0.40'}]}} + if with_gateway_ip: + data['subnet']['gateway_ip'] = '192.168.0.9' req = self.new_update_request('subnets', data, subnet['subnet']['id']) #check res code but then do GET on subnet for verification @@ -4099,6 +4101,15 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): res['subnet']['allocation_pools'][1].values() for pool_val in ['10', '20', '30', '40']: self.assertTrue('192.168.0.%s' % (pool_val) in res_vals) + if with_gateway_ip: + self.assertEqual((res['subnet']['gateway_ip']), + '192.168.0.9') + + def test_update_subnet_allocation_pools(self): + self._test_update_subnet_allocation_pools() + + def test_update_subnet_allocation_pools_and_gateway_ip(self): + self._test_update_subnet_allocation_pools(with_gateway_ip=True) #updating alloc pool to something outside subnet.cidr def test_update_subnet_allocation_pools_invalid_pool_for_cidr(self): -- 2.45.2