Ejemplo n.º 1
0
    def setUp(self):
        super(TemplateResourceCrudTest, self).setUp()
        files = {'test_resource.template': json.dumps(self.provider)}
        self.ctx = utils.dummy_context()

        class DummyResource(object):
            support_status = support.SupportStatus()
            properties_schema = {
                "Foo": properties.Schema(properties.Schema.STRING,
                                         required=True)
            }
            attributes_schema = {}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load(
            {'resource_registry': {
                'DummyResource': 'test_resource.template'
            }})
        self.stack = parser.Stack(self.ctx,
                                  'test_stack',
                                  template.Template(empty_template,
                                                    files=files,
                                                    env=env),
                                  stack_id=str(uuid.uuid4()))

        self.defn = rsrc_defn.ResourceDefinition('test_t_res', "DummyResource",
                                                 {"Foo": "bar"})
        self.res = template_resource.TemplateResource('test_t_res', self.defn,
                                                      self.stack)
        self.assertIsNone(self.res.validate())
Ejemplo n.º 2
0
    def test_properties_type_mismatch(self):
        provider = {
            'Parameters': {
                'Foo': {'Type': 'String'},
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(object):
            properties_schema = {"Foo":
                                 properties.Schema(properties.Schema.MAP)}
            attributes_schema = {}

        json_snippet = {
            "Type": "DummyResource",
            "Properties": {
                "Foo": "bar",
            },
        }

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load({'resource_registry':
                  {'DummyResource': 'test_resource.template'}})
        stack = parser.Stack(utils.dummy_context(), 'test_stack',
                             parser.Template({}, files=files), env=env,
                             stack_id=str(uuid.uuid4()))

        temp_res = template_resource.TemplateResource('test_t_res',
                                                      json_snippet, stack)
        self.assertRaises(exception.StackValidationFailed,
                          temp_res.validate)
Ejemplo n.º 3
0
    def test_incorrect_template_provided_with_url(self):
        wrong_template = '''
         <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#
        '''

        env = environment.Environment()
        test_templ_name = 'http://heatr/bad_tmpl.yaml'
        env.load({'resource_registry': {'Test::Tmpl': test_templ_name}})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template, env=env),
                             stack_id=str(uuid.uuid4()))

        self.m.StubOutWithMock(urlfetch, "get")
        urlfetch.get(test_templ_name,
                     allowed_schemes=('http',
                                      'https')).AndReturn(wrong_template)
        self.m.ReplayAll()

        definition = rsrc_defn.ResourceDefinition('test_t_res', 'Test::Tmpl')
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        err = self.assertRaises(exception.StackValidationFailed,
                                temp_res.validate)
        self.assertIn('Error parsing template: ', six.text_type(err))

        self.m.VerifyAll()
