~ubuntu-branches/ubuntu/saucy/heat/saucy-proposed

« back to all changes in this revision

Viewing changes to heat/tests/test_provider_template.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-10-12 16:53:03 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20131012165303-0sc41ujl3luuu56q
Tags: 2013.2~rc2-0ubuntu1
New upstream release candidate (LP: #1239156).

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from heat.engine import properties
25
25
from heat.engine import resource
26
26
from heat.engine import resources
 
27
from heat.engine import scheduler
27
28
from heat.engine.resources import template_resource
28
29
 
29
30
from heat.openstack.common import uuidutils
495
496
                                                      stack)
496
497
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
497
498
        self.m.VerifyAll()
 
499
 
 
500
    def create_stack(self, template):
 
501
        t = template_format.parse(template)
 
502
        stack = self.parse_stack(t)
 
503
        stack.create()
 
504
        self.assertEqual(stack.state, (stack.CREATE, stack.COMPLETE))
 
505
        return stack
 
506
 
 
507
    def parse_stack(self, t):
 
508
        ctx = utils.dummy_context('test_username', 'aaaa', 'password')
 
509
        stack_name = 'test_stack'
 
510
        tmpl = parser.Template(t)
 
511
        stack = parser.Stack(ctx, stack_name, tmpl)
 
512
        stack.store()
 
513
        return stack
 
514
 
 
515
    def test_template_resource_update(self):
 
516
        # assertion: updating a template resource is never destructive
 
517
        #            as it defers to the nested stack to determine if anything
 
518
        #            needs to be replaced.
 
519
 
 
520
        utils.setup_dummy_db()
 
521
        resource._register_class('GenericResource',
 
522
                                 generic_rsrc.GenericResource)
 
523
 
 
524
        templ_resource_name = 'http://server.test/the.yaml'
 
525
        test_template = '''
 
526
HeatTemplateFormatVersion: '2012-12-12'
 
527
Resources:
 
528
  the_nested:
 
529
    Type: %s
 
530
    Properties:
 
531
      one: myname
 
532
''' % templ_resource_name
 
533
 
 
534
        self.m.StubOutWithMock(urlfetch, "get")
 
535
        urlfetch.get(templ_resource_name,
 
536
                     allowed_schemes=('http',
 
537
                                      'https')).MultipleTimes().\
 
538
            AndReturn('''
 
539
HeatTemplateFormatVersion: '2012-12-12'
 
540
Parameters:
 
541
  one:
 
542
    Type: String
 
543
Resources:
 
544
  NestedResource:
 
545
    Type: GenericResource
 
546
Outputs:
 
547
  Foo:
 
548
    Value: {Ref: one}
 
549
''')
 
550
 
 
551
        self.m.ReplayAll()
 
552
 
 
553
        stack = self.create_stack(test_template)
 
554
        templ_resource = stack['the_nested']
 
555
        self.assertEqual('myname', templ_resource.FnGetAtt('Foo'))
 
556
 
 
557
        update_snippet = {
 
558
            "Type": templ_resource_name,
 
559
            "Properties": {
 
560
                "one": "yourname"
 
561
            }
 
562
        }
 
563
        # test that update() does NOT raise UpdateReplace.
 
564
        updater = scheduler.TaskRunner(templ_resource.update, update_snippet)
 
565
        self.assertEqual(None, updater())
 
566
        self.assertEqual('yourname', templ_resource.FnGetAtt('Foo'))
 
567
 
 
568
        self.m.VerifyAll()