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 | |
Jason Dunsmore | b5aa902 | 2015-09-09 16:57:04 -0500 | [diff] [blame] | 13 | from heat_integrationtests.functional import functional_base |
| 14 | |
| 15 | test_template_one_resource = { |
| 16 | 'heat_template_version': '2013-05-23', |
| 17 | 'description': 'Test template to create one instance.', |
| 18 | 'resources': { |
| 19 | 'test1': { |
| 20 | 'type': 'OS::Heat::TestResource', |
| 21 | 'properties': { |
| 22 | 'value': 'Test1', |
| 23 | 'fail': False, |
| 24 | 'update_replace': False, |
| 25 | 'wait_secs': 0 |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | test_template_two_resource = { |
| 32 | 'heat_template_version': '2013-05-23', |
| 33 | 'description': 'Test template to create two instance.', |
| 34 | 'resources': { |
| 35 | 'test1': { |
| 36 | 'type': 'OS::Heat::TestResource', |
| 37 | 'properties': { |
| 38 | 'value': 'Test1', |
| 39 | 'fail': False, |
| 40 | 'update_replace': False, |
| 41 | 'wait_secs': 0 |
| 42 | } |
| 43 | }, |
| 44 | 'test2': { |
| 45 | 'type': 'OS::Heat::TestResource', |
| 46 | 'properties': { |
| 47 | 'value': 'Test1', |
| 48 | 'fail': False, |
| 49 | 'update_replace': False, |
| 50 | 'wait_secs': 0 |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | |
| 57 | class UpdatePreviewStackTest(functional_base.FunctionalTestsBase): |
| 58 | |
Steven Hardy | 09ae1b0 | 2016-01-18 11:31:52 +0000 | [diff] [blame] | 59 | def test_add_resource(self): |
Jason Dunsmore | b5aa902 | 2015-09-09 16:57:04 -0500 | [diff] [blame] | 60 | self.stack_identifier = self.stack_create( |
| 61 | template=test_template_one_resource) |
Jason Dunsmore | b5aa902 | 2015-09-09 16:57:04 -0500 | [diff] [blame] | 62 | result = self.preview_update_stack(self.stack_identifier, |
| 63 | test_template_two_resource) |
| 64 | changes = result['resource_changes'] |
| 65 | |
| 66 | unchanged = changes['unchanged'][0]['resource_name'] |
| 67 | self.assertEqual('test1', unchanged) |
| 68 | |
| 69 | added = changes['added'][0]['resource_name'] |
| 70 | self.assertEqual('test2', added) |
| 71 | |
| 72 | empty_sections = ('updated', 'replaced', 'deleted') |
| 73 | for section in empty_sections: |
| 74 | self.assertEqual([], changes[section]) |
| 75 | |
| 76 | def test_no_change(self): |
Steven Hardy | 09ae1b0 | 2016-01-18 11:31:52 +0000 | [diff] [blame] | 77 | self.stack_identifier = self.stack_create( |
| 78 | template=test_template_one_resource) |
Jason Dunsmore | b5aa902 | 2015-09-09 16:57:04 -0500 | [diff] [blame] | 79 | result = self.preview_update_stack(self.stack_identifier, |
| 80 | test_template_one_resource) |
| 81 | changes = result['resource_changes'] |
| 82 | |
| 83 | unchanged = changes['unchanged'][0]['resource_name'] |
| 84 | self.assertEqual('test1', unchanged) |
| 85 | |
| 86 | empty_sections = ('updated', 'replaced', 'deleted', 'added') |
| 87 | for section in empty_sections: |
| 88 | self.assertEqual([], changes[section]) |
| 89 | |
| 90 | def test_update_resource(self): |
Steven Hardy | 09ae1b0 | 2016-01-18 11:31:52 +0000 | [diff] [blame] | 91 | self.stack_identifier = self.stack_create( |
| 92 | template=test_template_one_resource) |
Jason Dunsmore | b5aa902 | 2015-09-09 16:57:04 -0500 | [diff] [blame] | 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): |
Steven Hardy | 09ae1b0 | 2016-01-18 11:31:52 +0000 | [diff] [blame] | 121 | self.stack_identifier = self.stack_create( |
| 122 | template=test_template_one_resource) |
Jason Dunsmore | b5aa902 | 2015-09-09 16:57:04 -0500 | [diff] [blame] | 123 | new_template = { |
| 124 | 'heat_template_version': '2013-05-23', |
| 125 | 'description': 'Test template to create one instance.', |
| 126 | 'resources': { |
| 127 | 'test1': { |
| 128 | 'type': 'OS::Heat::TestResource', |
| 129 | 'properties': { |
| 130 | 'update_replace': True, |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
Steven Hardy | 09ae1b0 | 2016-01-18 11:31:52 +0000 | [diff] [blame] | 136 | result = self.preview_update_stack(self.stack_identifier, new_template) |
Jason Dunsmore | b5aa902 | 2015-09-09 16:57:04 -0500 | [diff] [blame] | 137 | changes = result['resource_changes'] |
| 138 | |
| 139 | replaced = changes['replaced'][0]['resource_name'] |
| 140 | self.assertEqual('test1', replaced) |
| 141 | |
| 142 | empty_sections = ('added', 'unchanged', 'updated', 'deleted') |
| 143 | for section in empty_sections: |
| 144 | self.assertEqual([], changes[section]) |
| 145 | |
| 146 | def test_delete_resource(self): |
Steven Hardy | 09ae1b0 | 2016-01-18 11:31:52 +0000 | [diff] [blame] | 147 | self.stack_identifier = self.stack_create( |
Jason Dunsmore | b5aa902 | 2015-09-09 16:57:04 -0500 | [diff] [blame] | 148 | template=test_template_two_resource) |
Steven Hardy | 09ae1b0 | 2016-01-18 11:31:52 +0000 | [diff] [blame] | 149 | result = self.preview_update_stack(self.stack_identifier, |
Jason Dunsmore | b5aa902 | 2015-09-09 16:57:04 -0500 | [diff] [blame] | 150 | test_template_one_resource) |
| 151 | changes = result['resource_changes'] |
| 152 | |
| 153 | unchanged = changes['unchanged'][0]['resource_name'] |
| 154 | self.assertEqual('test1', unchanged) |
| 155 | |
| 156 | deleted = changes['deleted'][0]['resource_name'] |
| 157 | self.assertEqual('test2', deleted) |
| 158 | |
| 159 | empty_sections = ('updated', 'replaced', 'added') |
| 160 | for section in empty_sections: |
| 161 | self.assertEqual([], changes[section]) |