blob: ceb74a9e6a282b840973491ae1dd2c46bfb9ec99 [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
39 def setUp(self):
40 super(UpdateSubnetTest, self).setUp()
41
huangtianhua95937162015-10-31 11:26:55 +080042 def get_outputs(self, stack_identifier, output_key):
huangtianhua80519eb2015-10-31 17:55:54 +080043 stack = self.client.stacks.get(stack_identifier)
huangtianhua95937162015-10-31 11:26:55 +080044 output = self._stack_output(stack, output_key)
45 return output
huangtianhua80519eb2015-10-31 17:55:54 +080046
47 def test_update_allocation_pools(self):
48 stack_identifier = self.stack_create(template=test_template)
huangtianhua95937162015-10-31 11:26:55 +080049 alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080050 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
51 alloc_pools)
52
53 # Update allocation_pools with a new range
54 templ_other_pool = test_template.replace(
55 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
56 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.100}]')
57 self.update_stack(stack_identifier, templ_other_pool)
huangtianhua95937162015-10-31 11:26:55 +080058 new_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080059 # the new pools should be the new range
60 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.100'}],
61 new_alloc_pools)
62
63 def test_update_allocation_pools_to_empty(self):
64 stack_identifier = self.stack_create(template=test_template)
huangtianhua95937162015-10-31 11:26:55 +080065 alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080066 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
67 alloc_pools)
68
69 # Update allocation_pools with []
70 templ_empty_pools = test_template.replace(
71 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
72 'allocation_pools: []')
73 self.update_stack(stack_identifier, templ_empty_pools)
huangtianhua95937162015-10-31 11:26:55 +080074 new_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080075 # new_alloc_pools should be []
76 self.assertEqual([], new_alloc_pools)
77
78 def test_update_to_no_allocation_pools(self):
79 stack_identifier = self.stack_create(template=test_template)
huangtianhua95937162015-10-31 11:26:55 +080080 alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080081 self.assertEqual([{'start': '11.11.11.10', 'end': '11.11.11.250'}],
82 alloc_pools)
83
84 # Remove the allocation_pools from template
85 templ_no_pools = test_template.replace(
86 'allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]',
87 '')
88 self.update_stack(stack_identifier, templ_no_pools)
huangtianhua95937162015-10-31 11:26:55 +080089 last_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools')
huangtianhua80519eb2015-10-31 17:55:54 +080090 # last_alloc_pools should be []
91 self.assertEqual([], last_alloc_pools)
huangtianhua95937162015-10-31 11:26:55 +080092
93 def test_update_gateway_ip(self):
94 stack_identifier = self.stack_create(template=test_template)
95 gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
96 self.assertEqual('11.11.11.5', gw_ip)
97
98 # Update gateway_ip
99 templ_other_gw_ip = test_template.replace(
100 'gateway_ip: 11.11.11.5', 'gateway_ip: 11.11.11.9')
101 self.update_stack(stack_identifier, templ_other_gw_ip)
102 new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
103 # the gateway_ip should be the new one
104 self.assertEqual('11.11.11.9', new_gw_ip)
105
106 def test_update_gateway_ip_to_empty(self):
107 stack_identifier = self.stack_create(template=test_template)
108 gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
109 self.assertEqual('11.11.11.5', gw_ip)
110
111 # Update gateway_ip to null(resolve to '')
112 templ_empty_gw_ip = test_template.replace(
113 'gateway_ip: 11.11.11.5', 'gateway_ip: null')
114 self.update_stack(stack_identifier, templ_empty_gw_ip)
115 new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
116 # new gateway_ip should be None
117 self.assertIsNone(new_gw_ip)
118
119 def test_update_to_no_gateway_ip(self):
120 stack_identifier = self.stack_create(template=test_template)
121 gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
122 self.assertEqual('11.11.11.5', gw_ip)
123
124 # Remove the gateway from template
125 templ_no_gw_ip = test_template.replace(
126 'gateway_ip: 11.11.11.5', '')
127 self.update_stack(stack_identifier, templ_no_gw_ip)
128 new_gw_ip = self.get_outputs(stack_identifier, 'gateway_ip')
129 # new gateway_ip should be None
130 self.assertIsNone(new_gw_ip)