blob: a967888352ef3ef3b3b4bb5c179400ab66363632 [file] [log] [blame]
Angus Salkeld2bd63a42015-01-07 11:11:29 +10001# 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
13import json
Pavlo Shchelokovskyy60e0ecd2014-12-14 22:17:21 +020014
Angus Salkeld2bd63a42015-01-07 11:11:29 +100015import yaml
16
17from heat_integrationtests.common import test
Rabi Mishra477efc92015-07-31 13:01:45 +053018from heat_integrationtests.functional import functional_base
Angus Salkeld2bd63a42015-01-07 11:11:29 +100019
20
Rabi Mishra477efc92015-07-31 13:01:45 +053021class TemplateResourceTest(functional_base.FunctionalTestsBase):
Angus Salkeld2bd63a42015-01-07 11:11:29 +100022 """Prove that we can use the registry in a nested provider."""
Angus Salkeld95403d82015-02-12 14:06:01 +100023
24 template = '''
25heat_template_version: 2013-05-23
26resources:
27 secret1:
28 type: OS::Heat::RandomString
29outputs:
30 secret-out:
31 value: { get_attr: [secret1, value] }
32'''
33 nested_templ = '''
34heat_template_version: 2013-05-23
35resources:
36 secret2:
37 type: OS::Heat::RandomString
38outputs:
39 value:
40 value: { get_attr: [secret2, value] }
41'''
42
43 env_templ = '''
44resource_registry:
45 "OS::Heat::RandomString": nested.yaml
46'''
47
Angus Salkeld2bd63a42015-01-07 11:11:29 +100048 def setUp(self):
49 super(TemplateResourceTest, self).setUp()
Angus Salkeld2bd63a42015-01-07 11:11:29 +100050
51 def test_nested_env(self):
52 main_templ = '''
53heat_template_version: 2013-05-23
54resources:
55 secret1:
56 type: My::NestedSecret
57outputs:
58 secret-out:
59 value: { get_attr: [secret1, value] }
60'''
61
62 nested_templ = '''
63heat_template_version: 2013-05-23
64resources:
65 secret2:
66 type: My::Secret
67outputs:
68 value:
69 value: { get_attr: [secret2, value] }
70'''
71
72 env_templ = '''
73resource_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 Salkeld2e61f9f2015-04-07 09:25:50 +100082 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 Salkeld2bd63a42015-01-07 11:11:29 +100087
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 Salkeld2bd63a42015-01-07 11:11:29 +100093 stack_identifier = self.stack_create(
Angus Salkeld95403d82015-02-12 14:06:01 +100094 template=self.template,
95 files={'nested.yaml': self.nested_templ},
96 environment=self.env_templ)
Angus Salkeld2bd63a42015-01-07 11:11:29 +100097 self.assert_resource_is_a_stack(stack_identifier, 'secret1')
98
Angus Salkeld95403d82015-02-12 14:06:01 +100099 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 Kraynevbf67ce32015-04-17 10:54:20 -0400105 # disable cleanup so we can call _stack_delete() directly.
106 stack_identifier = self.stack_create(
Angus Salkeld95403d82015-02-12 14:06:01 +1000107 template=self.template,
108 files={'nested.yaml': self.nested_templ},
109 environment=self.env_templ,
Sergey Kraynevbf67ce32015-04-17 10:54:20 -0400110 enable_cleanup=False)
Angus Salkeld95403d82015-02-12 14:06:01 +1000111
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 Salkeld19b9e1d2015-05-08 11:02:38 +1000118 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 = '''
127heat_template_version: 2013-05-23
128resources:
129 secret2:
130 type: OS::Heat::RandomString
131outputs:
132 value:
133 value: freddy
134'''
135 env_templ_2 = '''
136resource_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 Salkeld2bd63a42015-01-07 11:11:29 +1000148
Rabi Mishra477efc92015-07-31 13:01:45 +0530149class NestedAttributesTest(functional_base.FunctionalTestsBase):
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000150 """Prove that we can use the template resource references."""
151
152 main_templ = '''
153heat_template_version: 2014-10-16
154resources:
155 secret2:
156 type: My::NestedSecret
157outputs:
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 = '''
169resource_registry:
170 "My::NestedSecret": nested.yaml
171'''
172
173 def setUp(self):
174 super(NestedAttributesTest, self).setUp()
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000175
176 def test_stack_ref(self):
177 nested_templ = '''
178heat_template_version: 2014-10-16
179resources:
180 secret1:
181 type: OS::Heat::RandomString
Angus Salkelda89a0282015-07-24 15:47:38 +1000182outputs:
183 nested_str:
184 value: {get_attr: [secret1, value]}
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000185'''
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 = '''
200heat_template_version: 2014-10-16
201resources:
202 secret1:
203 type: OS::Heat::RandomString
204outputs:
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 = '''
224heat_template_version: 2014-10-16
225resources:
226 secret1:
227 type: OS::Heat::RandomString
228outputs:
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
Rabi Mishra477efc92015-07-31 13:01:45 +0530246class TemplateResourceUpdateTest(functional_base.FunctionalTestsBase):
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000247 """Prove that we can do template resource updates."""
248
249 main_template = '''
250HeatTemplateFormatVersion: '2012-12-12'
251Resources:
252 the_nested:
253 Type: the.yaml
254 Properties:
255 one: my_name
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530256 two: your_name
257Outputs:
258 identifier:
259 Value: {Ref: the_nested}
260 value:
261 Value: {'Fn::GetAtt': [the_nested, the_str]}
262'''
263
264 main_template_change_prop = '''
265HeatTemplateFormatVersion: '2012-12-12'
266Resources:
267 the_nested:
268 Type: the.yaml
269 Properties:
270 one: updated_name
271 two: your_name
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000272
273Outputs:
274 identifier:
275 Value: {Ref: the_nested}
276 value:
277 Value: {'Fn::GetAtt': [the_nested, the_str]}
278'''
279
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530280 main_template_add_prop = '''
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000281HeatTemplateFormatVersion: '2012-12-12'
282Resources:
283 the_nested:
284 Type: the.yaml
285 Properties:
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530286 one: my_name
287 two: your_name
288 three: third_name
289
290Outputs:
291 identifier:
292 Value: {Ref: the_nested}
293 value:
294 Value: {'Fn::GetAtt': [the_nested, the_str]}
295'''
296
297 main_template_remove_prop = '''
298HeatTemplateFormatVersion: '2012-12-12'
299Resources:
300 the_nested:
301 Type: the.yaml
302 Properties:
303 one: my_name
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000304
305Outputs:
306 identifier:
307 Value: {Ref: the_nested}
308 value:
309 Value: {'Fn::GetAtt': [the_nested, the_str]}
310'''
311
312 initial_tmpl = '''
313HeatTemplateFormatVersion: '2012-12-12'
314Parameters:
315 one:
316 Default: foo
317 Type: String
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530318 two:
319 Default: bar
320 Type: String
321
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000322Resources:
323 NestedResource:
324 Type: OS::Heat::RandomString
325 Properties:
326 salt: {Ref: one}
327Outputs:
328 the_str:
329 Value: {'Fn::GetAtt': [NestedResource, value]}
330'''
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530331
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000332 prop_change_tmpl = '''
333HeatTemplateFormatVersion: '2012-12-12'
334Parameters:
335 one:
336 Default: yikes
337 Type: String
338 two:
339 Default: foo
340 Type: String
341Resources:
342 NestedResource:
343 Type: OS::Heat::RandomString
344 Properties:
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530345 salt: {Ref: two}
346Outputs:
347 the_str:
348 Value: {'Fn::GetAtt': [NestedResource, value]}
349'''
350
351 prop_add_tmpl = '''
352HeatTemplateFormatVersion: '2012-12-12'
353Parameters:
354 one:
355 Default: yikes
356 Type: String
357 two:
358 Default: foo
359 Type: String
360 three:
361 Default: bar
362 Type: String
363
364Resources:
365 NestedResource:
366 Type: OS::Heat::RandomString
367 Properties:
368 salt: {Ref: three}
369Outputs:
370 the_str:
371 Value: {'Fn::GetAtt': [NestedResource, value]}
372'''
373
374 prop_remove_tmpl = '''
375HeatTemplateFormatVersion: '2012-12-12'
376Parameters:
377 one:
378 Default: yikes
379 Type: String
380
381Resources:
382 NestedResource:
383 Type: OS::Heat::RandomString
384 Properties:
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000385 salt: {Ref: one}
386Outputs:
387 the_str:
388 Value: {'Fn::GetAtt': [NestedResource, value]}
389'''
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530390
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000391 attr_change_tmpl = '''
392HeatTemplateFormatVersion: '2012-12-12'
393Parameters:
394 one:
395 Default: foo
396 Type: String
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530397 two:
398 Default: bar
399 Type: String
400
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000401Resources:
402 NestedResource:
403 Type: OS::Heat::RandomString
404 Properties:
405 salt: {Ref: one}
406Outputs:
407 the_str:
408 Value: {'Fn::GetAtt': [NestedResource, value]}
409 something_else:
410 Value: just_a_string
411'''
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530412
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000413 content_change_tmpl = '''
414HeatTemplateFormatVersion: '2012-12-12'
415Parameters:
416 one:
417 Default: foo
418 Type: String
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530419 two:
420 Default: bar
421 Type: String
422
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000423Resources:
424 NestedResource:
425 Type: OS::Heat::RandomString
426 Properties:
427 salt: yum
428Outputs:
429 the_str:
430 Value: {'Fn::GetAtt': [NestedResource, value]}
431'''
432
433 EXPECTED = (UPDATE, NOCHANGE) = ('update', 'nochange')
434 scenarios = [
435 ('no_changes', dict(template=main_template,
436 provider=initial_tmpl,
437 expect=NOCHANGE)),
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530438 ('main_tmpl_change', dict(template=main_template_change_prop,
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000439 provider=initial_tmpl,
440 expect=UPDATE)),
441 ('provider_change', dict(template=main_template,
442 provider=content_change_tmpl,
443 expect=UPDATE)),
444 ('provider_props_change', dict(template=main_template,
445 provider=prop_change_tmpl,
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530446 expect=UPDATE)),
447 ('provider_props_add', dict(template=main_template_add_prop,
448 provider=prop_add_tmpl,
449 expect=UPDATE)),
450 ('provider_props_remove', dict(template=main_template_remove_prop,
451 provider=prop_remove_tmpl,
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000452 expect=NOCHANGE)),
453 ('provider_attr_change', dict(template=main_template,
454 provider=attr_change_tmpl,
455 expect=NOCHANGE)),
456 ]
457
458 def setUp(self):
459 super(TemplateResourceUpdateTest, self).setUp()
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000460
461 def test_template_resource_update_template_schema(self):
462 stack_identifier = self.stack_create(
463 template=self.main_template,
464 files={'the.yaml': self.initial_tmpl})
465 stack = self.client.stacks.get(stack_identifier)
466 initial_id = self._stack_output(stack, 'identifier')
467 initial_val = self._stack_output(stack, 'value')
468
469 self.update_stack(stack_identifier,
470 self.template,
471 files={'the.yaml': self.provider})
472 stack = self.client.stacks.get(stack_identifier)
473 self.assertEqual(initial_id,
474 self._stack_output(stack, 'identifier'))
475 if self.expect == self.NOCHANGE:
476 self.assertEqual(initial_val,
477 self._stack_output(stack, 'value'))
478 else:
479 self.assertNotEqual(initial_val,
480 self._stack_output(stack, 'value'))
481
482
Rabi Mishra477efc92015-07-31 13:01:45 +0530483class TemplateResourceUpdateFailedTest(functional_base.FunctionalTestsBase):
Angus Salkeld5a3e1dd2015-02-03 15:31:47 +1000484 """Prove that we can do updates on a nested stack to fix a stack."""
485 main_template = '''
486HeatTemplateFormatVersion: '2012-12-12'
487Resources:
488 keypair:
489 Type: OS::Nova::KeyPair
490 Properties:
491 name: replace-this
492 save_private_key: false
493 server:
494 Type: server_fail.yaml
495 DependsOn: keypair
496'''
497 nested_templ = '''
498HeatTemplateFormatVersion: '2012-12-12'
499Resources:
500 RealRandom:
501 Type: OS::Heat::RandomString
502'''
503
504 def setUp(self):
505 super(TemplateResourceUpdateFailedTest, self).setUp()
Sergey Krayneva265c132015-02-13 03:51:03 -0500506 self.assign_keypair()
Angus Salkeld5a3e1dd2015-02-03 15:31:47 +1000507
508 def test_update_on_failed_create(self):
Vikas Jainac6b02f2015-02-11 11:31:46 -0800509 # create a stack with "server" dependent on "keypair", but
Angus Salkeld5a3e1dd2015-02-03 15:31:47 +1000510 # keypair fails, so "server" is not created properly.
511 # We then fix the template and it should succeed.
512 broken_templ = self.main_template.replace('replace-this',
513 self.keypair_name)
514 stack_identifier = self.stack_create(
515 template=broken_templ,
516 files={'server_fail.yaml': self.nested_templ},
517 expected_status='CREATE_FAILED')
518
519 fixed_templ = self.main_template.replace('replace-this',
520 test.rand_name())
521 self.update_stack(stack_identifier,
522 fixed_templ,
523 files={'server_fail.yaml': self.nested_templ})
524
525
Rabi Mishra477efc92015-07-31 13:01:45 +0530526class TemplateResourceAdoptTest(functional_base.FunctionalTestsBase):
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000527 """Prove that we can do template resource adopt/abandon."""
528
529 main_template = '''
530HeatTemplateFormatVersion: '2012-12-12'
531Resources:
532 the_nested:
533 Type: the.yaml
534 Properties:
535 one: my_name
536Outputs:
537 identifier:
538 Value: {Ref: the_nested}
539 value:
540 Value: {'Fn::GetAtt': [the_nested, the_str]}
541'''
542
543 nested_templ = '''
544HeatTemplateFormatVersion: '2012-12-12'
545Parameters:
546 one:
547 Default: foo
548 Type: String
549Resources:
550 RealRandom:
551 Type: OS::Heat::RandomString
552 Properties:
553 salt: {Ref: one}
554Outputs:
555 the_str:
556 Value: {'Fn::GetAtt': [RealRandom, value]}
557'''
558
559 def setUp(self):
560 super(TemplateResourceAdoptTest, self).setUp()
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000561
562 def _yaml_to_json(self, yaml_templ):
563 return yaml.load(yaml_templ)
564
565 def test_abandon(self):
Sergey Kraynevbf67ce32015-04-17 10:54:20 -0400566 stack_identifier = self.stack_create(
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000567 template=self.main_template,
568 files={'the.yaml': self.nested_templ},
Sergey Kraynevbf67ce32015-04-17 10:54:20 -0400569 enable_cleanup=False
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000570 )
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000571
Sirushti Murugesan04ee8022015-02-02 23:00:23 +0530572 info = self.stack_abandon(stack_id=stack_identifier)
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000573 self.assertEqual(self._yaml_to_json(self.main_template),
574 info['template'])
575 self.assertEqual(self._yaml_to_json(self.nested_templ),
576 info['resources']['the_nested']['template'])
577
578 def test_adopt(self):
579 data = {
580 'resources': {
581 'the_nested': {
582 "type": "the.yaml",
583 "resources": {
584 "RealRandom": {
585 "type": "OS::Heat::RandomString",
586 'resource_data': {'value': 'goopie'},
587 'resource_id': 'froggy'
588 }
589 }
590 }
591 },
592 "environment": {"parameters": {}},
593 "template": yaml.load(self.main_template)
594 }
595
596 stack_identifier = self.stack_adopt(
597 adopt_data=json.dumps(data),
598 files={'the.yaml': self.nested_templ})
599
600 self.assert_resource_is_a_stack(stack_identifier, 'the_nested')
601 stack = self.client.stacks.get(stack_identifier)
602 self.assertEqual('goopie', self._stack_output(stack, 'value'))
Angus Salkeld87601722015-01-05 14:57:27 +1000603
604
Rabi Mishra477efc92015-07-31 13:01:45 +0530605class TemplateResourceCheckTest(functional_base.FunctionalTestsBase):
Angus Salkeld87601722015-01-05 14:57:27 +1000606 """Prove that we can do template resource check."""
607
608 main_template = '''
609HeatTemplateFormatVersion: '2012-12-12'
610Resources:
611 the_nested:
612 Type: the.yaml
613 Properties:
614 one: my_name
615Outputs:
616 identifier:
617 Value: {Ref: the_nested}
618 value:
619 Value: {'Fn::GetAtt': [the_nested, the_str]}
620'''
621
622 nested_templ = '''
623HeatTemplateFormatVersion: '2012-12-12'
624Parameters:
625 one:
626 Default: foo
627 Type: String
628Resources:
629 RealRandom:
630 Type: OS::Heat::RandomString
631 Properties:
632 salt: {Ref: one}
633Outputs:
634 the_str:
635 Value: {'Fn::GetAtt': [RealRandom, value]}
636'''
637
638 def setUp(self):
639 super(TemplateResourceCheckTest, self).setUp()
Angus Salkeld87601722015-01-05 14:57:27 +1000640
641 def test_check(self):
Sergey Kraynevbf67ce32015-04-17 10:54:20 -0400642 stack_identifier = self.stack_create(
Angus Salkeld87601722015-01-05 14:57:27 +1000643 template=self.main_template,
Sergey Kraynevbf67ce32015-04-17 10:54:20 -0400644 files={'the.yaml': self.nested_templ}
Angus Salkeld87601722015-01-05 14:57:27 +1000645 )
Angus Salkeld87601722015-01-05 14:57:27 +1000646
647 self.client.actions.check(stack_id=stack_identifier)
648 self._wait_for_stack_status(stack_identifier, 'CHECK_COMPLETE')
Angus Salkeld793b0fc2015-06-24 08:52:08 +1000649
650
Rabi Mishra477efc92015-07-31 13:01:45 +0530651class TemplateResourceErrorMessageTest(functional_base.FunctionalTestsBase):
Angus Salkeld793b0fc2015-06-24 08:52:08 +1000652 """Prove that nested stack errors don't suck."""
653 template = '''
654HeatTemplateFormatVersion: '2012-12-12'
655Resources:
656 victim:
657 Type: fail.yaml
658'''
659 nested_templ = '''
660HeatTemplateFormatVersion: '2012-12-12'
661Resources:
662 oops:
663 Type: OS::Heat::TestResource
664 Properties:
665 fail: true
666 wait_secs: 2
667'''
668
669 def setUp(self):
670 super(TemplateResourceErrorMessageTest, self).setUp()
Angus Salkeld793b0fc2015-06-24 08:52:08 +1000671
672 def test_fail(self):
673 stack_identifier = self.stack_create(
674 template=self.template,
675 files={'fail.yaml': self.nested_templ},
676 expected_status='CREATE_FAILED')
677 stack = self.client.stacks.get(stack_identifier)
678
679 exp_path = 'resources.victim.resources.oops'
680 exp_msg = 'Test Resource failed oops'
681 exp = 'Resource CREATE failed: ValueError: %s: %s' % (exp_path,
682 exp_msg)
683 self.assertEqual(exp, stack.stack_status_reason)
kairat_kushaev61a99e12015-07-31 16:22:45 +0300684
685
Rabi Mishra477efc92015-07-31 13:01:45 +0530686class TemplateResourceSuspendResumeTest(functional_base.FunctionalTestsBase):
kairat_kushaev61a99e12015-07-31 16:22:45 +0300687 """Prove that we can do template resource suspend/resume."""
688
689 main_template = '''
690heat_template_version: 2014-10-16
691parameters:
692resources:
693 the_nested:
694 type: the.yaml
695'''
696
697 nested_templ = '''
698heat_template_version: 2014-10-16
699resources:
700 test_random_string:
701 type: OS::Heat::RandomString
702'''
703
704 def setUp(self):
705 super(TemplateResourceSuspendResumeTest, self).setUp()
kairat_kushaev61a99e12015-07-31 16:22:45 +0300706
707 def test_suspend_resume(self):
708 """Basic test for template resource suspend resume"""
709 stack_identifier = self.stack_create(
710 template=self.main_template,
711 files={'the.yaml': self.nested_templ}
712 )
713
714 self.stack_suspend(stack_identifier=stack_identifier)
715 self.stack_resume(stack_identifier=stack_identifier)