blob: b74561968a47304f6799dbf7f5d65fb695afc7d1 [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
rabif9681be2016-09-07 09:08:50 +053036test_template_with_translation = '''
37heat_template_version: 2016-10-14
38description: Test template to create/update subnet with translation
39parameters:
40 net_cidr:
41 type: string
42resources:
43 net:
44 type: OS::Neutron::Net
45 net_value:
46 type: OS::Heat::Value
47 properties:
48 value: {get_resource: net}
49 subnet:
50 type: OS::Neutron::Subnet
51 properties:
52 network: { get_attr: [net_value, value] }
53 cidr: {get_param: net_cidr}
54'''
55
huangtianhua80519eb2015-10-31 17:55:54 +080056
57class UpdateSubnetTest(functional_base.FunctionalTestsBase):
58
huangtianhua95937162015-10-31 11:26:55 +080059 def get_outputs(self, stack_identifier, output_key):
huangtianhua80519eb2015-10-31 17:55:54 +080060 stack = self.client.stacks.get(stack_identifier)
huangtianhua95937162015-10-31 11:26:55 +080061 output = self._stack_output(stack, output_key)
62 return output
huangtianhua80519eb2015-10-31 17:55:54 +080063
64 def test_update_allocation_pools(self):
65 stack_identifier = self.stack_create(template=test_template)
huangtianhua95937162015-10-31 11:26:55 +080066 alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080067 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
68 alloc_pools)
69
70 # Update allocation_pools with a new range
71 templ_other_pool = test_template.replace(
72 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
73 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.100}]')
74 self.update_stack(stack_identifier, templ_other_pool)
huangtianhua95937162015-10-31 11:26:55 +080075 new_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080076 # the new pools should be the new range
77 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.100'}],
78 new_alloc_pools)
79
80 def test_update_allocation_pools_to_empty(self):
81 stack_identifier = self.stack_create(template=test_template)
huangtianhua95937162015-10-31 11:26:55 +080082 alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080083 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
84 alloc_pools)
85
86 # Update allocation_pools with []
87 templ_empty_pools = test_template.replace(
88 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
89 'allocation_pools: []')
90 self.update_stack(stack_identifier, templ_empty_pools)
huangtianhua95937162015-10-31 11:26:55 +080091 new_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080092 # new_alloc_pools should be []
93 self.assertEqual([], new_alloc_pools)
94
95 def test_update_to_no_allocation_pools(self):
96 stack_identifier = self.stack_create(template=test_template)
huangtianhua95937162015-10-31 11:26:55 +080097 alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080098 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
99 alloc_pools)
100
101 # Remove the allocation_pools from template
102 templ_no_pools = test_template.replace(
103 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
104 '')
105 self.update_stack(stack_identifier, templ_no_pools)
huangtianhua95937162015-10-31 11:26:55 +0800106 last_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +0800107 # last_alloc_pools should be []
108 self.assertEqual([], last_alloc_pools)
huangtianhua95937162015-10-31 11:26:55 +0800109
110 def test_update_gateway_ip(self):
111 stack_identifier = self.stack_create(template=test_template)
112 gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
113 self.assertEqual('11.11.11.5', gw_ip)
114
115 # Update gateway_ip
116 templ_other_gw_ip = test_template.replace(
117 'gateway_ip: 11.11.11.5', 'gateway_ip: 11.11.11.9')
118 self.update_stack(stack_identifier, templ_other_gw_ip)
119 new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
120 # the gateway_ip should be the new one
121 self.assertEqual('11.11.11.9', new_gw_ip)
122
123 def test_update_gateway_ip_to_empty(self):
124 stack_identifier = self.stack_create(template=test_template)
125 gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
126 self.assertEqual('11.11.11.5', gw_ip)
127
128 # Update gateway_ip to null(resolve to '')
129 templ_empty_gw_ip = test_template.replace(
130 'gateway_ip: 11.11.11.5', 'gateway_ip: null')
131 self.update_stack(stack_identifier, templ_empty_gw_ip)
132 new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
133 # new gateway_ip should be None
134 self.assertIsNone(new_gw_ip)
135
136 def test_update_to_no_gateway_ip(self):
137 stack_identifier = self.stack_create(template=test_template)
138 gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
139 self.assertEqual('11.11.11.5', gw_ip)
140
141 # Remove the gateway from template
142 templ_no_gw_ip = test_template.replace(
143 'gateway_ip: 11.11.11.5', '')
144 self.update_stack(stack_identifier, templ_no_gw_ip)
145 new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
146 # new gateway_ip should be None
147 self.assertIsNone(new_gw_ip)
rabif9681be2016-09-07 09:08:50 +0530148
149 def test_update_with_network_translation(self):
150 # Just create and update where network is translated properly.
151 env = {'parameters': {'net_cidr': '11.11.11.0/24'}}
152 stack_identifier = self.stack_create(
153 template=test_template_with_translation,
154 environment=env)
155 env = {'parameters': {'net_cidr': '11.11.12.0/24'}}
156 self.update_stack(stack_identifier,
157 template=test_template_with_translation,
158 environment=env)