From 40a5853970cdd1555dfb5ebce81c6babf2e445da Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Tue, 9 Jul 2013 19:08:49 -0700 Subject: [PATCH] Allow gateway address to be unset for an existing subnet 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 | 2 +- neutron/tests/unit/test_db_plugin.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 7378c951f58..cdb71632fdd 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 4df9200d713..458019cbdab 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'}}