]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Allow gateway address to be unset for an existing subnet
authorarmando-migliaccio <amigliaccio@nicira.com>
Wed, 10 Jul 2013 02:08:49 +0000 (19:08 -0700)
committerarmando-migliaccio <amigliaccio@nicira.com>
Wed, 10 Jul 2013 02:14:08 +0000 (19:14 -0700)
Validation of the gateway IP address was taken place even
if the gateway IP was set to None; this was causing an
AddrFormatError exception to be raised by method
'_validate_gw_out_of_pools'. With this change we skip
the validation in case the gateway is set to None.

Fixes bug #1178273

Change-Id: Ib84378a4fd2cefdbbcacce695abbfaf82c647dd3

neutron/db/db_base_plugin_v2.py
neutron/tests/unit/test_db_plugin.py

index 7378c951f5877ecb3234ff817b41000b2d9d6527..cdb71632fdd64ae122d9c2c558bed99f84938065 100644 (file)
@@ -1205,7 +1205,7 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
         s['cidr'] = db_subnet.cidr
         self._validate_subnet(s)
 
-        if 'gateway_ip' in s:
+        if 'gateway_ip' in s and s['gateway_ip'] is not None:
             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)
index 4df9200d71316ce65bbab53c6a8873f17b58c5b5..458019cbdab589199f0cdb61c9daf5f4af88f4e0 100644 (file)
@@ -2972,6 +2972,20 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
             res = subnet_req.get_response(self.api)
             self.assertEqual(res.status_int, 400)
 
+    def test_update_subnet_no_gateway(self):
+        with self.subnet() as subnet:
+            data = {'subnet': {'gateway_ip': '11.0.0.1'}}
+            req = self.new_update_request('subnets', data,
+                                          subnet['subnet']['id'])
+            res = self.deserialize(self.fmt, req.get_response(self.api))
+            self.assertEqual(res['subnet']['gateway_ip'],
+                             data['subnet']['gateway_ip'])
+            data = {'subnet': {'gateway_ip': None}}
+            req = self.new_update_request('subnets', data,
+                                          subnet['subnet']['id'])
+            res = self.deserialize(self.fmt, req.get_response(self.api))
+            self.assertEqual(None, data['subnet']['gateway_ip'])
+
     def test_update_subnet(self):
         with self.subnet() as subnet:
             data = {'subnet': {'gateway_ip': '11.0.0.1'}}