]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix subnet updating failure on valid allocation pools
authorTomoaki Sato <tomoaki.sato@gmail.com>
Mon, 29 Jun 2015 01:02:20 +0000 (10:02 +0900)
committerTomoaki Sato <tomoaki.sato@gmail.com>
Mon, 29 Jun 2015 04:01:57 +0000 (13:01 +0900)
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
neutron/tests/unit/db/test_db_base_plugin_v2.py

index 9ca165e5b0110d7059944dadfaf90f033f68a89a..7a953983ac4c8c025fff59e30ea37033a111637b 100644 (file)
@@ -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):
index fbc20d27c051f65e1afeb62513c45adbbacc808b..241c6e90ad9d6c0b76d7f6079c97ecd17ce71075 100644 (file)
@@ -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):