Merge "Check gateway ip when update subnet" into stable/liberty

This commit is contained in:
Jenkins 2016-01-23 07:48:40 +00:00 committed by Gerrit Code Review
commit 30b53c9cc5
3 changed files with 41 additions and 5 deletions

View File

@ -705,13 +705,12 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
s['allocation_pools'] = range_pools
# If either gateway_ip or allocation_pools were specified
new_gateway_ip = s.get('gateway_ip')
gateway_ip_changed = (new_gateway_ip and
new_gateway_ip != db_subnet.gateway_ip)
gateway_ip = s.get('gateway_ip', db_subnet.gateway_ip)
gateway_ip_changed = gateway_ip != db_subnet.gateway_ip
if gateway_ip_changed or s.get('allocation_pools') is not None:
gateway_ip = new_gateway_ip or db_subnet.gateway_ip
pools = range_pools if range_pools is not None else db_pools
self.ipam.validate_gw_out_of_pools(gateway_ip, pools)
if gateway_ip:
self.ipam.validate_gw_out_of_pools(gateway_ip, pools)
if gateway_ip_changed:
# Provide pre-update notification not to break plugins that don't

View File

@ -4653,6 +4653,37 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
self.assertEqual(data['subnet']['host_routes'],
res['subnet']['host_routes'])
def _test_update_subnet(self, old_gw=None, new_gw=None,
check_gateway=False):
allocation_pools = [{'start': '192.168.0.16', 'end': '192.168.0.254'}]
with self.network() as network:
with self.subnet(network=network,
gateway_ip=old_gw,
allocation_pools=allocation_pools,
cidr='192.168.0.0/24') as subnet:
data = {
'subnet': {
'allocation_pools': [
{'start': '192.168.0.10', 'end': '192.168.0.20'},
{'start': '192.168.0.30', 'end': '192.168.0.40'}],
'gateway_ip': new_gw}}
req = self.new_update_request('subnets', data,
subnet['subnet']['id'])
res = req.get_response(self.api)
self.assertEqual(200, res.status_code)
self._verify_updated_subnet_allocation_pools(
res, with_gateway_ip=check_gateway)
def test_update_subnet_from_no_gw_to_no_gw(self):
self._test_update_subnet()
def test_update_subnet_from_gw_to_no_gw(self):
self._test_update_subnet(old_gw='192.168.0.15')
def test_update_subnet_from_gw_to_new_gw(self):
self._test_update_subnet(old_gw='192.168.0.15',
new_gw='192.168.0.9', check_gateway=True)
def test_update_subnet_route_with_too_many_entries(self):
with self.subnet() as subnet:
data = {'subnet': {'host_routes': [

View File

@ -221,6 +221,12 @@ class TestContrailSubnetsV2(test_plugin.TestSubnetsV2,
def test_delete_subnet_dhcp_port_associated_with_other_subnets(self):
self.skipTest("There is no dhcp port in contrail")
def test_update_subnet_from_gw_to_no_gw(self):
self.skipTest("There is no empty gateway support in contrail")
def test_update_subnet_from_no_gw_to_no_gw(self):
self.skipTest("There is no empty gateway support in contrail")
def _helper_test_validate_subnet(self, option, exception):
cfg.CONF.set_override(option, 0)
with self.network() as network: