blob: 6dad7f2c06983a0bc2793569f7f4dd2dcc8b772a [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
27 allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}]
28outputs:
29 alloc_pools:
30 value: {get_attr: [subnet, allocation_pools]}
31'''
32
33
34class UpdateSubnetTest(functional_base.FunctionalTestsBase):
35
36 def setUp(self):
37 super(UpdateSubnetTest, self).setUp()
38
39 def get_alloc_pools(self, stack_identifier):
40 stack = self.client.stacks.get(stack_identifier)
41 alloc_pools = self._stack_output(stack, 'alloc_pools')
42 return alloc_pools
43
44 def test_update_allocation_pools(self):
45 stack_identifier = self.stack_create(template=test_template)
46 alloc_pools = self.get_alloc_pools(stack_identifier)
47 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)
55 new_alloc_pools = self.get_alloc_pools(stack_identifier)
56 # 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)
62 alloc_pools = self.get_alloc_pools(stack_identifier)
63 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)
71 new_alloc_pools = self.get_alloc_pools(stack_identifier)
72 # 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)
77 alloc_pools = self.get_alloc_pools(stack_identifier)
78 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)
86 last_alloc_pools = self.get_alloc_pools(stack_identifier)
87 # last_alloc_pools should be []
88 self.assertEqual([], last_alloc_pools)