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
This commit is contained in:
armando-migliaccio 2013-07-09 19:08:49 -07:00
parent d80048eefc
commit 40a5853970
2 changed files with 15 additions and 1 deletions

View 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)

View 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'}}