Merge "Improve gateway_ip updation for subnet"

This commit is contained in:
Jenkins 2016-01-08 03:15:30 +00:00 committed by Gerrit Code Review
commit c4d6d17e64
3 changed files with 65 additions and 15 deletions

View File

@ -137,9 +137,12 @@ class Subnet(neutron.NeutronResource):
),
GATEWAY_IP: properties.Schema(
properties.Schema.STRING,
_('The gateway IP address. Set to any of [ null | ~ | "" ] to '
'create the subnet without a gateway. If omitted, the first IP '
'address within the subnet is assigned to the gateway.'),
_('The gateway IP address. Set to any of [ null | ~ | "" ] '
'to create/update a subnet without a gateway. '
'If omitted when creation, neutron will assign the first '
'free IP address within the subnet to the gateway '
'automatically. If remove this from template when update, '
'the old gateway IP address will be detached.'),
update_allowed=True
),
ENABLE_DHCP: properties.Schema(
@ -354,6 +357,10 @@ class Subnet(neutron.NeutronResource):
if (self.NAME in prop_diff and
prop_diff[self.NAME] is None):
prop_diff[self.NAME] = self.physical_resource_name()
# If the new value is '', set to None
self._null_gateway_ip(prop_diff)
self.client().update_subnet(
self.resource_id, {'subnet': prop_diff})

View File

@ -121,9 +121,10 @@ class NeutronSubnetTest(common.HeatTestCase):
'enable_dhcp': True,
'host_routes': [{'destination': '192.168.1.0/24',
'nexthop': '194.168.1.2'}],
"allocation_pools": [
{"start": "10.0.3.20", "end": "10.0.3.100"},
{"start": "10.0.3.110", "end": "10.0.3.200"}]}}
'gateway_ip': '10.0.3.105',
'allocation_pools': [
{'start': '10.0.3.20', 'end': '10.0.3.100'},
{'start': '10.0.3.110', 'end': '10.0.3.200'}]}}
t = self._test_subnet(u_props=update_props)
neutronV20.find_resourceid_by_name_or_id(

View File

@ -24,10 +24,13 @@ resources:
properties:
network: { get_resource: net }
cidr: 11.11.11.0/24
gateway_ip: 11.11.11.5
allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]
outputs:
alloc_pools:
value: {get_attr: [subnet, allocation_pools]}
gateway_ip:
value: {get_attr: [subnet, gateway_ip]}
'''
@ -36,14 +39,14 @@ class UpdateSubnetTest(functional_base.FunctionalTestsBase):
def setUp(self):
super(UpdateSubnetTest, self).setUp()
def get_alloc_pools(self, stack_identifier):
def get_outputs(self, stack_identifier, output_key):
stack = self.client.stacks.get(stack_identifier)
alloc_pools = self._stack_output(stack, 'alloc_pools')
return alloc_pools
output = self._stack_output(stack, output_key)
return output
def test_update_allocation_pools(self):
stack_identifier = self.stack_create(template=test_template)
alloc_pools = self.get_alloc_pools(stack_identifier)
alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
alloc_pools)
@ -52,14 +55,14 @@ class UpdateSubnetTest(functional_base.FunctionalTestsBase):
'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.100}]')
self.update_stack(stack_identifier, templ_other_pool)
new_alloc_pools = self.get_alloc_pools(stack_identifier)
new_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
# the new pools should be the new range
self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.100'}],
new_alloc_pools)
def test_update_allocation_pools_to_empty(self):
stack_identifier = self.stack_create(template=test_template)
alloc_pools = self.get_alloc_pools(stack_identifier)
alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
alloc_pools)
@ -68,13 +71,13 @@ class UpdateSubnetTest(functional_base.FunctionalTestsBase):
'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
'allocation_pools: []')
self.update_stack(stack_identifier, templ_empty_pools)
new_alloc_pools = self.get_alloc_pools(stack_identifier)
new_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
# new_alloc_pools should be []
self.assertEqual([], new_alloc_pools)
def test_update_to_no_allocation_pools(self):
stack_identifier = self.stack_create(template=test_template)
alloc_pools = self.get_alloc_pools(stack_identifier)
alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
alloc_pools)
@ -83,6 +86,45 @@ class UpdateSubnetTest(functional_base.FunctionalTestsBase):
'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
'')
self.update_stack(stack_identifier, templ_no_pools)
last_alloc_pools = self.get_alloc_pools(stack_identifier)
last_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
# last_alloc_pools should be []
self.assertEqual([], last_alloc_pools)
def test_update_gateway_ip(self):
stack_identifier = self.stack_create(template=test_template)
gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
self.assertEqual('11.11.11.5', gw_ip)
# Update gateway_ip
templ_other_gw_ip = test_template.replace(
'gateway_ip: 11.11.11.5', 'gateway_ip: 11.11.11.9')
self.update_stack(stack_identifier, templ_other_gw_ip)
new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
# the gateway_ip should be the new one
self.assertEqual('11.11.11.9', new_gw_ip)
def test_update_gateway_ip_to_empty(self):
stack_identifier = self.stack_create(template=test_template)
gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
self.assertEqual('11.11.11.5', gw_ip)
# Update gateway_ip to null(resolve to '')
templ_empty_gw_ip = test_template.replace(
'gateway_ip: 11.11.11.5', 'gateway_ip: null')
self.update_stack(stack_identifier, templ_empty_gw_ip)
new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
# new gateway_ip should be None
self.assertIsNone(new_gw_ip)
def test_update_to_no_gateway_ip(self):
stack_identifier = self.stack_create(template=test_template)
gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
self.assertEqual('11.11.11.5', gw_ip)
# Remove the gateway from template
templ_no_gw_ip = test_template.replace(
'gateway_ip: 11.11.11.5', '')
self.update_stack(stack_identifier, templ_no_gw_ip)
new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
# new gateway_ip should be None
self.assertIsNone(new_gw_ip)