James Combs | 3a17869 | 2015-12-29 17:32:23 +0000 | [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 | from heatclient import exc as heat_exceptions |
| 15 | |
| 16 | |
| 17 | class ImmutableParametersTest(functional_base.FunctionalTestsBase): |
| 18 | |
| 19 | template_param_has_no_immutable_field = ''' |
| 20 | heat_template_version: 2014-10-16 |
| 21 | parameters: |
| 22 | param1: |
| 23 | type: string |
| 24 | default: default_value |
| 25 | outputs: |
| 26 | param1_output: |
| 27 | description: 'parameter 1 details' |
| 28 | value: { get_param: param1 } |
| 29 | ''' |
| 30 | |
| 31 | template_param_has_immutable_field = ''' |
| 32 | heat_template_version: 2014-10-16 |
| 33 | parameters: |
| 34 | param1: |
| 35 | type: string |
| 36 | default: default_value |
| 37 | immutable: false |
| 38 | outputs: |
| 39 | param1_output: |
| 40 | description: 'parameter 1 details' |
| 41 | value: { get_param: param1 } |
| 42 | ''' |
| 43 | |
| 44 | def test_no_immutable_param_field(self): |
| 45 | param1_create_value = 'value1' |
| 46 | create_parameters = {"param1": param1_create_value} |
| 47 | |
| 48 | stack_identifier = self.stack_create( |
| 49 | template=self.template_param_has_no_immutable_field, |
| 50 | parameters=create_parameters |
| 51 | ) |
| 52 | stack = self.client.stacks.get(stack_identifier) |
| 53 | |
| 54 | # Verify the value of the parameter |
| 55 | self.assertEqual(param1_create_value, |
| 56 | self._stack_output(stack, 'param1_output')) |
| 57 | |
| 58 | param1_update_value = 'value2' |
| 59 | update_parameters = {"param1": param1_update_value} |
| 60 | |
| 61 | self.update_stack( |
| 62 | stack_identifier, |
| 63 | template=self.template_param_has_no_immutable_field, |
| 64 | parameters=update_parameters) |
| 65 | |
| 66 | stack = self.client.stacks.get(stack_identifier) |
| 67 | |
| 68 | # Verify the value of the updated parameter |
| 69 | self.assertEqual(param1_update_value, |
| 70 | self._stack_output(stack, 'param1_output')) |
| 71 | |
| 72 | def test_immutable_param_field_allowed(self): |
| 73 | param1_create_value = 'value1' |
| 74 | create_parameters = {"param1": param1_create_value} |
| 75 | |
| 76 | stack_identifier = self.stack_create( |
| 77 | template=self.template_param_has_immutable_field, |
| 78 | parameters=create_parameters |
| 79 | ) |
| 80 | stack = self.client.stacks.get(stack_identifier) |
| 81 | |
| 82 | # Verify the value of the parameter |
| 83 | self.assertEqual(param1_create_value, |
| 84 | self._stack_output(stack, 'param1_output')) |
| 85 | |
| 86 | param1_update_value = 'value2' |
| 87 | update_parameters = {"param1": param1_update_value} |
| 88 | |
| 89 | self.update_stack( |
| 90 | stack_identifier, |
| 91 | template=self.template_param_has_immutable_field, |
| 92 | parameters=update_parameters) |
| 93 | stack = self.client.stacks.get(stack_identifier) |
| 94 | |
| 95 | # Verify the value of the updated parameter |
| 96 | self.assertEqual(param1_update_value, |
| 97 | self._stack_output(stack, 'param1_output')) |
| 98 | |
| 99 | # Ensure stack is not in a failed state |
| 100 | self.assertEqual('UPDATE_COMPLETE', stack.stack_status) |
| 101 | |
| 102 | def test_immutable_param_field_error(self): |
| 103 | param1_create_value = 'value1' |
| 104 | create_parameters = {"param1": param1_create_value} |
| 105 | |
| 106 | # Toggle the immutable field to preclude updating |
| 107 | immutable_true = self.template_param_has_immutable_field.replace( |
| 108 | 'immutable: false', 'immutable: true') |
| 109 | |
| 110 | stack_identifier = self.stack_create( |
| 111 | template=immutable_true, |
| 112 | parameters=create_parameters |
| 113 | ) |
| 114 | stack = self.client.stacks.get(stack_identifier) |
| 115 | |
| 116 | param1_update_value = 'value2' |
| 117 | update_parameters = {"param1": param1_update_value} |
| 118 | |
| 119 | # Verify the value of the parameter |
| 120 | self.assertEqual(param1_create_value, |
| 121 | self._stack_output(stack, 'param1_output')) |
| 122 | |
| 123 | # Attempt to update the stack with a new parameter value |
| 124 | try: |
| 125 | self.update_stack( |
| 126 | stack_identifier, |
| 127 | template=immutable_true, |
| 128 | parameters=update_parameters) |
Jason Dunsmore | 2087529 | 2016-02-25 14:23:37 -0600 | [diff] [blame^] | 129 | except heat_exceptions.HTTPBadRequest as exc: |
James Combs | 3a17869 | 2015-12-29 17:32:23 +0000 | [diff] [blame] | 130 | exp = ('The following parameters are immutable and may not be ' |
| 131 | 'updated: param1') |
| 132 | self.assertIn(exp, str(exc)) |
| 133 | |
| 134 | stack = self.client.stacks.get(stack_identifier) |
| 135 | |
| 136 | # Ensure stack is not in a failed state |
| 137 | self.assertEqual('CREATE_COMPLETE', stack.stack_status) |
| 138 | |
| 139 | # Ensure immutable parameter has not changed |
| 140 | self.assertEqual(param1_create_value, |
| 141 | self._stack_output(stack, 'param1_output')) |