~ubuntu-branches/ubuntu/trusty/heat/trusty-security

« back to all changes in this revision

Viewing changes to heat/tests/test_provider_template.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-10-03 09:43:04 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20131003094304-k2c4qcsfn7cv6eos
Tags: 2013.2~rc1-0ubuntu1
* New upstream release.
* debian/control: Dropped python-d2to1 build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
            'Parameters': {
92
92
                'Foo': {'Type': 'String'},
93
93
                'AList': {'Type': 'CommaDelimitedList'},
 
94
                'ListEmpty': {'Type': 'CommaDelimitedList'},
94
95
                'ANum': {'Type': 'Number'},
95
96
                'AMap': {'Type': 'Json'},
96
97
            },
106
107
            properties_schema = {
107
108
                "Foo": {"Type": "String"},
108
109
                "AList": {"Type": "List"},
 
110
                "ListEmpty": {"Type": "List"},
109
111
                "ANum": {"Type": "Number"},
110
112
                "AMap": {"Type": "Map"}
111
113
            }
131
133
            "Properties": {
132
134
                "Foo": "Bar",
133
135
                "AList": ["one", "two", "three"],
 
136
                "ListEmpty": [],
134
137
                "ANum": 5,
135
138
                "AMap": map_prop_val
136
139
            }
422
425
 
423
426
    def test_user_template_not_retrieved_by_file(self):
424
427
        # make sure that a TemplateResource defined in the user environment
425
 
        # can NOT be retrieved using the "file:" scheme.
 
428
        # can NOT be retrieved using the "file:" scheme, validation should fail
426
429
        env = environment.Environment()
427
430
        test_templ_name = 'file:///etc/heatr/flippy.yaml'
428
431
        env.load({'resource_registry':
431
434
                             parser.Template({}), env=env,
432
435
                             stack_id=uuidutils.generate_uuid())
433
436
 
434
 
        self.assertRaises(ValueError,
435
 
                          template_resource.TemplateResource,
436
 
                          'test_t_res',
437
 
                          {"Type": 'Test::Flippy'},
438
 
                          stack)
 
437
        temp_res = template_resource.TemplateResource('test_t_res',
 
438
                                                      {"Type": 'Test::Flippy'},
 
439
                                                      stack)
 
440
 
 
441
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
 
442
 
 
443
    def test_system_template_retrieve_fail(self):
 
444
        # make sure that a TemplateResource defined in the global environment
 
445
        # fails gracefully if the template file specified is inaccessible
 
446
        # we should be able to create the TemplateResource object, but
 
447
        # validation should fail, when the second attempt to access it is
 
448
        # made in validate()
 
449
        g_env = resources.global_env()
 
450
        test_templ_name = 'file:///etc/heatr/frodo.yaml'
 
451
        g_env.load({'resource_registry':
 
452
                   {'Test::Frodo': test_templ_name}})
 
453
        stack = parser.Stack(utils.dummy_context(), 'test_stack',
 
454
                             parser.Template({}),
 
455
                             stack_id=uuidutils.generate_uuid())
 
456
 
 
457
        self.m.StubOutWithMock(urlfetch, "get")
 
458
        urlfetch.get(test_templ_name,
 
459
                     allowed_schemes=('http', 'https',
 
460
                                      'file')).AndRaise(IOError)
 
461
        urlfetch.get(test_templ_name,
 
462
                     allowed_schemes=('http', 'https',
 
463
                                      'file')).AndRaise(IOError)
 
464
        self.m.ReplayAll()
 
465
 
 
466
        temp_res = template_resource.TemplateResource('test_t_res',
 
467
                                                      {"Type": 'Test::Frodo'},
 
468
                                                      stack)
 
469
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
 
470
        self.m.VerifyAll()
 
471
 
 
472
    def test_user_template_retrieve_fail(self):
 
473
        # make sure that a TemplateResource defined in the user environment
 
474
        # fails gracefully if the template file specified is inaccessible
 
475
        # we should be able to create the TemplateResource object, but
 
476
        # validation should fail, when the second attempt to access it is
 
477
        # made in validate()
 
478
        env = environment.Environment()
 
479
        test_templ_name = 'http://heatr/noexist.yaml'
 
480
        env.load({'resource_registry':
 
481
                  {'Test::Flippy': test_templ_name}})
 
482
        stack = parser.Stack(utils.dummy_context(), 'test_stack',
 
483
                             parser.Template({}), env=env,
 
484
                             stack_id=uuidutils.generate_uuid())
 
485
 
 
486
        self.m.StubOutWithMock(urlfetch, "get")
 
487
        urlfetch.get(test_templ_name,
 
488
                     allowed_schemes=('http', 'https')).AndRaise(IOError)
 
489
        urlfetch.get(test_templ_name,
 
490
                     allowed_schemes=('http', 'https')).AndRaise(IOError)
 
491
        self.m.ReplayAll()
 
492
 
 
493
        temp_res = template_resource.TemplateResource('test_t_res',
 
494
                                                      {"Type": 'Test::Flippy'},
 
495
                                                      stack)
 
496
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
 
497
        self.m.VerifyAll()