Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [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 | import json |
Pavlo Shchelokovskyy | 60e0ecd | 2014-12-14 22:17:21 +0200 | [diff] [blame] | 14 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 15 | import yaml |
| 16 | |
| 17 | from heat_integrationtests.common import test |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 18 | from heat_integrationtests.functional import functional_base |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 19 | |
| 20 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 21 | class TemplateResourceTest(functional_base.FunctionalTestsBase): |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 22 | """Prove that we can use the registry in a nested provider.""" |
Angus Salkeld | 95403d8 | 2015-02-12 14:06:01 +1000 | [diff] [blame] | 23 | |
| 24 | template = ''' |
| 25 | heat_template_version: 2013-05-23 |
| 26 | resources: |
| 27 | secret1: |
| 28 | type: OS::Heat::RandomString |
| 29 | outputs: |
| 30 | secret-out: |
| 31 | value: { get_attr: [secret1, value] } |
| 32 | ''' |
| 33 | nested_templ = ''' |
| 34 | heat_template_version: 2013-05-23 |
| 35 | resources: |
| 36 | secret2: |
| 37 | type: OS::Heat::RandomString |
| 38 | outputs: |
| 39 | value: |
| 40 | value: { get_attr: [secret2, value] } |
| 41 | ''' |
| 42 | |
| 43 | env_templ = ''' |
| 44 | resource_registry: |
| 45 | "OS::Heat::RandomString": nested.yaml |
| 46 | ''' |
| 47 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 48 | def setUp(self): |
| 49 | super(TemplateResourceTest, self).setUp() |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 50 | |
| 51 | def test_nested_env(self): |
| 52 | main_templ = ''' |
| 53 | heat_template_version: 2013-05-23 |
| 54 | resources: |
| 55 | secret1: |
| 56 | type: My::NestedSecret |
| 57 | outputs: |
| 58 | secret-out: |
| 59 | value: { get_attr: [secret1, value] } |
| 60 | ''' |
| 61 | |
| 62 | nested_templ = ''' |
| 63 | heat_template_version: 2013-05-23 |
| 64 | resources: |
| 65 | secret2: |
| 66 | type: My::Secret |
| 67 | outputs: |
| 68 | value: |
| 69 | value: { get_attr: [secret2, value] } |
| 70 | ''' |
| 71 | |
| 72 | env_templ = ''' |
| 73 | resource_registry: |
| 74 | "My::Secret": "OS::Heat::RandomString" |
| 75 | "My::NestedSecret": nested.yaml |
| 76 | ''' |
| 77 | |
| 78 | stack_identifier = self.stack_create( |
| 79 | template=main_templ, |
| 80 | files={'nested.yaml': nested_templ}, |
| 81 | environment=env_templ) |
Angus Salkeld | 2e61f9f | 2015-04-07 09:25:50 +1000 | [diff] [blame] | 82 | nested_ident = self.assert_resource_is_a_stack(stack_identifier, |
| 83 | 'secret1') |
| 84 | # prove that resource.parent_resource is populated. |
| 85 | sec2 = self.client.resources.get(nested_ident, 'secret2') |
| 86 | self.assertEqual('secret1', sec2.parent_resource) |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 87 | |
| 88 | def test_no_infinite_recursion(self): |
| 89 | """Prove that we can override a python resource. |
| 90 | |
| 91 | And use that resource within the template resource. |
| 92 | """ |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 93 | stack_identifier = self.stack_create( |
Angus Salkeld | 95403d8 | 2015-02-12 14:06:01 +1000 | [diff] [blame] | 94 | template=self.template, |
| 95 | files={'nested.yaml': self.nested_templ}, |
| 96 | environment=self.env_templ) |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 97 | self.assert_resource_is_a_stack(stack_identifier, 'secret1') |
| 98 | |
Angus Salkeld | 95403d8 | 2015-02-12 14:06:01 +1000 | [diff] [blame] | 99 | def test_nested_stack_delete_then_delete_parent_stack(self): |
| 100 | """Check the robustness of stack deletion. |
| 101 | |
| 102 | This tests that if you manually delete a nested |
| 103 | stack, the parent stack is still deletable. |
| 104 | """ |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 105 | # disable cleanup so we can call _stack_delete() directly. |
| 106 | stack_identifier = self.stack_create( |
Angus Salkeld | 95403d8 | 2015-02-12 14:06:01 +1000 | [diff] [blame] | 107 | template=self.template, |
| 108 | files={'nested.yaml': self.nested_templ}, |
| 109 | environment=self.env_templ, |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 110 | enable_cleanup=False) |
Angus Salkeld | 95403d8 | 2015-02-12 14:06:01 +1000 | [diff] [blame] | 111 | |
| 112 | nested_ident = self.assert_resource_is_a_stack(stack_identifier, |
| 113 | 'secret1') |
| 114 | |
| 115 | self._stack_delete(nested_ident) |
| 116 | self._stack_delete(stack_identifier) |
| 117 | |
Angus Salkeld | 19b9e1d | 2015-05-08 11:02:38 +1000 | [diff] [blame] | 118 | def test_change_in_file_path(self): |
| 119 | stack_identifier = self.stack_create( |
| 120 | template=self.template, |
| 121 | files={'nested.yaml': self.nested_templ}, |
| 122 | environment=self.env_templ) |
| 123 | stack = self.client.stacks.get(stack_identifier) |
| 124 | secret_out1 = self._stack_output(stack, 'secret-out') |
| 125 | |
| 126 | nested_templ_2 = ''' |
| 127 | heat_template_version: 2013-05-23 |
| 128 | resources: |
| 129 | secret2: |
| 130 | type: OS::Heat::RandomString |
| 131 | outputs: |
| 132 | value: |
| 133 | value: freddy |
| 134 | ''' |
| 135 | env_templ_2 = ''' |
| 136 | resource_registry: |
| 137 | "OS::Heat::RandomString": new/nested.yaml |
| 138 | ''' |
| 139 | self.update_stack(stack_identifier, |
| 140 | template=self.template, |
| 141 | files={'new/nested.yaml': nested_templ_2}, |
| 142 | environment=env_templ_2) |
| 143 | stack = self.client.stacks.get(stack_identifier) |
| 144 | secret_out2 = self._stack_output(stack, 'secret-out') |
| 145 | self.assertNotEqual(secret_out1, secret_out2) |
| 146 | self.assertEqual('freddy', secret_out2) |
| 147 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 148 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 149 | class NestedAttributesTest(functional_base.FunctionalTestsBase): |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 150 | """Prove that we can use the template resource references.""" |
| 151 | |
| 152 | main_templ = ''' |
| 153 | heat_template_version: 2014-10-16 |
| 154 | resources: |
| 155 | secret2: |
| 156 | type: My::NestedSecret |
| 157 | outputs: |
| 158 | old_way: |
| 159 | value: { get_attr: [secret2, nested_str]} |
| 160 | test_attr1: |
| 161 | value: { get_attr: [secret2, resource.secret1, value]} |
| 162 | test_attr2: |
| 163 | value: { get_attr: [secret2, resource.secret1.value]} |
| 164 | test_ref: |
| 165 | value: { get_resource: secret2 } |
| 166 | ''' |
| 167 | |
| 168 | env_templ = ''' |
| 169 | resource_registry: |
| 170 | "My::NestedSecret": nested.yaml |
| 171 | ''' |
| 172 | |
| 173 | def setUp(self): |
| 174 | super(NestedAttributesTest, self).setUp() |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 175 | |
| 176 | def test_stack_ref(self): |
| 177 | nested_templ = ''' |
| 178 | heat_template_version: 2014-10-16 |
| 179 | resources: |
| 180 | secret1: |
| 181 | type: OS::Heat::RandomString |
Angus Salkeld | a89a028 | 2015-07-24 15:47:38 +1000 | [diff] [blame] | 182 | outputs: |
| 183 | nested_str: |
| 184 | value: {get_attr: [secret1, value]} |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 185 | ''' |
| 186 | stack_identifier = self.stack_create( |
| 187 | template=self.main_templ, |
| 188 | files={'nested.yaml': nested_templ}, |
| 189 | environment=self.env_templ) |
| 190 | self.assert_resource_is_a_stack(stack_identifier, 'secret2') |
| 191 | stack = self.client.stacks.get(stack_identifier) |
| 192 | test_ref = self._stack_output(stack, 'test_ref') |
| 193 | self.assertIn('arn:openstack:heat:', test_ref) |
| 194 | |
| 195 | def test_transparent_ref(self): |
| 196 | """With the addition of OS::stack_id we can now use the nested resource |
| 197 | more transparently. |
| 198 | """ |
| 199 | nested_templ = ''' |
| 200 | heat_template_version: 2014-10-16 |
| 201 | resources: |
| 202 | secret1: |
| 203 | type: OS::Heat::RandomString |
| 204 | outputs: |
| 205 | OS::stack_id: |
| 206 | value: {get_resource: secret1} |
| 207 | nested_str: |
| 208 | value: {get_attr: [secret1, value]} |
| 209 | ''' |
| 210 | stack_identifier = self.stack_create( |
| 211 | template=self.main_templ, |
| 212 | files={'nested.yaml': nested_templ}, |
| 213 | environment=self.env_templ) |
| 214 | self.assert_resource_is_a_stack(stack_identifier, 'secret2') |
| 215 | stack = self.client.stacks.get(stack_identifier) |
| 216 | test_ref = self._stack_output(stack, 'test_ref') |
| 217 | test_attr = self._stack_output(stack, 'old_way') |
| 218 | |
| 219 | self.assertNotIn('arn:openstack:heat', test_ref) |
| 220 | self.assertEqual(test_attr, test_ref) |
| 221 | |
| 222 | def test_nested_attributes(self): |
| 223 | nested_templ = ''' |
| 224 | heat_template_version: 2014-10-16 |
| 225 | resources: |
| 226 | secret1: |
| 227 | type: OS::Heat::RandomString |
| 228 | outputs: |
| 229 | nested_str: |
| 230 | value: {get_attr: [secret1, value]} |
| 231 | ''' |
| 232 | stack_identifier = self.stack_create( |
| 233 | template=self.main_templ, |
| 234 | files={'nested.yaml': nested_templ}, |
| 235 | environment=self.env_templ) |
| 236 | self.assert_resource_is_a_stack(stack_identifier, 'secret2') |
| 237 | stack = self.client.stacks.get(stack_identifier) |
| 238 | old_way = self._stack_output(stack, 'old_way') |
| 239 | test_attr1 = self._stack_output(stack, 'test_attr1') |
| 240 | test_attr2 = self._stack_output(stack, 'test_attr2') |
| 241 | |
| 242 | self.assertEqual(old_way, test_attr1) |
| 243 | self.assertEqual(old_way, test_attr2) |
| 244 | |
| 245 | |
Angus Salkeld | dd5a607 | 2015-09-02 09:10:04 +1000 | [diff] [blame^] | 246 | class TemplateResourceFacadeTest(functional_base.FunctionalTestsBase): |
| 247 | """Prove that we can use ResourceFacade in a HOT template.""" |
| 248 | |
| 249 | main_template = ''' |
| 250 | heat_template_version: 2013-05-23 |
| 251 | resources: |
| 252 | the_nested: |
| 253 | type: the.yaml |
| 254 | metadata: |
| 255 | foo: bar |
| 256 | outputs: |
| 257 | value: |
| 258 | value: {get_attr: [the_nested, output]} |
| 259 | ''' |
| 260 | |
| 261 | nested_templ = ''' |
| 262 | heat_template_version: 2013-05-23 |
| 263 | resources: |
| 264 | test: |
| 265 | type: OS::Heat::TestResource |
| 266 | properties: |
| 267 | value: {"Fn::Select": [foo, {resource_facade: metadata}]} |
| 268 | outputs: |
| 269 | output: |
| 270 | value: {get_attr: [test, output]} |
| 271 | ''' |
| 272 | |
| 273 | def test_metadata(self): |
| 274 | stack_identifier = self.stack_create( |
| 275 | template=self.main_template, |
| 276 | files={'the.yaml': self.nested_templ}) |
| 277 | stack = self.client.stacks.get(stack_identifier) |
| 278 | value = self._stack_output(stack, 'value') |
| 279 | self.assertEqual('bar', value) |
| 280 | |
| 281 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 282 | class TemplateResourceUpdateTest(functional_base.FunctionalTestsBase): |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 283 | """Prove that we can do template resource updates.""" |
| 284 | |
| 285 | main_template = ''' |
| 286 | HeatTemplateFormatVersion: '2012-12-12' |
| 287 | Resources: |
| 288 | the_nested: |
| 289 | Type: the.yaml |
| 290 | Properties: |
| 291 | one: my_name |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 292 | two: your_name |
| 293 | Outputs: |
| 294 | identifier: |
| 295 | Value: {Ref: the_nested} |
| 296 | value: |
| 297 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 298 | ''' |
| 299 | |
| 300 | main_template_change_prop = ''' |
| 301 | HeatTemplateFormatVersion: '2012-12-12' |
| 302 | Resources: |
| 303 | the_nested: |
| 304 | Type: the.yaml |
| 305 | Properties: |
| 306 | one: updated_name |
| 307 | two: your_name |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 308 | |
| 309 | Outputs: |
| 310 | identifier: |
| 311 | Value: {Ref: the_nested} |
| 312 | value: |
| 313 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 314 | ''' |
| 315 | |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 316 | main_template_add_prop = ''' |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 317 | HeatTemplateFormatVersion: '2012-12-12' |
| 318 | Resources: |
| 319 | the_nested: |
| 320 | Type: the.yaml |
| 321 | Properties: |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 322 | one: my_name |
| 323 | two: your_name |
| 324 | three: third_name |
| 325 | |
| 326 | Outputs: |
| 327 | identifier: |
| 328 | Value: {Ref: the_nested} |
| 329 | value: |
| 330 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 331 | ''' |
| 332 | |
| 333 | main_template_remove_prop = ''' |
| 334 | HeatTemplateFormatVersion: '2012-12-12' |
| 335 | Resources: |
| 336 | the_nested: |
| 337 | Type: the.yaml |
| 338 | Properties: |
| 339 | one: my_name |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 340 | |
| 341 | Outputs: |
| 342 | identifier: |
| 343 | Value: {Ref: the_nested} |
| 344 | value: |
| 345 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 346 | ''' |
| 347 | |
| 348 | initial_tmpl = ''' |
| 349 | HeatTemplateFormatVersion: '2012-12-12' |
| 350 | Parameters: |
| 351 | one: |
| 352 | Default: foo |
| 353 | Type: String |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 354 | two: |
| 355 | Default: bar |
| 356 | Type: String |
| 357 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 358 | Resources: |
| 359 | NestedResource: |
| 360 | Type: OS::Heat::RandomString |
| 361 | Properties: |
| 362 | salt: {Ref: one} |
| 363 | Outputs: |
| 364 | the_str: |
| 365 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 366 | ''' |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 367 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 368 | prop_change_tmpl = ''' |
| 369 | HeatTemplateFormatVersion: '2012-12-12' |
| 370 | Parameters: |
| 371 | one: |
| 372 | Default: yikes |
| 373 | Type: String |
| 374 | two: |
| 375 | Default: foo |
| 376 | Type: String |
| 377 | Resources: |
| 378 | NestedResource: |
| 379 | Type: OS::Heat::RandomString |
| 380 | Properties: |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 381 | salt: {Ref: two} |
| 382 | Outputs: |
| 383 | the_str: |
| 384 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 385 | ''' |
| 386 | |
| 387 | prop_add_tmpl = ''' |
| 388 | HeatTemplateFormatVersion: '2012-12-12' |
| 389 | Parameters: |
| 390 | one: |
| 391 | Default: yikes |
| 392 | Type: String |
| 393 | two: |
| 394 | Default: foo |
| 395 | Type: String |
| 396 | three: |
| 397 | Default: bar |
| 398 | Type: String |
| 399 | |
| 400 | Resources: |
| 401 | NestedResource: |
| 402 | Type: OS::Heat::RandomString |
| 403 | Properties: |
| 404 | salt: {Ref: three} |
| 405 | Outputs: |
| 406 | the_str: |
| 407 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 408 | ''' |
| 409 | |
| 410 | prop_remove_tmpl = ''' |
| 411 | HeatTemplateFormatVersion: '2012-12-12' |
| 412 | Parameters: |
| 413 | one: |
| 414 | Default: yikes |
| 415 | Type: String |
| 416 | |
| 417 | Resources: |
| 418 | NestedResource: |
| 419 | Type: OS::Heat::RandomString |
| 420 | Properties: |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 421 | salt: {Ref: one} |
| 422 | Outputs: |
| 423 | the_str: |
| 424 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 425 | ''' |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 426 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 427 | attr_change_tmpl = ''' |
| 428 | HeatTemplateFormatVersion: '2012-12-12' |
| 429 | Parameters: |
| 430 | one: |
| 431 | Default: foo |
| 432 | Type: String |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 433 | two: |
| 434 | Default: bar |
| 435 | Type: String |
| 436 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 437 | Resources: |
| 438 | NestedResource: |
| 439 | Type: OS::Heat::RandomString |
| 440 | Properties: |
| 441 | salt: {Ref: one} |
| 442 | Outputs: |
| 443 | the_str: |
| 444 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 445 | something_else: |
| 446 | Value: just_a_string |
| 447 | ''' |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 448 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 449 | content_change_tmpl = ''' |
| 450 | HeatTemplateFormatVersion: '2012-12-12' |
| 451 | Parameters: |
| 452 | one: |
| 453 | Default: foo |
| 454 | Type: String |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 455 | two: |
| 456 | Default: bar |
| 457 | Type: String |
| 458 | |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 459 | Resources: |
| 460 | NestedResource: |
| 461 | Type: OS::Heat::RandomString |
| 462 | Properties: |
| 463 | salt: yum |
| 464 | Outputs: |
| 465 | the_str: |
| 466 | Value: {'Fn::GetAtt': [NestedResource, value]} |
| 467 | ''' |
| 468 | |
| 469 | EXPECTED = (UPDATE, NOCHANGE) = ('update', 'nochange') |
| 470 | scenarios = [ |
| 471 | ('no_changes', dict(template=main_template, |
| 472 | provider=initial_tmpl, |
| 473 | expect=NOCHANGE)), |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 474 | ('main_tmpl_change', dict(template=main_template_change_prop, |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 475 | provider=initial_tmpl, |
| 476 | expect=UPDATE)), |
| 477 | ('provider_change', dict(template=main_template, |
| 478 | provider=content_change_tmpl, |
| 479 | expect=UPDATE)), |
| 480 | ('provider_props_change', dict(template=main_template, |
| 481 | provider=prop_change_tmpl, |
Rabi Mishra | b1293ae | 2015-05-13 16:39:04 +0530 | [diff] [blame] | 482 | expect=UPDATE)), |
| 483 | ('provider_props_add', dict(template=main_template_add_prop, |
| 484 | provider=prop_add_tmpl, |
| 485 | expect=UPDATE)), |
| 486 | ('provider_props_remove', dict(template=main_template_remove_prop, |
| 487 | provider=prop_remove_tmpl, |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 488 | expect=NOCHANGE)), |
| 489 | ('provider_attr_change', dict(template=main_template, |
| 490 | provider=attr_change_tmpl, |
| 491 | expect=NOCHANGE)), |
| 492 | ] |
| 493 | |
| 494 | def setUp(self): |
| 495 | super(TemplateResourceUpdateTest, self).setUp() |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 496 | |
| 497 | def test_template_resource_update_template_schema(self): |
| 498 | stack_identifier = self.stack_create( |
| 499 | template=self.main_template, |
| 500 | files={'the.yaml': self.initial_tmpl}) |
| 501 | stack = self.client.stacks.get(stack_identifier) |
| 502 | initial_id = self._stack_output(stack, 'identifier') |
| 503 | initial_val = self._stack_output(stack, 'value') |
| 504 | |
| 505 | self.update_stack(stack_identifier, |
| 506 | self.template, |
| 507 | files={'the.yaml': self.provider}) |
| 508 | stack = self.client.stacks.get(stack_identifier) |
| 509 | self.assertEqual(initial_id, |
| 510 | self._stack_output(stack, 'identifier')) |
| 511 | if self.expect == self.NOCHANGE: |
| 512 | self.assertEqual(initial_val, |
| 513 | self._stack_output(stack, 'value')) |
| 514 | else: |
| 515 | self.assertNotEqual(initial_val, |
| 516 | self._stack_output(stack, 'value')) |
| 517 | |
| 518 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 519 | class TemplateResourceUpdateFailedTest(functional_base.FunctionalTestsBase): |
Angus Salkeld | 5a3e1dd | 2015-02-03 15:31:47 +1000 | [diff] [blame] | 520 | """Prove that we can do updates on a nested stack to fix a stack.""" |
| 521 | main_template = ''' |
| 522 | HeatTemplateFormatVersion: '2012-12-12' |
| 523 | Resources: |
| 524 | keypair: |
| 525 | Type: OS::Nova::KeyPair |
| 526 | Properties: |
| 527 | name: replace-this |
| 528 | save_private_key: false |
| 529 | server: |
| 530 | Type: server_fail.yaml |
| 531 | DependsOn: keypair |
| 532 | ''' |
| 533 | nested_templ = ''' |
| 534 | HeatTemplateFormatVersion: '2012-12-12' |
| 535 | Resources: |
| 536 | RealRandom: |
| 537 | Type: OS::Heat::RandomString |
| 538 | ''' |
| 539 | |
| 540 | def setUp(self): |
| 541 | super(TemplateResourceUpdateFailedTest, self).setUp() |
Sergey Kraynev | a265c13 | 2015-02-13 03:51:03 -0500 | [diff] [blame] | 542 | self.assign_keypair() |
Angus Salkeld | 5a3e1dd | 2015-02-03 15:31:47 +1000 | [diff] [blame] | 543 | |
| 544 | def test_update_on_failed_create(self): |
Vikas Jain | ac6b02f | 2015-02-11 11:31:46 -0800 | [diff] [blame] | 545 | # create a stack with "server" dependent on "keypair", but |
Angus Salkeld | 5a3e1dd | 2015-02-03 15:31:47 +1000 | [diff] [blame] | 546 | # keypair fails, so "server" is not created properly. |
| 547 | # We then fix the template and it should succeed. |
| 548 | broken_templ = self.main_template.replace('replace-this', |
| 549 | self.keypair_name) |
| 550 | stack_identifier = self.stack_create( |
| 551 | template=broken_templ, |
| 552 | files={'server_fail.yaml': self.nested_templ}, |
| 553 | expected_status='CREATE_FAILED') |
| 554 | |
| 555 | fixed_templ = self.main_template.replace('replace-this', |
| 556 | test.rand_name()) |
| 557 | self.update_stack(stack_identifier, |
| 558 | fixed_templ, |
| 559 | files={'server_fail.yaml': self.nested_templ}) |
| 560 | |
| 561 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 562 | class TemplateResourceAdoptTest(functional_base.FunctionalTestsBase): |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 563 | """Prove that we can do template resource adopt/abandon.""" |
| 564 | |
| 565 | main_template = ''' |
| 566 | HeatTemplateFormatVersion: '2012-12-12' |
| 567 | Resources: |
| 568 | the_nested: |
| 569 | Type: the.yaml |
| 570 | Properties: |
| 571 | one: my_name |
| 572 | Outputs: |
| 573 | identifier: |
| 574 | Value: {Ref: the_nested} |
| 575 | value: |
| 576 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 577 | ''' |
| 578 | |
| 579 | nested_templ = ''' |
| 580 | HeatTemplateFormatVersion: '2012-12-12' |
| 581 | Parameters: |
| 582 | one: |
| 583 | Default: foo |
| 584 | Type: String |
| 585 | Resources: |
| 586 | RealRandom: |
| 587 | Type: OS::Heat::RandomString |
| 588 | Properties: |
| 589 | salt: {Ref: one} |
| 590 | Outputs: |
| 591 | the_str: |
| 592 | Value: {'Fn::GetAtt': [RealRandom, value]} |
| 593 | ''' |
| 594 | |
| 595 | def setUp(self): |
| 596 | super(TemplateResourceAdoptTest, self).setUp() |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 597 | |
| 598 | def _yaml_to_json(self, yaml_templ): |
| 599 | return yaml.load(yaml_templ) |
| 600 | |
| 601 | def test_abandon(self): |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 602 | stack_identifier = self.stack_create( |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 603 | template=self.main_template, |
| 604 | files={'the.yaml': self.nested_templ}, |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 605 | enable_cleanup=False |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 606 | ) |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 607 | |
Sirushti Murugesan | 04ee802 | 2015-02-02 23:00:23 +0530 | [diff] [blame] | 608 | info = self.stack_abandon(stack_id=stack_identifier) |
Angus Salkeld | 2bd63a4 | 2015-01-07 11:11:29 +1000 | [diff] [blame] | 609 | self.assertEqual(self._yaml_to_json(self.main_template), |
| 610 | info['template']) |
| 611 | self.assertEqual(self._yaml_to_json(self.nested_templ), |
| 612 | info['resources']['the_nested']['template']) |
| 613 | |
| 614 | def test_adopt(self): |
| 615 | data = { |
| 616 | 'resources': { |
| 617 | 'the_nested': { |
| 618 | "type": "the.yaml", |
| 619 | "resources": { |
| 620 | "RealRandom": { |
| 621 | "type": "OS::Heat::RandomString", |
| 622 | 'resource_data': {'value': 'goopie'}, |
| 623 | 'resource_id': 'froggy' |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | }, |
| 628 | "environment": {"parameters": {}}, |
| 629 | "template": yaml.load(self.main_template) |
| 630 | } |
| 631 | |
| 632 | stack_identifier = self.stack_adopt( |
| 633 | adopt_data=json.dumps(data), |
| 634 | files={'the.yaml': self.nested_templ}) |
| 635 | |
| 636 | self.assert_resource_is_a_stack(stack_identifier, 'the_nested') |
| 637 | stack = self.client.stacks.get(stack_identifier) |
| 638 | self.assertEqual('goopie', self._stack_output(stack, 'value')) |
Angus Salkeld | 8760172 | 2015-01-05 14:57:27 +1000 | [diff] [blame] | 639 | |
| 640 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 641 | class TemplateResourceCheckTest(functional_base.FunctionalTestsBase): |
Angus Salkeld | 8760172 | 2015-01-05 14:57:27 +1000 | [diff] [blame] | 642 | """Prove that we can do template resource check.""" |
| 643 | |
| 644 | main_template = ''' |
| 645 | HeatTemplateFormatVersion: '2012-12-12' |
| 646 | Resources: |
| 647 | the_nested: |
| 648 | Type: the.yaml |
| 649 | Properties: |
| 650 | one: my_name |
| 651 | Outputs: |
| 652 | identifier: |
| 653 | Value: {Ref: the_nested} |
| 654 | value: |
| 655 | Value: {'Fn::GetAtt': [the_nested, the_str]} |
| 656 | ''' |
| 657 | |
| 658 | nested_templ = ''' |
| 659 | HeatTemplateFormatVersion: '2012-12-12' |
| 660 | Parameters: |
| 661 | one: |
| 662 | Default: foo |
| 663 | Type: String |
| 664 | Resources: |
| 665 | RealRandom: |
| 666 | Type: OS::Heat::RandomString |
| 667 | Properties: |
| 668 | salt: {Ref: one} |
| 669 | Outputs: |
| 670 | the_str: |
| 671 | Value: {'Fn::GetAtt': [RealRandom, value]} |
| 672 | ''' |
| 673 | |
| 674 | def setUp(self): |
| 675 | super(TemplateResourceCheckTest, self).setUp() |
Angus Salkeld | 8760172 | 2015-01-05 14:57:27 +1000 | [diff] [blame] | 676 | |
| 677 | def test_check(self): |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 678 | stack_identifier = self.stack_create( |
Angus Salkeld | 8760172 | 2015-01-05 14:57:27 +1000 | [diff] [blame] | 679 | template=self.main_template, |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 680 | files={'the.yaml': self.nested_templ} |
Angus Salkeld | 8760172 | 2015-01-05 14:57:27 +1000 | [diff] [blame] | 681 | ) |
Angus Salkeld | 8760172 | 2015-01-05 14:57:27 +1000 | [diff] [blame] | 682 | |
| 683 | self.client.actions.check(stack_id=stack_identifier) |
| 684 | self._wait_for_stack_status(stack_identifier, 'CHECK_COMPLETE') |
Angus Salkeld | 793b0fc | 2015-06-24 08:52:08 +1000 | [diff] [blame] | 685 | |
| 686 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 687 | class TemplateResourceErrorMessageTest(functional_base.FunctionalTestsBase): |
Angus Salkeld | 793b0fc | 2015-06-24 08:52:08 +1000 | [diff] [blame] | 688 | """Prove that nested stack errors don't suck.""" |
| 689 | template = ''' |
| 690 | HeatTemplateFormatVersion: '2012-12-12' |
| 691 | Resources: |
| 692 | victim: |
| 693 | Type: fail.yaml |
| 694 | ''' |
| 695 | nested_templ = ''' |
| 696 | HeatTemplateFormatVersion: '2012-12-12' |
| 697 | Resources: |
| 698 | oops: |
| 699 | Type: OS::Heat::TestResource |
| 700 | Properties: |
| 701 | fail: true |
| 702 | wait_secs: 2 |
| 703 | ''' |
| 704 | |
| 705 | def setUp(self): |
| 706 | super(TemplateResourceErrorMessageTest, self).setUp() |
Angus Salkeld | 793b0fc | 2015-06-24 08:52:08 +1000 | [diff] [blame] | 707 | |
| 708 | def test_fail(self): |
| 709 | stack_identifier = self.stack_create( |
| 710 | template=self.template, |
| 711 | files={'fail.yaml': self.nested_templ}, |
| 712 | expected_status='CREATE_FAILED') |
| 713 | stack = self.client.stacks.get(stack_identifier) |
| 714 | |
| 715 | exp_path = 'resources.victim.resources.oops' |
| 716 | exp_msg = 'Test Resource failed oops' |
| 717 | exp = 'Resource CREATE failed: ValueError: %s: %s' % (exp_path, |
| 718 | exp_msg) |
| 719 | self.assertEqual(exp, stack.stack_status_reason) |
kairat_kushaev | 61a99e1 | 2015-07-31 16:22:45 +0300 | [diff] [blame] | 720 | |
| 721 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 722 | class TemplateResourceSuspendResumeTest(functional_base.FunctionalTestsBase): |
kairat_kushaev | 61a99e1 | 2015-07-31 16:22:45 +0300 | [diff] [blame] | 723 | """Prove that we can do template resource suspend/resume.""" |
| 724 | |
| 725 | main_template = ''' |
| 726 | heat_template_version: 2014-10-16 |
| 727 | parameters: |
| 728 | resources: |
| 729 | the_nested: |
| 730 | type: the.yaml |
| 731 | ''' |
| 732 | |
| 733 | nested_templ = ''' |
| 734 | heat_template_version: 2014-10-16 |
| 735 | resources: |
| 736 | test_random_string: |
| 737 | type: OS::Heat::RandomString |
| 738 | ''' |
| 739 | |
| 740 | def setUp(self): |
| 741 | super(TemplateResourceSuspendResumeTest, self).setUp() |
kairat_kushaev | 61a99e1 | 2015-07-31 16:22:45 +0300 | [diff] [blame] | 742 | |
| 743 | def test_suspend_resume(self): |
| 744 | """Basic test for template resource suspend resume""" |
| 745 | stack_identifier = self.stack_create( |
| 746 | template=self.main_template, |
| 747 | files={'the.yaml': self.nested_templ} |
| 748 | ) |
| 749 | |
| 750 | self.stack_suspend(stack_identifier=stack_identifier) |
| 751 | self.stack_resume(stack_identifier=stack_identifier) |