Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +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 | |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 13 | import copy |
Angus Salkeld | 011acc7 | 2015-01-16 20:26:34 +1000 | [diff] [blame] | 14 | import json |
| 15 | |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 16 | from heatclient import exc |
Pavlo Shchelokovskyy | 60e0ecd | 2014-12-14 22:17:21 +0200 | [diff] [blame] | 17 | import six |
Angus Salkeld | 011acc7 | 2015-01-16 20:26:34 +1000 | [diff] [blame] | 18 | import yaml |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 19 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 20 | from heat_integrationtests.functional import functional_base |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 21 | |
| 22 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 23 | class ResourceGroupTest(functional_base.FunctionalTestsBase): |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 24 | template = ''' |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 25 | heat_template_version: 2013-05-23 |
| 26 | resources: |
| 27 | random_group: |
| 28 | type: OS::Heat::ResourceGroup |
| 29 | properties: |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 30 | count: 0 |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 31 | resource_def: |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 32 | type: My::RandomString |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 33 | properties: |
| 34 | length: 30 |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 35 | salt: initial |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 36 | outputs: |
| 37 | random1: |
| 38 | value: {get_attr: [random_group, resource.0.value]} |
| 39 | random2: |
| 40 | value: {get_attr: [random_group, resource.1.value]} |
| 41 | all_values: |
| 42 | value: {get_attr: [random_group, value]} |
| 43 | ''' |
| 44 | |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 45 | def setUp(self): |
| 46 | super(ResourceGroupTest, self).setUp() |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 47 | |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 48 | def test_resource_group_zero_novalidate(self): |
| 49 | # Nested resources should be validated only when size > 0 |
| 50 | # This allows features to be disabled via size=0 without |
| 51 | # triggering validation of nested resource custom contraints |
| 52 | # e.g images etc in the nested schema. |
| 53 | nested_template_fail = ''' |
| 54 | heat_template_version: 2013-05-23 |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 55 | parameters: |
| 56 | length: |
| 57 | type: string |
| 58 | default: 50 |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 59 | salt: |
| 60 | type: string |
| 61 | default: initial |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 62 | resources: |
| 63 | random: |
| 64 | type: OS::Heat::RandomString |
| 65 | properties: |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 66 | length: BAD |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 67 | ''' |
| 68 | |
| 69 | files = {'provider.yaml': nested_template_fail} |
| 70 | env = {'resource_registry': |
| 71 | {'My::RandomString': 'provider.yaml'}} |
| 72 | stack_identifier = self.stack_create( |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 73 | template=self.template, |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 74 | files=files, |
| 75 | environment=env |
| 76 | ) |
| 77 | |
| 78 | self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'}, |
| 79 | self.list_resources(stack_identifier)) |
| 80 | |
| 81 | # Check we created an empty nested stack |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 82 | nested_identifier = self.group_nested_identifier(stack_identifier, |
| 83 | 'random_group') |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 84 | self.assertEqual({}, self.list_resources(nested_identifier)) |
| 85 | |
| 86 | # Prove validation works for non-zero create/update |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 87 | template_two_nested = self.template.replace("count: 0", "count: 2") |
Peter Razumovsky | d750079 | 2014-10-08 19:19:13 +0400 | [diff] [blame] | 88 | expected_err = "Value 'BAD' is not an integer" |
Steven Hardy | 6f0bda8 | 2014-12-12 17:49:10 +0000 | [diff] [blame] | 89 | ex = self.assertRaises(exc.HTTPBadRequest, self.update_stack, |
| 90 | stack_identifier, template_two_nested, |
| 91 | environment=env, files=files) |
| 92 | self.assertIn(expected_err, six.text_type(ex)) |
| 93 | |
| 94 | ex = self.assertRaises(exc.HTTPBadRequest, self.stack_create, |
| 95 | template=template_two_nested, |
| 96 | environment=env, files=files) |
| 97 | self.assertIn(expected_err, six.text_type(ex)) |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 98 | |
Steven Hardy | 0145b8d | 2015-04-23 14:14:26 +1000 | [diff] [blame] | 99 | def _validate_resources(self, stack_identifier, expected_count): |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 100 | resources = self.list_group_resources(stack_identifier, |
| 101 | 'random_group') |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 102 | self.assertEqual(expected_count, len(resources)) |
| 103 | expected_resources = dict( |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 104 | (str(idx), 'My::RandomString') |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 105 | for idx in range(expected_count)) |
| 106 | |
| 107 | self.assertEqual(expected_resources, resources) |
| 108 | |
| 109 | def test_create(self): |
| 110 | def validate_output(stack, output_key, length): |
| 111 | output_value = self._stack_output(stack, output_key) |
| 112 | self.assertEqual(length, len(output_value)) |
| 113 | return output_value |
| 114 | # verify that the resources in resource group are identically |
| 115 | # configured, resource names and outputs are appropriate. |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 116 | env = {'resource_registry': |
| 117 | {'My::RandomString': 'OS::Heat::RandomString'}} |
| 118 | create_template = self.template.replace("count: 0", "count: 2") |
| 119 | stack_identifier = self.stack_create(template=create_template, |
| 120 | environment=env) |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 121 | self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'}, |
| 122 | self.list_resources(stack_identifier)) |
| 123 | |
| 124 | # validate count, type and name of resources in a resource group. |
| 125 | self._validate_resources(stack_identifier, 2) |
| 126 | |
| 127 | # validate outputs |
| 128 | stack = self.client.stacks.get(stack_identifier) |
| 129 | outputs = [] |
| 130 | outputs.append(validate_output(stack, 'random1', 30)) |
| 131 | outputs.append(validate_output(stack, 'random2', 30)) |
| 132 | self.assertEqual(outputs, self._stack_output(stack, 'all_values')) |
| 133 | |
| 134 | def test_update_increase_decrease_count(self): |
| 135 | # create stack with resource group count 2 |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 136 | env = {'resource_registry': |
| 137 | {'My::RandomString': 'OS::Heat::RandomString'}} |
| 138 | create_template = self.template.replace("count: 0", "count: 2") |
| 139 | stack_identifier = self.stack_create(template=create_template, |
| 140 | environment=env) |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 141 | self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'}, |
| 142 | self.list_resources(stack_identifier)) |
| 143 | # verify that the resource group has 2 resources |
| 144 | self._validate_resources(stack_identifier, 2) |
| 145 | |
| 146 | # increase the resource group count to 5 |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 147 | update_template = self.template.replace("count: 0", "count: 5") |
| 148 | self.update_stack(stack_identifier, update_template, environment=env) |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 149 | # verify that the resource group has 5 resources |
| 150 | self._validate_resources(stack_identifier, 5) |
| 151 | |
| 152 | # decrease the resource group count to 3 |
Angus Salkeld | 665d86c | 2015-01-19 22:15:48 +1000 | [diff] [blame] | 153 | update_template = self.template.replace("count: 0", "count: 3") |
| 154 | self.update_stack(stack_identifier, update_template, environment=env) |
Unmesh Gurjar | 0a25a73 | 2014-12-23 17:28:33 +0530 | [diff] [blame] | 155 | # verify that the resource group has 3 resources |
| 156 | self._validate_resources(stack_identifier, 3) |
Angus Salkeld | 011acc7 | 2015-01-16 20:26:34 +1000 | [diff] [blame] | 157 | |
Steven Hardy | 0145b8d | 2015-04-23 14:14:26 +1000 | [diff] [blame] | 158 | def test_update_removal_policies(self): |
| 159 | rp_template = ''' |
| 160 | heat_template_version: 2014-10-16 |
| 161 | resources: |
| 162 | random_group: |
| 163 | type: OS::Heat::ResourceGroup |
| 164 | properties: |
| 165 | count: 5 |
| 166 | removal_policies: [] |
| 167 | resource_def: |
| 168 | type: OS::Heat::RandomString |
| 169 | ''' |
| 170 | |
| 171 | # create stack with resource group, initial count 5 |
| 172 | stack_identifier = self.stack_create(template=rp_template) |
| 173 | self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'}, |
| 174 | self.list_resources(stack_identifier)) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 175 | group_resources = self.list_group_resources(stack_identifier, |
| 176 | 'random_group') |
Steven Hardy | 0145b8d | 2015-04-23 14:14:26 +1000 | [diff] [blame] | 177 | expected_resources = {u'0': u'OS::Heat::RandomString', |
| 178 | u'1': u'OS::Heat::RandomString', |
| 179 | u'2': u'OS::Heat::RandomString', |
| 180 | u'3': u'OS::Heat::RandomString', |
| 181 | u'4': u'OS::Heat::RandomString'} |
| 182 | self.assertEqual(expected_resources, group_resources) |
| 183 | |
| 184 | # Remove three, specifying the middle resources to be removed |
| 185 | update_template = rp_template.replace( |
| 186 | 'removal_policies: []', |
| 187 | 'removal_policies: [{resource_list: [\'1\', \'2\', \'3\']}]') |
| 188 | self.update_stack(stack_identifier, update_template) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 189 | group_resources = self.list_group_resources(stack_identifier, |
| 190 | 'random_group') |
Steven Hardy | 0145b8d | 2015-04-23 14:14:26 +1000 | [diff] [blame] | 191 | expected_resources = {u'0': u'OS::Heat::RandomString', |
| 192 | u'4': u'OS::Heat::RandomString', |
| 193 | u'5': u'OS::Heat::RandomString', |
| 194 | u'6': u'OS::Heat::RandomString', |
| 195 | u'7': u'OS::Heat::RandomString'} |
| 196 | self.assertEqual(expected_resources, group_resources) |
| 197 | |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 198 | def test_props_update(self): |
| 199 | """Test update of resource_def properties behaves as expected.""" |
| 200 | |
| 201 | env = {'resource_registry': |
| 202 | {'My::RandomString': 'OS::Heat::RandomString'}} |
| 203 | template_one = self.template.replace("count: 0", "count: 1") |
| 204 | stack_identifier = self.stack_create(template=template_one, |
| 205 | environment=env) |
| 206 | self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'}, |
| 207 | self.list_resources(stack_identifier)) |
| 208 | |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 209 | initial_nested_ident = self.group_nested_identifier(stack_identifier, |
| 210 | 'random_group') |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 211 | self.assertEqual({'0': 'My::RandomString'}, |
| 212 | self.list_resources(initial_nested_ident)) |
| 213 | # get the resource id |
| 214 | res = self.client.resources.get(initial_nested_ident, '0') |
| 215 | initial_res_id = res.physical_resource_id |
| 216 | |
| 217 | # change the salt (this should replace the RandomString but |
| 218 | # not the nested stack or resource group. |
| 219 | template_salt = template_one.replace("salt: initial", "salt: more") |
| 220 | self.update_stack(stack_identifier, template_salt, environment=env) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 221 | updated_nested_ident = self.group_nested_identifier(stack_identifier, |
| 222 | 'random_group') |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 223 | self.assertEqual(initial_nested_ident, updated_nested_ident) |
| 224 | |
| 225 | # compare the resource id, we expect a change. |
| 226 | res = self.client.resources.get(updated_nested_ident, '0') |
| 227 | updated_res_id = res.physical_resource_id |
| 228 | self.assertNotEqual(initial_res_id, updated_res_id) |
| 229 | |
| 230 | def test_update_nochange(self): |
| 231 | """Test update with no properties change.""" |
| 232 | |
| 233 | env = {'resource_registry': |
| 234 | {'My::RandomString': 'OS::Heat::RandomString'}} |
Angus Salkeld | a89a028 | 2015-07-24 15:47:38 +1000 | [diff] [blame] | 235 | template_one = self.template.replace("count: 0", "count: 2") |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 236 | stack_identifier = self.stack_create(template=template_one, |
| 237 | environment=env) |
| 238 | self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'}, |
| 239 | self.list_resources(stack_identifier)) |
| 240 | |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 241 | initial_nested_ident = self.group_nested_identifier(stack_identifier, |
| 242 | 'random_group') |
Angus Salkeld | a89a028 | 2015-07-24 15:47:38 +1000 | [diff] [blame] | 243 | self.assertEqual({'0': 'My::RandomString', '1': 'My::RandomString'}, |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 244 | self.list_resources(initial_nested_ident)) |
| 245 | # get the output |
| 246 | stack0 = self.client.stacks.get(stack_identifier) |
| 247 | initial_rand = self._stack_output(stack0, 'random1') |
| 248 | |
| 249 | template_copy = copy.deepcopy(template_one) |
| 250 | self.update_stack(stack_identifier, template_copy, environment=env) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 251 | updated_nested_ident = self.group_nested_identifier(stack_identifier, |
| 252 | 'random_group') |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 253 | self.assertEqual(initial_nested_ident, updated_nested_ident) |
| 254 | |
| 255 | # compare the random number, we expect no change. |
| 256 | stack1 = self.client.stacks.get(stack_identifier) |
| 257 | updated_rand = self._stack_output(stack1, 'random1') |
| 258 | self.assertEqual(initial_rand, updated_rand) |
| 259 | |
| 260 | def test_update_nochange_resource_needs_update(self): |
Peter Razumovsky | f0ac958 | 2015-09-24 16:49:03 +0300 | [diff] [blame] | 261 | """Test update when the resource definition has changed. |
| 262 | |
| 263 | Test the scenario when the ResourceGroup update happens without |
| 264 | any changed properties, this can happen if the definition of |
| 265 | a contained provider resource changes (files map changes), then |
| 266 | the group and underlying nested stack should end up updated. |
| 267 | """ |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 268 | |
| 269 | random_templ1 = ''' |
| 270 | heat_template_version: 2013-05-23 |
| 271 | parameters: |
| 272 | length: |
| 273 | type: string |
| 274 | default: not-used |
| 275 | salt: |
| 276 | type: string |
| 277 | default: not-used |
| 278 | resources: |
| 279 | random1: |
| 280 | type: OS::Heat::RandomString |
| 281 | properties: |
| 282 | salt: initial |
| 283 | outputs: |
| 284 | value: |
| 285 | value: {get_attr: [random1, value]} |
| 286 | ''' |
| 287 | files1 = {'my_random.yaml': random_templ1} |
| 288 | |
| 289 | random_templ2 = random_templ1.replace('salt: initial', |
| 290 | 'salt: more') |
| 291 | files2 = {'my_random.yaml': random_templ2} |
| 292 | |
| 293 | env = {'resource_registry': |
| 294 | {'My::RandomString': 'my_random.yaml'}} |
| 295 | |
Angus Salkeld | a89a028 | 2015-07-24 15:47:38 +1000 | [diff] [blame] | 296 | template_one = self.template.replace("count: 0", "count: 2") |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 297 | stack_identifier = self.stack_create(template=template_one, |
| 298 | environment=env, |
| 299 | files=files1) |
| 300 | self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'}, |
| 301 | self.list_resources(stack_identifier)) |
| 302 | |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 303 | initial_nested_ident = self.group_nested_identifier(stack_identifier, |
| 304 | 'random_group') |
Angus Salkeld | a89a028 | 2015-07-24 15:47:38 +1000 | [diff] [blame] | 305 | self.assertEqual({'0': 'My::RandomString', '1': 'My::RandomString'}, |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 306 | self.list_resources(initial_nested_ident)) |
| 307 | # get the output |
| 308 | stack0 = self.client.stacks.get(stack_identifier) |
| 309 | initial_rand = self._stack_output(stack0, 'random1') |
| 310 | |
| 311 | # change the environment so we use a different TemplateResource. |
| 312 | # note "files2". |
| 313 | self.update_stack(stack_identifier, template_one, |
| 314 | environment=env, files=files2) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 315 | updated_nested_ident = self.group_nested_identifier(stack_identifier, |
| 316 | 'random_group') |
Angus Salkeld | b61f8f1 | 2015-01-19 23:00:45 +1000 | [diff] [blame] | 317 | self.assertEqual(initial_nested_ident, updated_nested_ident) |
| 318 | |
| 319 | # compare the output, we expect a change. |
| 320 | stack1 = self.client.stacks.get(stack_identifier) |
| 321 | updated_rand = self._stack_output(stack1, 'random1') |
| 322 | self.assertNotEqual(initial_rand, updated_rand) |
| 323 | |
Angus Salkeld | 011acc7 | 2015-01-16 20:26:34 +1000 | [diff] [blame] | 324 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 325 | class ResourceGroupTestNullParams(functional_base.FunctionalTestsBase): |
Angus Salkeld | 59b8f41 | 2015-02-25 21:01:12 +1000 | [diff] [blame] | 326 | template = ''' |
| 327 | heat_template_version: 2013-05-23 |
| 328 | parameters: |
| 329 | param: |
| 330 | type: empty |
| 331 | resources: |
| 332 | random_group: |
| 333 | type: OS::Heat::ResourceGroup |
| 334 | properties: |
| 335 | count: 1 |
| 336 | resource_def: |
| 337 | type: My::RandomString |
| 338 | properties: |
| 339 | param: {get_param: param} |
| 340 | outputs: |
| 341 | val: |
| 342 | value: {get_attr: [random_group, val]} |
| 343 | ''' |
| 344 | |
| 345 | nested_template_file = ''' |
| 346 | heat_template_version: 2013-05-23 |
| 347 | parameters: |
| 348 | param: |
| 349 | type: empty |
| 350 | outputs: |
| 351 | val: |
| 352 | value: {get_param: param} |
| 353 | ''' |
| 354 | |
| 355 | scenarios = [ |
| 356 | ('string_empty', dict( |
| 357 | param='', |
| 358 | p_type='string', |
| 359 | )), |
| 360 | ('boolean_false', dict( |
| 361 | param=False, |
| 362 | p_type='boolean', |
| 363 | )), |
| 364 | ('number_zero', dict( |
| 365 | param=0, |
| 366 | p_type='number', |
| 367 | )), |
| 368 | ('comma_delimited_list', dict( |
| 369 | param=[], |
| 370 | p_type='comma_delimited_list', |
| 371 | )), |
| 372 | ('json_empty', dict( |
| 373 | param={}, |
| 374 | p_type='json', |
| 375 | )), |
| 376 | ] |
| 377 | |
| 378 | def setUp(self): |
| 379 | super(ResourceGroupTestNullParams, self).setUp() |
Angus Salkeld | 59b8f41 | 2015-02-25 21:01:12 +1000 | [diff] [blame] | 380 | |
| 381 | def test_create_pass_zero_parameter(self): |
| 382 | templ = self.template.replace('type: empty', |
| 383 | 'type: %s' % self.p_type) |
| 384 | n_t_f = self.nested_template_file.replace('type: empty', |
| 385 | 'type: %s' % self.p_type) |
| 386 | files = {'provider.yaml': n_t_f} |
| 387 | env = {'resource_registry': |
| 388 | {'My::RandomString': 'provider.yaml'}} |
| 389 | stack_identifier = self.stack_create( |
| 390 | template=templ, |
| 391 | files=files, |
| 392 | environment=env, |
| 393 | parameters={'param': self.param} |
| 394 | ) |
| 395 | stack = self.client.stacks.get(stack_identifier) |
| 396 | self.assertEqual(self.param, self._stack_output(stack, 'val')[0]) |
| 397 | |
| 398 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 399 | class ResourceGroupAdoptTest(functional_base.FunctionalTestsBase): |
Angus Salkeld | 011acc7 | 2015-01-16 20:26:34 +1000 | [diff] [blame] | 400 | """Prove that we can do resource group adopt.""" |
| 401 | |
| 402 | main_template = ''' |
| 403 | heat_template_version: "2013-05-23" |
| 404 | resources: |
| 405 | group1: |
| 406 | type: OS::Heat::ResourceGroup |
| 407 | properties: |
| 408 | count: 2 |
| 409 | resource_def: |
| 410 | type: OS::Heat::RandomString |
| 411 | outputs: |
| 412 | test0: |
| 413 | value: {get_attr: [group1, resource.0.value]} |
| 414 | test1: |
| 415 | value: {get_attr: [group1, resource.1.value]} |
| 416 | ''' |
| 417 | |
| 418 | def setUp(self): |
| 419 | super(ResourceGroupAdoptTest, self).setUp() |
Angus Salkeld | 011acc7 | 2015-01-16 20:26:34 +1000 | [diff] [blame] | 420 | |
| 421 | def _yaml_to_json(self, yaml_templ): |
Bo Wang | d8df4dd | 2016-02-16 21:23:53 +0800 | [diff] [blame] | 422 | return yaml.safe_load(yaml_templ) |
Angus Salkeld | 011acc7 | 2015-01-16 20:26:34 +1000 | [diff] [blame] | 423 | |
| 424 | def test_adopt(self): |
| 425 | data = { |
| 426 | "resources": { |
| 427 | "group1": { |
| 428 | "status": "COMPLETE", |
| 429 | "name": "group1", |
| 430 | "resource_data": {}, |
| 431 | "metadata": {}, |
| 432 | "resource_id": "test-group1-id", |
| 433 | "action": "CREATE", |
| 434 | "type": "OS::Heat::ResourceGroup", |
| 435 | "resources": { |
| 436 | "0": { |
| 437 | "status": "COMPLETE", |
| 438 | "name": "0", |
| 439 | "resource_data": {"value": "goopie"}, |
| 440 | "resource_id": "ID-0", |
| 441 | "action": "CREATE", |
| 442 | "type": "OS::Heat::RandomString", |
| 443 | "metadata": {} |
| 444 | }, |
| 445 | "1": { |
| 446 | "status": "COMPLETE", |
| 447 | "name": "1", |
| 448 | "resource_data": {"value": "different"}, |
| 449 | "resource_id": "ID-1", |
| 450 | "action": "CREATE", |
| 451 | "type": "OS::Heat::RandomString", |
| 452 | "metadata": {} |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | }, |
| 457 | "environment": {"parameters": {}}, |
Bo Wang | d8df4dd | 2016-02-16 21:23:53 +0800 | [diff] [blame] | 458 | "template": yaml.safe_load(self.main_template) |
Angus Salkeld | 011acc7 | 2015-01-16 20:26:34 +1000 | [diff] [blame] | 459 | } |
| 460 | stack_identifier = self.stack_adopt( |
| 461 | adopt_data=json.dumps(data)) |
| 462 | |
| 463 | self.assert_resource_is_a_stack(stack_identifier, 'group1') |
| 464 | stack = self.client.stacks.get(stack_identifier) |
| 465 | self.assertEqual('goopie', self._stack_output(stack, 'test0')) |
| 466 | self.assertEqual('different', self._stack_output(stack, 'test1')) |
Steve Baker | 75ee9d1 | 2015-07-22 10:56:55 +1200 | [diff] [blame] | 467 | |
| 468 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 469 | class ResourceGroupErrorResourceTest(functional_base.FunctionalTestsBase): |
Steve Baker | 75ee9d1 | 2015-07-22 10:56:55 +1200 | [diff] [blame] | 470 | template = ''' |
| 471 | heat_template_version: "2013-05-23" |
| 472 | resources: |
| 473 | group1: |
| 474 | type: OS::Heat::ResourceGroup |
| 475 | properties: |
| 476 | count: 2 |
| 477 | resource_def: |
| 478 | type: fail.yaml |
| 479 | ''' |
| 480 | nested_templ = ''' |
| 481 | heat_template_version: "2013-05-23" |
| 482 | resources: |
| 483 | oops: |
| 484 | type: OS::Heat::TestResource |
| 485 | properties: |
| 486 | fail: true |
| 487 | wait_secs: 2 |
| 488 | ''' |
| 489 | |
| 490 | def setUp(self): |
| 491 | super(ResourceGroupErrorResourceTest, self).setUp() |
Steve Baker | 75ee9d1 | 2015-07-22 10:56:55 +1200 | [diff] [blame] | 492 | |
| 493 | def test_fail(self): |
| 494 | stack_identifier = self.stack_create( |
| 495 | template=self.template, |
| 496 | files={'fail.yaml': self.nested_templ}, |
| 497 | expected_status='CREATE_FAILED', |
| 498 | enable_cleanup=False) |
| 499 | stack = self.client.stacks.get(stack_identifier) |
| 500 | |
| 501 | self.assertEqual('CREATE_FAILED', stack.stack_status) |
| 502 | self.client.stacks.delete(stack_identifier) |
| 503 | self._wait_for_stack_status( |
| 504 | stack_identifier, 'DELETE_COMPLETE', |
| 505 | success_on_not_found=True) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 506 | |
| 507 | |
| 508 | class ResourceGroupUpdatePolicyTest(functional_base.FunctionalTestsBase): |
| 509 | |
| 510 | template = ''' |
| 511 | heat_template_version: '2015-04-30' |
| 512 | resources: |
| 513 | random_group: |
| 514 | type: OS::Heat::ResourceGroup |
| 515 | update_policy: |
| 516 | rolling_update: |
| 517 | min_in_service: 1 |
| 518 | max_batch_size: 2 |
| 519 | pause_time: 1 |
| 520 | properties: |
| 521 | count: 10 |
| 522 | resource_def: |
| 523 | type: OS::Heat::TestResource |
| 524 | properties: |
| 525 | value: initial |
| 526 | update_replace: False |
| 527 | ''' |
| 528 | |
| 529 | def update_resource_group(self, update_template, |
| 530 | updated, created, deleted): |
| 531 | stack_identifier = self.stack_create(template=self.template) |
| 532 | group_resources = self.list_group_resources(stack_identifier, |
| 533 | 'random_group', |
| 534 | minimal=False) |
| 535 | |
| 536 | init_names = [res.physical_resource_id for res in group_resources] |
| 537 | |
| 538 | self.update_stack(stack_identifier, update_template) |
| 539 | group_resources = self.list_group_resources(stack_identifier, |
| 540 | 'random_group', |
| 541 | minimal=False) |
| 542 | |
| 543 | updt_names = [res.physical_resource_id for res in group_resources] |
| 544 | |
| 545 | matched_names = set(updt_names) & set(init_names) |
| 546 | |
| 547 | self.assertEqual(updated, len(matched_names)) |
| 548 | |
| 549 | self.assertEqual(created, len(set(updt_names) - set(init_names))) |
| 550 | |
| 551 | self.assertEqual(deleted, len(set(init_names) - set(updt_names))) |
| 552 | |
| 553 | def test_resource_group_update(self): |
| 554 | """Test rolling update with no conflict. |
| 555 | |
| 556 | Simple rolling update with no conflict in batch size |
| 557 | and minimum instances in service. |
| 558 | """ |
Bo Wang | d8df4dd | 2016-02-16 21:23:53 +0800 | [diff] [blame] | 559 | updt_template = yaml.safe_load(copy.deepcopy(self.template)) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 560 | grp = updt_template['resources']['random_group'] |
| 561 | policy = grp['update_policy']['rolling_update'] |
| 562 | policy['min_in_service'] = '1' |
| 563 | policy['max_batch_size'] = '3' |
| 564 | res_def = grp['properties']['resource_def'] |
| 565 | res_def['properties']['value'] = 'updated' |
| 566 | |
| 567 | self.update_resource_group(updt_template, |
| 568 | updated=10, |
| 569 | created=0, |
| 570 | deleted=0) |
| 571 | |
| 572 | def test_resource_group_update_replace(self): |
| 573 | """Test rolling update(replace)with no conflict. |
| 574 | |
| 575 | Simple rolling update replace with no conflict in batch size |
| 576 | and minimum instances in service. |
| 577 | """ |
Bo Wang | d8df4dd | 2016-02-16 21:23:53 +0800 | [diff] [blame] | 578 | updt_template = yaml.safe_load(copy.deepcopy(self.template)) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 579 | grp = updt_template['resources']['random_group'] |
| 580 | policy = grp['update_policy']['rolling_update'] |
| 581 | policy['min_in_service'] = '1' |
| 582 | policy['max_batch_size'] = '3' |
| 583 | res_def = grp['properties']['resource_def'] |
| 584 | res_def['properties']['value'] = 'updated' |
| 585 | res_def['properties']['update_replace'] = True |
| 586 | |
| 587 | self.update_resource_group(updt_template, |
| 588 | updated=0, |
| 589 | created=10, |
| 590 | deleted=10) |
| 591 | |
| 592 | def test_resource_group_update_scaledown(self): |
| 593 | """Test rolling update with scaledown. |
| 594 | |
| 595 | Simple rolling update with reduced size. |
| 596 | """ |
Bo Wang | d8df4dd | 2016-02-16 21:23:53 +0800 | [diff] [blame] | 597 | updt_template = yaml.safe_load(copy.deepcopy(self.template)) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 598 | grp = updt_template['resources']['random_group'] |
| 599 | policy = grp['update_policy']['rolling_update'] |
| 600 | policy['min_in_service'] = '1' |
| 601 | policy['max_batch_size'] = '3' |
| 602 | grp['properties']['count'] = 6 |
| 603 | res_def = grp['properties']['resource_def'] |
| 604 | res_def['properties']['value'] = 'updated' |
| 605 | |
| 606 | self.update_resource_group(updt_template, |
| 607 | updated=6, |
| 608 | created=0, |
| 609 | deleted=4) |
| 610 | |
| 611 | def test_resource_group_update_scaleup(self): |
| 612 | """Test rolling update with scaleup. |
| 613 | |
| 614 | Simple rolling update with increased size. |
| 615 | """ |
Bo Wang | d8df4dd | 2016-02-16 21:23:53 +0800 | [diff] [blame] | 616 | updt_template = yaml.safe_load(copy.deepcopy(self.template)) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 617 | grp = updt_template['resources']['random_group'] |
| 618 | policy = grp['update_policy']['rolling_update'] |
| 619 | policy['min_in_service'] = '1' |
| 620 | policy['max_batch_size'] = '3' |
| 621 | grp['properties']['count'] = 12 |
| 622 | res_def = grp['properties']['resource_def'] |
| 623 | res_def['properties']['value'] = 'updated' |
| 624 | |
| 625 | self.update_resource_group(updt_template, |
| 626 | updated=10, |
| 627 | created=2, |
| 628 | deleted=0) |
| 629 | |
| 630 | def test_resource_group_update_adjusted(self): |
| 631 | """Test rolling update with enough available resources |
| 632 | |
| 633 | Update with capacity adjustment with enough resources. |
| 634 | """ |
Bo Wang | d8df4dd | 2016-02-16 21:23:53 +0800 | [diff] [blame] | 635 | updt_template = yaml.safe_load(copy.deepcopy(self.template)) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 636 | grp = updt_template['resources']['random_group'] |
| 637 | policy = grp['update_policy']['rolling_update'] |
| 638 | policy['min_in_service'] = '8' |
| 639 | policy['max_batch_size'] = '4' |
| 640 | grp['properties']['count'] = 6 |
| 641 | res_def = grp['properties']['resource_def'] |
| 642 | res_def['properties']['value'] = 'updated' |
| 643 | |
| 644 | self.update_resource_group(updt_template, |
| 645 | updated=6, |
| 646 | created=0, |
| 647 | deleted=4) |
| 648 | |
| 649 | def test_resource_group_update_with_adjusted_capacity(self): |
| 650 | """Test rolling update with capacity adjustment. |
| 651 | |
| 652 | Rolling update with capacity adjustment due to conflict in |
| 653 | batch size and minimum instances in service. |
| 654 | """ |
Bo Wang | d8df4dd | 2016-02-16 21:23:53 +0800 | [diff] [blame] | 655 | updt_template = yaml.safe_load(copy.deepcopy(self.template)) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 656 | grp = updt_template['resources']['random_group'] |
| 657 | policy = grp['update_policy']['rolling_update'] |
| 658 | policy['min_in_service'] = '8' |
| 659 | policy['max_batch_size'] = '4' |
| 660 | res_def = grp['properties']['resource_def'] |
| 661 | res_def['properties']['value'] = 'updated' |
| 662 | |
| 663 | self.update_resource_group(updt_template, |
| 664 | updated=10, |
| 665 | created=0, |
| 666 | deleted=0) |
| 667 | |
| 668 | def test_resource_group_update_huge_batch_size(self): |
| 669 | """Test rolling update with huge batch size. |
| 670 | |
| 671 | Rolling Update with a huge batch size(more than |
| 672 | current size). |
| 673 | """ |
Bo Wang | d8df4dd | 2016-02-16 21:23:53 +0800 | [diff] [blame] | 674 | updt_template = yaml.safe_load(copy.deepcopy(self.template)) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 675 | grp = updt_template['resources']['random_group'] |
| 676 | policy = grp['update_policy']['rolling_update'] |
| 677 | policy['min_in_service'] = '0' |
| 678 | policy['max_batch_size'] = '20' |
| 679 | res_def = grp['properties']['resource_def'] |
| 680 | res_def['properties']['value'] = 'updated' |
| 681 | self.update_resource_group(updt_template, |
| 682 | updated=10, |
| 683 | created=0, |
| 684 | deleted=0) |
| 685 | |
| 686 | def test_resource_group_update_huge_min_in_service(self): |
| 687 | """Test rolling update with huge minimum capacity. |
| 688 | |
| 689 | Rolling Update with a huge number of minimum instances |
| 690 | in service. |
| 691 | """ |
Bo Wang | d8df4dd | 2016-02-16 21:23:53 +0800 | [diff] [blame] | 692 | updt_template = yaml.safe_load(copy.deepcopy(self.template)) |
Rabi Mishra | 8bcff8a | 2015-09-21 18:15:04 +0530 | [diff] [blame] | 693 | grp = updt_template['resources']['random_group'] |
| 694 | policy = grp['update_policy']['rolling_update'] |
| 695 | policy['min_in_service'] = '20' |
| 696 | policy['max_batch_size'] = '1' |
| 697 | res_def = grp['properties']['resource_def'] |
| 698 | res_def['properties']['value'] = 'updated' |
| 699 | |
| 700 | self.update_resource_group(updt_template, |
| 701 | updated=10, |
| 702 | created=0, |
| 703 | deleted=0) |