diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 7378c951f5..cdb71632fd 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -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) diff --git a/neutron/tests/unit/test_db_plugin.py b/neutron/tests/unit/test_db_plugin.py index 4df9200d71..458019cbda 100644 --- a/neutron/tests/unit/test_db_plugin.py +++ b/neutron/tests/unit/test_db_plugin.py @@ -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'}}