Ejemplo n.º 4
0
    def test_properties_missing(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {
                'Blarg': {'Type': 'String', 'Default': 'wibble'},
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(object):
            support_status = support.SupportStatus()
            properties_schema = {"Foo":
                                 properties.Schema(properties.Schema.STRING,
                                                   required=True)}
            attributes_schema = {}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load({'resource_registry':
                  {'DummyResource': 'test_resource.template'}})
        stack = parser.Stack(utils.dummy_context(), 'test_stack',
                             template.Template(empty_template, files=files,
                             env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource")
        temp_res = template_resource.TemplateResource('test_t_res',
                                                      definition, stack)
        self.assertRaises(exception.StackValidationFailed,
                          temp_res.validate)
Ejemplo n.º 5
0
    def test_incorrect_template_provided_with_url(self):
        wrong_template = '''
         <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#
        '''

        env = environment.Environment()
        test_templ_name = 'http://heatr/bad_tmpl.yaml'
        env.load({'resource_registry': {'Test::Tmpl': test_templ_name}})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template, env=env),
                             stack_id=str(uuid.uuid4()))

        mock_get = self.patchobject(urlfetch,
                                    "get",
                                    return_value=wrong_template)

        definition = rsrc_defn.ResourceDefinition('test_t_res', 'Test::Tmpl')
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        err = self.assertRaises(exception.StackValidationFailed,
                                temp_res.validate)
        self.assertIn('Error parsing template http://heatr/bad_tmpl.yaml',
                      str(err))
        mock_get.assert_called_once_with(test_templ_name,
                                         allowed_schemes=(
                                             'http',
                                             'https',
                                         ))
Ejemplo n.º 6
0
    def test_resource_info_special(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {
                'Foo': {'Type': 'Boolean'},
            },
        }
        files = {'test_resource.template': json.dumps(provider),
                 'foo.template': json.dumps(provider)}

        class DummyResource(object):
            support_status = support.SupportStatus()
            properties_schema = {"Foo":
                                 properties.Schema(properties.Schema.BOOLEAN)}
            attributes_schema = {}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load({'resource_registry':
                  {'DummyResource': 'test_resource.template',
                   'resources': {'foo': {'DummyResource': 'foo.template'}}}})
        stack = parser.Stack(utils.dummy_context(), 'test_stack',
                             template.Template(
                                 {'HeatTemplateFormatVersion': '2012-12-12'},
                                 files=files, env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('foo',
                                                  'DummyResource',
                                                  {"Foo": "False"})
        temp_res = template_resource.TemplateResource('foo',
                                                      definition, stack)
        self.assertEqual('foo.template',
                         temp_res.template_name)
Ejemplo n.º 7
0
    def test_system_template_retrieve_by_file(self):
        # make sure that a TemplateResource defined in the global environment
        # can be created and the template retrieved using the "file:"
        # scheme.
        g_env = resources.global_env()
        test_templ_name = 'file:///etc/heatr/frodo.yaml'
        g_env.load({'resource_registry': {'Test::Frodo': test_templ_name}})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             parser.Template(empty_template),
                             stack_id=str(uuid.uuid4()))

        minimal_temp = json.dumps({
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {},
            'Resources': {}
        })
        self.m.StubOutWithMock(urlfetch, "get")
        urlfetch.get(test_templ_name,
                     allowed_schemes=('http', 'https',
                                      'file')).AndReturn(minimal_temp)
        self.m.ReplayAll()

        definition = rsrc_defn.ResourceDefinition('test_t_res', 'Test::Frodo')
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertIsNone(temp_res.validate())
        self.m.VerifyAll()
Ejemplo n.º 8
0
    def test_attributes_missing_based_on_class(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Outputs': {
                'Blarg': {
                    'Value': 'wibble'
                },
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(generic_rsrc.GenericResource):
            attributes_schema = {"Foo": attributes.Schema("A test attribute")}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load(
            {'resource_registry': {
                'DummyResource': 'test_resource.template'
            }})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template,
                                               files=files,
                                               env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource")
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
Ejemplo n.º 9
0
    def test_properties_extra_required(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {
                'Blarg': {
                    'Type': 'String'
                },
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(object):
            properties_schema = {}
            attributes_schema = {}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load(
            {'resource_registry': {
                'DummyResource': 'test_resource.template'
            }})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             parser.Template(empty_template, files=files),
                             env=env,
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource",
                                                  {"Blarg": "wibble"})
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
Ejemplo n.º 10
0
    def test_attributes_missing(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Outputs': {
                'Blarg': {
                    'Value': 'wibble'
                },
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(object):
            properties_schema = {}
            attributes_schema = {"Foo": "A test attribute"}

        json_snippet = {
            "Type": "DummyResource",
        }

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load(
            {'resource_registry': {
                'DummyResource': 'test_resource.template'
            }})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             parser.Template(empty_template, files=files),
                             env=env,
                             stack_id=str(uuid.uuid4()))

        temp_res = template_resource.TemplateResource('test_t_res',
                                                      json_snippet, stack)
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
Ejemplo n.º 11
0
    def test_properties_missing(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {
                'Blarg': {
                    'Type': 'String',
                    'Default': 'wibble'
                },
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        env = environment.Environment()
        env.load({
            'resource_registry': {
                'ResourceWithRequiredPropsAndEmptyAttrs':
                'test_resource.template'
            }
        })
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template,
                                               files=files,
                                               env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition(
            'test_t_res', "ResourceWithRequiredPropsAndEmptyAttrs")
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
Ejemplo n.º 12
0
    def test_attributes_extra(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Outputs': {
                'Foo': {
                    'Value': 'bar'
                },
                'Blarg': {
                    'Value': 'wibble'
                },
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(object):
            properties_schema = {}
            attributes_schema = {"Foo": attributes.Schema("A test attribute")}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load(
            {'resource_registry': {
                'DummyResource': 'test_resource.template'
            }})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             parser.Template(empty_template, files=files),
                             env=env,
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource")
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertIsNone(temp_res.validate())
Ejemplo n.º 13
0
    def setUp(self):
        super(TemplateResourceCrudTest, self).setUp()
        files = {'test_resource.template': json.dumps(self.provider)}
        self.ctx = utils.dummy_context()

        env = environment.Environment()
        env.load({
            'resource_registry': {
                'ResourceWithRequiredPropsAndEmptyAttrs':
                'test_resource.template'
            }
        })
        self.stack = parser.Stack(self.ctx,
                                  'test_stack',
                                  template.Template(empty_template,
                                                    files=files,
                                                    env=env),
                                  stack_id=str(uuid.uuid4()))

        self.defn = rsrc_defn.ResourceDefinition(
            'test_t_res', "ResourceWithRequiredPropsAndEmptyAttrs",
            {"Foo": "bar"})
        self.res = template_resource.TemplateResource('test_t_res', self.defn,
                                                      self.stack)
        self.assertIsNone(self.res.validate())
Ejemplo n.º 14
0
    def test_metadata_update_called(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {
                'Foo': {'Type': 'Boolean'},
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(object):
            support_status = support.SupportStatus()
            properties_schema = {"Foo":
                                 properties.Schema(properties.Schema.BOOLEAN)}
            attributes_schema = {}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load({'resource_registry':
                  {'DummyResource': 'test_resource.template'}})
        stack = parser.Stack(utils.dummy_context(), 'test_stack',
                             template.Template(
                                 {'HeatTemplateFormatVersion': '2012-12-12'},
                                 files=files, env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource",
                                                  {"Foo": "False"})
        temp_res = template_resource.TemplateResource('test_t_res',
                                                      definition, stack)
        temp_res.metadata_set = mock.Mock()
        temp_res.metadata_update()
        temp_res.metadata_set.assert_called_once_with({})
Ejemplo n.º 15
0
    def test_properties_normal(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {
                'Foo': {'Type': 'String'},
                'Blarg': {'Type': 'String', 'Default': 'wibble'},
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(object):
            properties_schema = {"Foo":
                                 properties.Schema(properties.Schema.STRING,
                                                   required=True)}
            attributes_schema = {}

        json_snippet = {
            "Type": "DummyResource",
            "Properties": {
                "Foo": "bar",
            },
        }

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load({'resource_registry':
                  {'DummyResource': 'test_resource.template'}})
        stack = parser.Stack(utils.dummy_context(), 'test_stack',
                             parser.Template({}, files=files), env=env,
                             stack_id=str(uuid.uuid4()))

        temp_res = template_resource.TemplateResource('test_t_res',
                                                      json_snippet, stack)
        self.assertIsNone(temp_res.validate())
Ejemplo n.º 16
0
    def test_properties_type_match(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {
                'Length': {'Type': 'Number'},
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(generic_rsrc.GenericResource):
            support_status = support.SupportStatus()
            properties_schema = {"Length":
                                 properties.Schema(properties.Schema.INTEGER)}
            attributes_schema = {}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load({'resource_registry':
                  {'DummyResource': 'test_resource.template'}})
        stack = parser.Stack(utils.dummy_context(), 'test_stack',
                             template.Template(
                                 {'HeatTemplateFormatVersion': '2012-12-12'},
                                 files=files, env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource",
                                                  {"Length": 10})
        temp_res = template_resource.TemplateResource('test_t_res',
                                                      definition, stack)
        self.assertIsNone(temp_res.validate())
Ejemplo n.º 17
0
    def test_user_template_retrieve_fail(self):
        # make sure that a TemplateResource defined in the user environment
        # fails gracefully if the template file specified is inaccessible
        # we should be able to create the TemplateResource object, but
        # validation should fail, when the second attempt to access it is
        # made in validate()
        env = environment.Environment()
        test_templ_name = 'http://heatr/noexist.yaml'
        env.load({'resource_registry': {'Test::Flippy': test_templ_name}})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             parser.Template(empty_template),
                             env=env,
                             stack_id=str(uuid.uuid4()))

        self.m.StubOutWithMock(urlfetch, "get")
        urlfetch.get(test_templ_name,
                     allowed_schemes=('http', 'https'))\
            .AndRaise(urlfetch.URLFetchError(_('Failed to retrieve template')))
        self.m.ReplayAll()

        definition = rsrc_defn.ResourceDefinition('test_t_res', 'Test::Flippy')
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
        self.m.VerifyAll()
Ejemplo n.º 18
0
    def test_properties_type_mismatch(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {
                'Foo': {'Type': 'String'},
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(generic_rsrc.GenericResource):
            support_status = support.SupportStatus()
            properties_schema = {"Foo":
                                 properties.Schema(properties.Schema.MAP)}
            attributes_schema = {}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load({'resource_registry':
                  {'DummyResource': 'test_resource.template'}})
        stack = parser.Stack(utils.dummy_context(), 'test_stack',
                             template.Template(
                                 {'HeatTemplateFormatVersion': '2012-12-12'},
                                 files=files, env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource",
                                                  {"Foo": "bar"})
        temp_res = template_resource.TemplateResource('test_t_res',
                                                      definition, stack)
        ex = self.assertRaises(exception.StackValidationFailed,
                               temp_res.validate)
        self.assertEqual("Property Foo type mismatch between facade "
                         "DummyResource (Map) and provider (String)",
                         six.text_type(ex))
Ejemplo n.º 19
0
    def test_attributes_missing_no_class(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Outputs': {
                'Blarg': {'Value': 'wibble'},
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        env = environment.Environment()
        env.load({'resource_registry':
                  {'DummyResource2': 'test_resource.template'}})
        stack = parser.Stack(utils.dummy_context(), 'test_stack',
                             template.Template(empty_template, files=files,
                             env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource2")
        temp_res = template_resource.TemplateResource('test_t_res',
                                                      definition, stack)
        nested = mock.Mock()
        nested.outputs = {'Blarg': {'Value': 'fluffy'}}
        temp_res._nested = nested
        self.assertRaises(exception.InvalidTemplateAttribute,
                          temp_res.FnGetAtt, 'Foo')
Ejemplo n.º 20
0
    def test_system_template_retrieve_fail(self):
        # make sure that a TemplateResource defined in the global environment
        # fails gracefully if the template file specified is inaccessible
        # we should be able to create the TemplateResource object, but
        # validation should fail, when the second attempt to access it is
        # made in validate()
        g_env = resources.global_env()
        test_templ_name = 'file:///etc/heatr/frodo.yaml'
        g_env.load({'resource_registry': {'Test::Frodo': test_templ_name}})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             parser.Template({}),
                             stack_id=str(uuid.uuid4()))

        self.m.StubOutWithMock(urlfetch, "get")
        urlfetch.get(test_templ_name,
                     allowed_schemes=('http', 'https',
                                      'file')).AndRaise(IOError)
        self.m.ReplayAll()

        temp_res = template_resource.TemplateResource('test_t_res',
                                                      {"Type": 'Test::Frodo'},
                                                      stack)
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
        self.m.VerifyAll()
Ejemplo n.º 21
0
    def test_system_template_retrieve_fail(self):
        # make sure that a TemplateResource defined in the global environment
        # fails gracefully if the template file specified is inaccessible
        # we should be able to create the TemplateResource object, but
        # validation should fail, when the second attempt to access it is
        # made in validate()
        g_env = resources.global_env()
        test_templ_name = 'file:///etc/heatr/frodo.yaml'
        g_env.load({'resource_registry': {'Test::Frodo': test_templ_name}})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template),
                             stack_id=str(uuid.uuid4()))

        mock_get = self.patchobject(urlfetch,
                                    "get",
                                    side_effect=urlfetch.URLFetchError(
                                        _('Failed to retrieve template')))

        definition = rsrc_defn.ResourceDefinition('test_t_res', 'Test::Frodo')
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
        mock_get.assert_called_once_with(test_templ_name,
                                         allowed_schemes=(
                                             'http',
                                             'https',
                                             'file',
                                         ))
Ejemplo n.º 22
0
    def test_attributes_not_parsable(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Outputs': {
                'Foo': {
                    'Value': 'bar'
                },
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(generic_rsrc.GenericResource):
            support_status = support.SupportStatus()
            properties_schema = {}
            attributes_schema = {"Foo": attributes.Schema("A test attribute")}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load(
            {'resource_registry': {
                'DummyResource': 'test_resource.template'
            }})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template,
                                               files=files,
                                               env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource")
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        temp_res.resource_id = 'dummy_id'
        temp_res.nested_identifier = mock.Mock()
        temp_res.nested_identifier.return_value = {'foo': 'bar'}

        temp_res._rpc_client = mock.MagicMock()
        output = {
            'outputs': [{
                'output_key': 'Foo',
                'output_value': None,
                'output_error': 'it is all bad'
            }]
        }
        temp_res._rpc_client.show_stack.return_value = [output]
        temp_res._rpc_client.list_stack_resources.return_value = []
        self.assertIsNone(temp_res.validate())
        self.assertRaises(exception.TemplateOutputError, temp_res.FnGetAtt,
                          'Foo')
Ejemplo n.º 23
0
    def test_user_template_not_retrieved_by_file(self):
        # make sure that a TemplateResource defined in the user environment
        # can NOT be retrieved using the "file:" scheme, validation should fail
        env = environment.Environment()
        test_templ_name = 'file:///etc/heatr/flippy.yaml'
        env.load({'resource_registry': {'Test::Flippy': test_templ_name}})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template, env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res', 'Test::Flippy')
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)

        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
Ejemplo n.º 24
0
    def test_user_template_not_retrieved_by_file(self):
        # make sure that a TemplateResource defined in the user environment
        # can NOT be retrieved using the "file:" scheme, validation should fail
        env = environment.Environment()
        test_templ_name = 'file:///etc/heatr/flippy.yaml'
        env.load({'resource_registry': {'Test::Flippy': test_templ_name}})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             parser.Template({}),
                             env=env,
                             stack_id=uuidutils.generate_uuid())

        temp_res = template_resource.TemplateResource('test_t_res',
                                                      {"Type": 'Test::Flippy'},
                                                      stack)

        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
Ejemplo n.º 25
0
    def test_attributes_not_parsable(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Outputs': {
                'Foo': {
                    'Value': 'bar'
                },
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(generic_rsrc.GenericResource):
            support_status = support.SupportStatus()
            properties_schema = {}
            attributes_schema = {"Foo": attributes.Schema("A test attribute")}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load(
            {'resource_registry': {
                'DummyResource': 'test_resource.template'
            }})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template,
                                               files=files,
                                               env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource")
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertIsNone(temp_res.validate())
        nested = mock.Mock()
        nested.outputs = {
            'Foo': {
                'Value': 'not-this',
                'error_msg': 'it is all bad'
            }
        }
        nested.output.return_value = None
        temp_res._nested = nested
        self.assertRaises(exception.InvalidTemplateAttribute,
                          temp_res.FnGetAtt, 'Foo')
Ejemplo n.º 26
0
    def test_user_template_retrieve_fail_ext(self):
        # make sure that a TemplateResource defined in the user environment
        # fails gracefully if the template file is the wrong extension
        # we should be able to create the TemplateResource object, but
        # validation should fail, when the second attempt to access it is
        # made in validate()
        env = environment.Environment()
        test_templ_name = 'http://heatr/letter_to_granny.docx'
        env.load({'resource_registry': {'Test::Flippy': test_templ_name}})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template, env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res', 'Test::Flippy')
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertRaises(exception.StackValidationFailed, temp_res.validate)
Ejemplo n.º 27
0
    def test_attributes_missing_no_class(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Outputs': {
                'Blarg': {
                    'Value': 'wibble'
                },
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        env = environment.Environment()
        env.load({
            'resource_registry': {
                'DummyResource2': 'test_resource.template'
            }
        })
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template,
                                               files=files,
                                               env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource2")
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        temp_res.resource_id = 'dummy_id'
        temp_res.nested_identifier = mock.Mock()
        temp_res.nested_identifier.return_value = {'foo': 'bar'}

        temp_res._rpc_client = mock.MagicMock()
        output = {
            'outputs': [{
                'output_key': 'Blarg',
                'output_value': 'fluffy'
            }]
        }
        temp_res._rpc_client.show_stack.return_value = [output]
        self.assertRaises(exception.InvalidTemplateAttribute,
                          temp_res.FnGetAtt, 'Foo')
Ejemplo n.º 28
0
    def test_attributes_not_parsable(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Outputs': {
                'Blarg': {
                    'Value': 'wibble'
                },
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        env = environment.Environment()
        env.load(
            {'resource_registry': {
                'DummyResource': 'test_resource.template'
            }})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             template.Template(empty_template,
                                               files=files,
                                               env=env),
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource")
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertIsNone(temp_res.validate())
        nested = mock.Mock()
        nested.outputs = {
            'Blarg': {
                'Value': 'not-this',
                'error_msg': 'it is all bad'
            }
        }
        nested.output.return_value = None
        temp_res._nested = nested
        self.assertRaises(exception.InvalidTemplateAttribute,
                          temp_res.FnGetAtt, 'Blarg')
Ejemplo n.º 29
0
    def test_boolean_type_provider(self):
        provider = {
            'HeatTemplateFormatVersion': '2012-12-12',
            'Parameters': {
                'Foo': {
                    'Type': 'Boolean'
                },
            },
        }
        files = {'test_resource.template': json.dumps(provider)}

        class DummyResource(object):
            properties_schema = {
                "Foo": properties.Schema(properties.Schema.BOOLEAN)
            }
            attributes_schema = {}

        env = environment.Environment()
        resource._register_class('DummyResource', DummyResource)
        env.load(
            {'resource_registry': {
                'DummyResource': 'test_resource.template'
            }})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             parser.Template(
                                 {'HeatTemplateFormatVersion': '2012-12-12'},
                                 files=files),
                             env=env,
                             stack_id=str(uuid.uuid4()))

        definition = rsrc_defn.ResourceDefinition('test_t_res',
                                                  "DummyResource",
                                                  {"Foo": "False"})
        temp_res = template_resource.TemplateResource('test_t_res', definition,
                                                      stack)
        self.assertIsNone(temp_res.validate())
Ejemplo n.º 30
0
    def test_system_template_retrieve_by_file(self):
        # make sure that a TemplateResource defined in the global environment
        # can be created and the template retrieved using the "file:"
        # scheme.
        g_env = resources.global_env()
        test_templ_name = 'file:///etc/heatr/frodo.yaml'
        g_env.load({'resource_registry': {'Test::Frodo': test_templ_name}})
        stack = parser.Stack(utils.dummy_context(),
                             'test_stack',
                             parser.Template({}),
                             stack_id=uuidutils.generate_uuid())

        minimal_temp = json.dumps({'Parameters': {}, 'Resources': {}})
        self.m.StubOutWithMock(urlfetch, "get")
        urlfetch.get(test_templ_name,
                     allowed_schemes=('http', 'https',
                                      'file')).AndReturn(minimal_temp)
        self.m.ReplayAll()

        temp_res = template_resource.TemplateResource('test_t_res',
                                                      {"Type": 'Test::Frodo'},
                                                      stack)
        self.assertEqual(None, temp_res.validate())
        self.m.VerifyAll()