blob: 31ad6f5ba265551f9b495907a3fcee2b1119a201 [file] [log] [blame]
huangtianhua80519eb2015-10-31 17:55:54 +08001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from heat_integrationtests.functional import functional_base
14
15
16test_template = '''
17heat_template_version: 2015-04-30
18description: Test template to create/update subnet with allocation_pools.
19resources:
20 net:
21 type: OS::Neutron::Net
22 subnet:
23 type: OS::Neutron::Subnet
24 properties:
25 network: { get_resource: net }
26 cidr: 11.11.11.0/24
huangtianhua95937162015-10-31 11:26:55 +080027 gateway_ip: 11.11.11.5
huangtianhua80519eb2015-10-31 17:55:54 +080028 allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]
29outputs:
30 alloc_pools:
31 value: {get_attr: [subnet, allocation_pools]}
huangtianhua95937162015-10-31 11:26:55 +080032 gateway_ip:
33 value: {get_attr: [subnet, gateway_ip]}
huangtianhua80519eb2015-10-31 17:55:54 +080034'''
35
36
37class UpdateSubnetTest(functional_base.FunctionalTestsBase):
38
huangtianhua95937162015-10-31 11:26:55 +080039 def get_outputs(self, stack_identifier, output_key):
huangtianhua80519eb2015-10-31 17:55:54 +080040 stack = self.client.stacks.get(stack_identifier)
huangtianhua95937162015-10-31 11:26:55 +080041 output = self._stack_output(stack, output_key)
42 return output
huangtianhua80519eb2015-10-31 17:55:54 +080043
44 def test_update_allocation_pools(self):
45 stack_identifier = self.stack_create(template=test_template)
huangtianhua95937162015-10-31 11:26:55 +080046 alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080047 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
48 alloc_pools)
49
50 # Update allocation_pools with a new range
51 templ_other_pool = test_template.replace(
52 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
53 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.100}]')
54 self.update_stack(stack_identifier, templ_other_pool)
huangtianhua95937162015-10-31 11:26:55 +080055 new_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080056 # the new pools should be the new range
57 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.100'}],
58 new_alloc_pools)
59
60 def test_update_allocation_pools_to_empty(self):
61 stack_identifier = self.stack_create(template=test_template)
huangtianhua95937162015-10-31 11:26:55 +080062 alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080063 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
64 alloc_pools)
65
66 # Update allocation_pools with []
67 templ_empty_pools = test_template.replace(
68 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
69 'allocation_pools: []')
70 self.update_stack(stack_identifier, templ_empty_pools)
huangtianhua95937162015-10-31 11:26:55 +080071 new_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080072 # new_alloc_pools should be []
73 self.assertEqual([], new_alloc_pools)
74
75 def test_update_to_no_allocation_pools(self):
76 stack_identifier = self.stack_create(template=test_template)
huangtianhua95937162015-10-31 11:26:55 +080077 alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080078 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
79 alloc_pools)
80
81 # Remove the allocation_pools from template
82 templ_no_pools = test_template.replace(
83 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
84 '')
85 self.update_stack(stack_identifier, templ_no_pools)
huangtianhua95937162015-10-31 11:26:55 +080086 last_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080087 # last_alloc_pools should be []
88 self.assertEqual([], last_alloc_pools)
huangtianhua95937162015-10-31 11:26:55 +080089
90 def test_update_gateway_ip(self):
91 stack_identifier = self.stack_create(template=test_template)
92 gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
93 self.assertEqual('11.11.11.5', gw_ip)
94
95 # Update gateway_ip
96 templ_other_gw_ip = test_template.replace(
97 'gateway_ip: 11.11.11.5', 'gateway_ip: 11.11.11.9')
98 self.update_stack(stack_identifier, templ_other_gw_ip)
99 new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
100 # the gateway_ip should be the new one
101 self.assertEqual('11.11.11.9', new_gw_ip)
102
103 def test_update_gateway_ip_to_empty(self):
104 stack_identifier = self.stack_create(template=test_template)
105 gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
106 self.assertEqual('11.11.11.5', gw_ip)
107
108 # Update gateway_ip to null(resolve to '')
109 templ_empty_gw_ip = test_template.replace(
110 'gateway_ip: 11.11.11.5', 'gateway_ip: null')
111 self.update_stack(stack_identifier, templ_empty_gw_ip)
112 new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
113 # new gateway_ip should be None
114 self.assertIsNone(new_gw_ip)
115
116 def test_update_to_no_gateway_ip(self):
117 stack_identifier = self.stack_create(template=test_template)
118 gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
119 self.assertEqual('11.11.11.5', gw_ip)
120
121 # Remove the gateway from template
122 templ_no_gw_ip = test_template.replace(
123 'gateway_ip: 11.11.11.5', '')
124 self.update_stack(stack_identifier, templ_no_gw_ip)
125 new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
126 # new gateway_ip should be None
127 self.assertIsNone(new_gw_ip)