huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 1 | # 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 | |
| 13 | from heat_integrationtests.functional import functional_base |
| 14 | |
| 15 | |
| 16 | test_template = ''' |
| 17 | heat_template_version: 2015-04-30 |
| 18 | description: Test template to create/update subnet with allocation_pools. |
| 19 | resources: |
| 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 |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 27 | gateway_ip: 11.11.11.5 |
huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 28 | allocation_pools: [{start: 11.11.11.10, end: 11.11.11.250}] |
| 29 | outputs: |
| 30 | alloc_pools: |
| 31 | value: {get_attr: [subnet, allocation_pools]} |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 32 | gateway_ip: |
| 33 | value: {get_attr: [subnet, gateway_ip]} |
huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 34 | ''' |
| 35 | |
| 36 | |
| 37 | class UpdateSubnetTest(functional_base.FunctionalTestsBase): |
| 38 | |
| 39 | def setUp(self): |
| 40 | super(UpdateSubnetTest, self).setUp() |
| 41 | |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 42 | def get_outputs(self, stack_identifier, output_key): |
huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 43 | stack = self.client.stacks.get(stack_identifier) |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 44 | output = self._stack_output(stack, output_key) |
| 45 | return output |
huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 46 | |
| 47 | def test_update_allocation_pools(self): |
| 48 | stack_identifier = self.stack_create(template=test_template) |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 49 | alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools') |
huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 50 | 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) |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 58 | new_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools') |
huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 59 | # 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) |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 65 | alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools') |
huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 66 | 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) |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 74 | new_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools') |
huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 75 | # 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) |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 80 | alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools') |
huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 81 | 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) |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 89 | last_alloc_pools = self.get_outputs(stack_identifier, 'alloc_pools') |
huangtianhua | 80519eb | 2015-10-31 17:55:54 +0800 | [diff] [blame] | 90 | # last_alloc_pools should be [] |
| 91 | self.assertEqual([], last_alloc_pools) |
huangtianhua | 9593716 | 2015-10-31 11:26:55 +0800 | [diff] [blame] | 92 | |
| 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) |