Jason Dunsmore | b5aa902 | 2015-09-09 16:57:04 -0500 | [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 | |
| 14 | from heat_integrationtests.functional import functional_base |
| 15 | |
| 16 | test_template_one_resource = { |
| 17 | 'heat_template_version': '2013-05-23', |
| 18 | 'description': 'Test template to create one instance.', |
| 19 | 'resources': { |
| 20 | 'test1': { |
| 21 | 'type': 'OS::Heat::TestResource', |
| 22 | 'properties': { |
| 23 | 'value': 'Test1', |
| 24 | 'fail': False, |
| 25 | 'update_replace': False, |
| 26 | 'wait_secs': 0 |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | test_template_two_resource = { |
| 33 | 'heat_template_version': '2013-05-23', |
| 34 | 'description': 'Test template to create two instance.', |
| 35 | 'resources': { |
| 36 | 'test1': { |
| 37 | 'type': 'OS::Heat::TestResource', |
| 38 | 'properties': { |
| 39 | 'value': 'Test1', |
| 40 | 'fail': False, |
| 41 | 'update_replace': False, |
| 42 | 'wait_secs': 0 |
| 43 | } |
| 44 | }, |
| 45 | 'test2': { |
| 46 | 'type': 'OS::Heat::TestResource', |
| 47 | 'properties': { |
| 48 | 'value': 'Test1', |
| 49 | 'fail': False, |
| 50 | 'update_replace': False, |
| 51 | 'wait_secs': 0 |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | class UpdatePreviewStackTest(functional_base.FunctionalTestsBase): |
| 59 | |
| 60 | def setUp(self): |
| 61 | super(UpdatePreviewStackTest, self).setUp() |
| 62 | self.stack_identifier = self.stack_create( |
| 63 | template=test_template_one_resource) |
| 64 | |
| 65 | def test_add_resource(self): |
| 66 | result = self.preview_update_stack(self.stack_identifier, |
| 67 | test_template_two_resource) |
| 68 | changes = result['resource_changes'] |
| 69 | |
| 70 | unchanged = changes['unchanged'][0]['resource_name'] |
| 71 | self.assertEqual('test1', unchanged) |
| 72 | |
| 73 | added = changes['added'][0]['resource_name'] |
| 74 | self.assertEqual('test2', added) |
| 75 | |
| 76 | empty_sections = ('updated', 'replaced', 'deleted') |
| 77 | for section in empty_sections: |
| 78 | self.assertEqual([], changes[section]) |
| 79 | |
| 80 | def test_no_change(self): |
| 81 | result = self.preview_update_stack(self.stack_identifier, |
| 82 | test_template_one_resource) |
| 83 | changes = result['resource_changes'] |
| 84 | |
| 85 | unchanged = changes['unchanged'][0]['resource_name'] |
| 86 | self.assertEqual('test1', unchanged) |
| 87 | |
| 88 | empty_sections = ('updated', 'replaced', 'deleted', 'added') |
| 89 | for section in empty_sections: |
| 90 | self.assertEqual([], changes[section]) |
| 91 | |
| 92 | def test_update_resource(self): |
| 93 | test_template_updated_resource = { |
| 94 | 'heat_template_version': '2013-05-23', |
| 95 | 'description': 'Test template to create one instance.', |
| 96 | 'resources': { |
| 97 | 'test1': { |
| 98 | 'type': 'OS::Heat::TestResource', |
| 99 | 'properties': { |
| 100 | 'value': 'Test1 foo', |
| 101 | 'fail': False, |
| 102 | 'update_replace': False, |
| 103 | 'wait_secs': 0 |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | result = self.preview_update_stack(self.stack_identifier, |
| 110 | test_template_updated_resource) |
| 111 | changes = result['resource_changes'] |
| 112 | |
| 113 | updated = changes['updated'][0]['resource_name'] |
| 114 | self.assertEqual('test1', updated) |
| 115 | |
| 116 | empty_sections = ('added', 'unchanged', 'replaced', 'deleted') |
| 117 | for section in empty_sections: |
| 118 | self.assertEqual([], changes[section]) |
| 119 | |
| 120 | def test_replaced_resource(self): |
| 121 | orig_template = { |
| 122 | 'heat_template_version': '2013-05-23', |
| 123 | 'description': 'Test template to create one instance.', |
| 124 | 'resources': { |
| 125 | 'test1': { |
| 126 | 'type': 'OS::Heat::TestResource', |
| 127 | 'properties': { |
| 128 | 'update_replace': False, |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | new_template = { |
| 135 | 'heat_template_version': '2013-05-23', |
| 136 | 'description': 'Test template to create one instance.', |
| 137 | 'resources': { |
| 138 | 'test1': { |
| 139 | 'type': 'OS::Heat::TestResource', |
| 140 | 'properties': { |
| 141 | 'update_replace': True, |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | stack_identifier = self.stack_create(template=orig_template) |
| 148 | result = self.preview_update_stack(stack_identifier, new_template) |
| 149 | changes = result['resource_changes'] |
| 150 | |
| 151 | replaced = changes['replaced'][0]['resource_name'] |
| 152 | self.assertEqual('test1', replaced) |
| 153 | |
| 154 | empty_sections = ('added', 'unchanged', 'updated', 'deleted') |
| 155 | for section in empty_sections: |
| 156 | self.assertEqual([], changes[section]) |
| 157 | |
| 158 | def test_delete_resource(self): |
| 159 | stack_identifier = self.stack_create( |
| 160 | template=test_template_two_resource) |
| 161 | result = self.preview_update_stack(stack_identifier, |
| 162 | test_template_one_resource) |
| 163 | changes = result['resource_changes'] |
| 164 | |
| 165 | unchanged = changes['unchanged'][0]['resource_name'] |
| 166 | self.assertEqual('test1', unchanged) |
| 167 | |
| 168 | deleted = changes['deleted'][0]['resource_name'] |
| 169 | self.assertEqual('test2', deleted) |
| 170 | |
| 171 | empty_sections = ('updated', 'replaced', 'added') |
| 172 | for section in empty_sections: |
| 173 | self.assertEqual([], changes[section]) |