Exemplo n.º 1
0
 def test_validate_no_scheme_address_for_get_attr(self):
     self.test_resource.properties.data['type'] = self.test_resource.WEBHOOK
     self.patchobject(cfn_funcs, 'GetAtt', return_value=None)
     get_att = cfn_funcs.GetAtt(self.stack, 'Fn::GetAtt',
                                ["ResourceA", "abc"])
     self.test_resource.properties.data['address'] = get_att
     self.assertIsNone(self.test_resource.validate())
Exemplo n.º 2
0
    def test_resolve_rule_other_with_get_attr(self):
        client_plugin, schema = self._test_resolve_rule()

        class DummyStack(dict):
            pass

        class rsrc(object):
            pass

        stack = DummyStack(another_res=rsrc())
        attr_func = cfn_funcs.GetAtt(stack, 'Fn::GetAtt',
                                     ['another_res', 'name'])
        data = {'far': attr_func}
        props = properties.Properties(schema, data)
        rule = translation.TranslationRule(
            props,
            translation.TranslationRule.RESOLVE,
            ['far'],
            client_plugin=client_plugin,
            finder='find_name_id')

        tran = translation.Translation(props)
        tran.set_rules([rule], client_resolve=False)
        self.assertFalse(tran.store_translated_values)
        self.assertFalse(tran.has_translation('far'))
        result = tran.translate('far', 'no_check', data['far'])
        self.assertEqual('no_check', result)
        self.assertIsNone(tran.resolved_translations.get('far'))
Exemplo n.º 3
0
 def test_resource_no_attribute_with_default_fn_get_att(self):
     func = functions.GetAtt(self.stack, 'Fn::GetAtt',
                             [self.rsrc.name, 'Bar'])
     ex = self.assertRaises(exception.InvalidTemplateAttribute,
                            func.validate)
     self.assertEqual('The Referenced Attribute (test_rsrc Bar) '
                      'is incorrect.', six.text_type(ex))
Exemplo n.º 4
0
    def test_resolve_rule_other_with_get_attr(self):
        client_plugin, schema = self._test_resolve_rule()

        class DummyStack(dict):
            pass

        class rsrc(object):
            pass

        stack = DummyStack(another_res=rsrc())
        attr_func = cfn_funcs.GetAtt(stack, 'Fn::GetAtt',
                                     ['another_res', 'name'])
        data = {'far': attr_func}
        props = properties.Properties(schema, data)
        rule = translation.TranslationRule(props,
                                           translation.TranslationRule.RESOLVE,
                                           ['far'],
                                           client_plugin=client_plugin,
                                           finder='find_name_id')
        rule.execute_rule(client_resolve=False)
        self.assertEqual(data, props.data)

        mock_getatt = self.patchobject(attr_func,
                                       'result',
                                       return_value='rose')
        rule.execute_rule()
        self.assertEqual('pink', props.get('far'))
        self.assertEqual(1, mock_getatt.call_count)
    def test_property_get_attr_translation_successfully_skipped(self):
        schema = {
            'source':
            properties.Schema(properties.Schema.LIST,
                              schema=properties.Schema(
                                  properties.Schema.MAP,
                                  schema={
                                      'sub-source':
                                      properties.Schema(
                                          properties.Schema.STRING)
                                  })),
            'destination':
            properties.Schema(properties.Schema.STRING)
        }

        class DummyStack(dict):
            pass

        class rsrc(object):
            pass

        stack = DummyStack(res=rsrc())
        attr_func = cfn_funcs.GetAtt(stack, 'Fn::GetAtt',
                                     ['res', 'sub-sources'])

        data = {'source': attr_func, 'destination': ''}
        props = properties.Properties(schema, data)

        rule = translation.TranslationRule(props,
                                           translation.TranslationRule.REPLACE,
                                           ['source', 'sub-sources'],
                                           value_path=['destination'])
        rule.execute_rule()
        self.assertEqual({'source': attr_func, 'destination': ''}, props.data)
Exemplo n.º 6
0
    def test_resource_is_not_appear_in_stack(self):
        self.stack.remove_resource(self.rsrc.name)

        func = functions.GetAtt(self.stack, 'Fn::GetAtt',
                                [self.rsrc.name, 'Foo'])
        ex = self.assertRaises(exception.InvalidTemplateReference,
                               func.validate)
        self.assertEqual('The specified reference "test_rsrc" (in unknown) '
                         'is incorrect.', six.text_type(ex))
Exemplo n.º 7
0
    def test_resource_no_attribute_with_overwritten_fn_get_att(self):
        res_defn = rsrc_defn.ResourceDefinition('test_rsrc',
                                                'OS::Test::FakeResource')
        self.rsrc = resource.Resource('test_rsrc', res_defn, self.stack)
        self.stack.add_resource(self.rsrc)
        self.rsrc.attributes_schema = {}

        func = functions.GetAtt(self.stack, 'Fn::GetAtt',
                                [self.rsrc.name, 'Foo'])
        self.assertIsNone(func.validate())
Exemplo n.º 8
0
    def test_resource_no_attribute_with_default_fn_get_att(self):
        res_defn = rsrc_defn.ResourceDefinition('test_rsrc',
                                                'ResWithStringPropAndAttr')
        self.rsrc = resource.Resource('test_rsrc', res_defn, self.stack)
        self.stack.add_resource(self.rsrc)
        stk_defn.update_resource_data(self.stack.defn, self.rsrc.name,
                                      self.rsrc.node_data())
        self.stack.validate()

        func = functions.GetAtt(self.stack.defn, 'Fn::GetAtt',
                                [self.rsrc.name, 'Bar'])
        ex = self.assertRaises(exception.InvalidTemplateAttribute,
                               func.validate)
        self.assertEqual('The Referenced Attribute (test_rsrc Bar) '
                         'is incorrect.', str(ex))
Exemplo n.º 9
0
 def test_resource_is_appear_in_stack(self):
     func = functions.GetAtt(self.stack.defn, 'Fn::GetAtt',
                             [self.rsrc.name, 'Foo'])
     self.assertIsNone(func.validate())