Пример #1
0
    def test_resolve_rule_other_with_ref(self):
        client_plugin, schema = self._test_resolve_rule()

        class rsrc(object):
            action = INIT = "INIT"

            def FnGetRefId(self):
                return 'resource_id'

        class DummyStack(dict):
            pass

        stack = DummyStack(another_res=rsrc())
        ref = hot_funcs.GetResource(stack, 'get_resource',
                                    'another_res')
        data = {'far': ref}
        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])
        self.assertTrue(tran.has_translation('far'))
        result = tran.translate('far', data['far'])
        self.assertEqual('yellow', result)
Пример #2
0
    def test_deprecated_network_id(self):
        template = """
        heat_template_version: 2015-04-30
        resources:
          net:
            type: OS::Neutron::Net
            properties:
              name: test
          subnet:
            type: OS::Neutron::Subnet
            properties:
              network_id: { get_resource: net }
              cidr: 10.0.0.0/24
        """
        t = template_format.parse(template)
        stack = utils.parse_stack(t)
        rsrc = stack['subnet']
        nd = {'reference_id': 'fc68ea2c-b60b-4b4f-bd82-94ec81110766'}
        stk_defn.update_resource_data(stack.defn, 'net',
                                      node_data.NodeData.from_dict(nd))
        self.create_mock.return_value = {
            "subnet": {
                "id": "91e47a57-7508-46fe-afc9-fc454e8580e1",
                "ip_version": 4,
                "name": "name",
                "network_id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766",
                "tenant_id": "c1210485b2424d48804aad5d39c61b8f"
            }
        }
        stack.create()

        self.assertEqual(
            hot_funcs.GetResource(stack.defn, 'get_resource', 'net'),
            rsrc.properties.get('network'))
        self.assertIsNone(rsrc.properties.get('network_id'))
Пример #3
0
    def test_deprecated_network_id(self):
        template = """
        heat_template_version: 2015-04-30
        resources:
          net:
            type: OS::Neutron::Net
            properties:
              name: test
          subnet:
            type: OS::Neutron::Subnet
            properties:
              network_id: { get_resource: net }
              cidr: 10.0.0.0/24
        """
        t = template_format.parse(template)
        stack = utils.parse_stack(t)
        self.patchobject(stack['net'],
                         'FnGetRefId',
                         return_value='fc68ea2c-b60b-4b4f-bd82-94ec81110766')
        rsrc = stack['subnet']
        stack.create()

        self.assertEqual(hot_funcs.GetResource(stack, 'get_resource', 'net'),
                         rsrc.properties.get('network'))
        self.assertIsNone(rsrc.properties.get('network_id'))
Пример #4
0
    def test_resolve_rule_list_with_ref(self):
        client_plugin, schema = self._test_resolve_rule(is_list=True)

        class rsrc(object):
            action = INIT = "INIT"

        class DummyStack(dict):
            pass

        stack = DummyStack(another_res=rsrc())
        ref = hot_funcs.GetResource(stack, 'get_resource',
                                    'another_res')
        data = {
            'far': [{'red': ref}],
        }
        props = properties.Properties(schema, data)

        rule = translation.TranslationRule(
            props,
            translation.TranslationRule.RESOLVE,
            ['far', 'red'],
            client_plugin=client_plugin,
            finder='find_name_id'
            )
        rule.execute_rule()
        self.assertEqual(data, props.data)