blob: 6ece7d126d6c278b48982199603d0bbab939b07f [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
Angus Salkelddd5a6072015-09-02 09:10:04 +1000246class TemplateResourceFacadeTest(functional_base.FunctionalTestsBase):
247 """Prove that we can use ResourceFacade in a HOT template."""
248
249 main_template = '''
250heat_template_version: 2013-05-23
251resources:
252 the_nested:
253 type: the.yaml
254 metadata:
255 foo: bar
256outputs:
257 value:
258 value: {get_attr: [the_nested, output]}
259'''
260
261 nested_templ = '''
262heat_template_version: 2013-05-23
263resources:
264 test:
265 type: OS::Heat::TestResource
266 properties:
267 value: {"Fn::Select": [foo, {resource_facade: metadata}]}
268outputs:
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 Mishra477efc92015-07-31 13:01:45 +0530282class TemplateResourceUpdateTest(functional_base.FunctionalTestsBase):
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000283 """Prove that we can do template resource updates."""
284
285 main_template = '''
286HeatTemplateFormatVersion: '2012-12-12'
287Resources:
288 the_nested:
289 Type: the.yaml
290 Properties:
291 one: my_name
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530292 two: your_name
293Outputs:
294 identifier:
295 Value: {Ref: the_nested}
296 value:
297 Value: {'Fn::GetAtt': [the_nested, the_str]}
298'''
299
300 main_template_change_prop = '''
301HeatTemplateFormatVersion: '2012-12-12'
302Resources:
303 the_nested:
304 Type: the.yaml
305 Properties:
306 one: updated_name
307 two: your_name
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000308
309Outputs:
310 identifier:
311 Value: {Ref: the_nested}
312 value:
313 Value: {'Fn::GetAtt': [the_nested, the_str]}
314'''
315
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530316 main_template_add_prop = '''
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000317HeatTemplateFormatVersion: '2012-12-12'
318Resources:
319 the_nested:
320 Type: the.yaml
321 Properties:
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530322 one: my_name
323 two: your_name
324 three: third_name
325
326Outputs:
327 identifier:
328 Value: {Ref: the_nested}
329 value:
330 Value: {'Fn::GetAtt': [the_nested, the_str]}
331'''
332
333 main_template_remove_prop = '''
334HeatTemplateFormatVersion: '2012-12-12'
335Resources:
336 the_nested:
337 Type: the.yaml
338 Properties:
339 one: my_name
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000340
341Outputs:
342 identifier:
343 Value: {Ref: the_nested}
344 value:
345 Value: {'Fn::GetAtt': [the_nested, the_str]}
346'''
347
348 initial_tmpl = '''
349HeatTemplateFormatVersion: '2012-12-12'
350Parameters:
351 one:
352 Default: foo
353 Type: String
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530354 two:
355 Default: bar
356 Type: String
357
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000358Resources:
359 NestedResource:
360 Type: OS::Heat::RandomString
361 Properties:
362 salt: {Ref: one}
363Outputs:
364 the_str:
365 Value: {'Fn::GetAtt': [NestedResource, value]}
366'''
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530367
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000368 prop_change_tmpl = '''
369HeatTemplateFormatVersion: '2012-12-12'
370Parameters:
371 one:
372 Default: yikes
373 Type: String
374 two:
375 Default: foo
376 Type: String
377Resources:
378 NestedResource:
379 Type: OS::Heat::RandomString
380 Properties:
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530381 salt: {Ref: two}
382Outputs:
383 the_str:
384 Value: {'Fn::GetAtt': [NestedResource, value]}
385'''
386
387 prop_add_tmpl = '''
388HeatTemplateFormatVersion: '2012-12-12'
389Parameters:
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
400Resources:
401 NestedResource:
402 Type: OS::Heat::RandomString
403 Properties:
404 salt: {Ref: three}
405Outputs:
406 the_str:
407 Value: {'Fn::GetAtt': [NestedResource, value]}
408'''
409
410 prop_remove_tmpl = '''
411HeatTemplateFormatVersion: '2012-12-12'
412Parameters:
413 one:
414 Default: yikes
415 Type: String
416
417Resources:
418 NestedResource:
419 Type: OS::Heat::RandomString
420 Properties:
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000421 salt: {Ref: one}
422Outputs:
423 the_str:
424 Value: {'Fn::GetAtt': [NestedResource, value]}
425'''
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530426
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000427 attr_change_tmpl = '''
428HeatTemplateFormatVersion: '2012-12-12'
429Parameters:
430 one:
431 Default: foo
432 Type: String
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530433 two:
434 Default: bar
435 Type: String
436
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000437Resources:
438 NestedResource:
439 Type: OS::Heat::RandomString
440 Properties:
441 salt: {Ref: one}
442Outputs:
443 the_str:
444 Value: {'Fn::GetAtt': [NestedResource, value]}
445 something_else:
446 Value: just_a_string
447'''
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530448
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000449 content_change_tmpl = '''
450HeatTemplateFormatVersion: '2012-12-12'
451Parameters:
452 one:
453 Default: foo
454 Type: String
Rabi Mishrab1293ae2015-05-13 16:39:04 +0530455 two:
456 Default: bar
457 Type: String
458
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000459Resources:
460 NestedResource:
461 Type: OS::Heat::RandomString
462 Properties:
463 salt: yum
464Outputs:
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 Mishrab1293ae2015-05-13 16:39:04 +0530474 ('main_tmpl_change', dict(template=main_template_change_prop,
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000475 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 Mishrab1293ae2015-05-13 16:39:04 +0530482 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 Salkeld2bd63a42015-01-07 11:11:29 +1000488 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 Salkeld2bd63a42015-01-07 11:11:29 +1000496
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 Mishra477efc92015-07-31 13:01:45 +0530519class TemplateResourceUpdateFailedTest(functional_base.FunctionalTestsBase):
Angus Salkeld5a3e1dd2015-02-03 15:31:47 +1000520 """Prove that we can do updates on a nested stack to fix a stack."""
521 main_template = '''
522HeatTemplateFormatVersion: '2012-12-12'
523Resources:
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 = '''
534HeatTemplateFormatVersion: '2012-12-12'
535Resources:
536 RealRandom:
537 Type: OS::Heat::RandomString
538'''
539
540 def setUp(self):
541 super(TemplateResourceUpdateFailedTest, self).setUp()
Sergey Krayneva265c132015-02-13 03:51:03 -0500542 self.assign_keypair()
Angus Salkeld5a3e1dd2015-02-03 15:31:47 +1000543
544 def test_update_on_failed_create(self):
Vikas Jainac6b02f2015-02-11 11:31:46 -0800545 # create a stack with "server" dependent on "keypair", but
Angus Salkeld5a3e1dd2015-02-03 15:31:47 +1000546 # 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 Mishra477efc92015-07-31 13:01:45 +0530562class TemplateResourceAdoptTest(functional_base.FunctionalTestsBase):
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000563 """Prove that we can do template resource adopt/abandon."""
564
565 main_template = '''
566HeatTemplateFormatVersion: '2012-12-12'
567Resources:
568 the_nested:
569 Type: the.yaml
570 Properties:
571 one: my_name
572Outputs:
573 identifier:
574 Value: {Ref: the_nested}
575 value:
576 Value: {'Fn::GetAtt': [the_nested, the_str]}
577'''
578
579 nested_templ = '''
580HeatTemplateFormatVersion: '2012-12-12'
581Parameters:
582 one:
583 Default: foo
584 Type: String
585Resources:
586 RealRandom:
587 Type: OS::Heat::RandomString
588 Properties:
589 salt: {Ref: one}
590Outputs:
591 the_str:
592 Value: {'Fn::GetAtt': [RealRandom, value]}
593'''
594
595 def setUp(self):
596 super(TemplateResourceAdoptTest, self).setUp()
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000597
598 def _yaml_to_json(self, yaml_templ):
599 return yaml.load(yaml_templ)
600
601 def test_abandon(self):
Sergey Kraynevbf67ce32015-04-17 10:54:20 -0400602 stack_identifier = self.stack_create(
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000603 template=self.main_template,
604 files={'the.yaml': self.nested_templ},
Sergey Kraynevbf67ce32015-04-17 10:54:20 -0400605 enable_cleanup=False
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000606 )
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000607
Sirushti Murugesan04ee8022015-02-02 23:00:23 +0530608 info = self.stack_abandon(stack_id=stack_identifier)
Angus Salkeld2bd63a42015-01-07 11:11:29 +1000609 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 Salkeld87601722015-01-05 14:57:27 +1000639
640
Rabi Mishra477efc92015-07-31 13:01:45 +0530641class TemplateResourceCheckTest(functional_base.FunctionalTestsBase):
Angus Salkeld87601722015-01-05 14:57:27 +1000642 """Prove that we can do template resource check."""
643
644 main_template = '''
645HeatTemplateFormatVersion: '2012-12-12'
646Resources:
647 the_nested:
648 Type: the.yaml
649 Properties:
650 one: my_name
651Outputs:
652 identifier:
653 Value: {Ref: the_nested}
654 value:
655 Value: {'Fn::GetAtt': [the_nested, the_str]}
656'''
657
658 nested_templ = '''
659HeatTemplateFormatVersion: '2012-12-12'
660Parameters:
661 one:
662 Default: foo
663 Type: String
664Resources:
665 RealRandom:
666 Type: OS::Heat::RandomString
667 Properties:
668 salt: {Ref: one}
669Outputs:
670 the_str:
671 Value: {'Fn::GetAtt': [RealRandom, value]}
672'''
673
674 def setUp(self):
675 super(TemplateResourceCheckTest, self).setUp()
Angus Salkeld87601722015-01-05 14:57:27 +1000676
677 def test_check(self):
Sergey Kraynevbf67ce32015-04-17 10:54:20 -0400678 stack_identifier = self.stack_create(
Angus Salkeld87601722015-01-05 14:57:27 +1000679 template=self.main_template,
Sergey Kraynevbf67ce32015-04-17 10:54:20 -0400680 files={'the.yaml': self.nested_templ}
Angus Salkeld87601722015-01-05 14:57:27 +1000681 )
Angus Salkeld87601722015-01-05 14:57:27 +1000682
683 self.client.actions.check(stack_id=stack_identifier)
684 self._wait_for_stack_status(stack_identifier, 'CHECK_COMPLETE')
Angus Salkeld793b0fc2015-06-24 08:52:08 +1000685
686
Rabi Mishra477efc92015-07-31 13:01:45 +0530687class TemplateResourceErrorMessageTest(functional_base.FunctionalTestsBase):
Angus Salkeld793b0fc2015-06-24 08:52:08 +1000688 """Prove that nested stack errors don't suck."""
689 template = '''
690HeatTemplateFormatVersion: '2012-12-12'
691Resources:
692 victim:
693 Type: fail.yaml
694'''
695 nested_templ = '''
696HeatTemplateFormatVersion: '2012-12-12'
697Resources:
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 Salkeld793b0fc2015-06-24 08:52:08 +1000707
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_kushaev61a99e12015-07-31 16:22:45 +0300720
721
Rabi Mishra477efc92015-07-31 13:01:45 +0530722class TemplateResourceSuspendResumeTest(functional_base.FunctionalTestsBase):
kairat_kushaev61a99e12015-07-31 16:22:45 +0300723 """Prove that we can do template resource suspend/resume."""
724
725 main_template = '''
726heat_template_version: 2014-10-16
727parameters:
728resources:
729 the_nested:
730 type: the.yaml
731'''
732
733 nested_templ = '''
734heat_template_version: 2014-10-16
735resources:
736 test_random_string:
737 type: OS::Heat::RandomString
738'''
739
740 def setUp(self):
741 super(TemplateResourceSuspendResumeTest, self).setUp()
kairat_kushaev61a99e12015-07-31 16:22:45 +0300742
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)