Comment 5 for bug 1819737

Revision history for this message
Luca Miccini (lmiccini2) wrote :

I think the issue is in the way lists are handled:

def replace_links_in_template(template_part, link_replacement):
    """Replace get_file and type file links in a Heat template

    Scan the template for 'get_file' and 'type' occurrences, and
    replace the file paths according to link_replacement
    dict. (Key/value in link_replacement are from/to, respectively.)
    """

    def replaced_dict_value(key, value):
        if ((key == 'get_file' or key == 'type') and
                isinstance(value, six.string_types)):
            return link_replacement.get(value, value)
        else:
            return replace_links_in_template(value, link_replacement)

    def replaced_list_value(value):
        return replace_links_in_template(value, link_replacement)

    if isinstance(template_part, dict):
        return {k: replaced_dict_value(k, v)
                for k, v in six.iteritems(template_part)}
    elif isinstance(template_part, list):
        return map(replaced_list_value, template_part)

    else:
        return template_part

both empty and non-empty lists are ending up like:

template_part: []

replaced value: <function replace_links_in_template.<locals>.replaced_list_value at 0x7fea0d31a378>
...

template_part:

[{'type': 'interface', 'name': 'nic1', 'use_dhcp': False, 'dns_servers': {'get_param': 'DnsServers'}, 'addresses': [{'ip_netmask': {'list_join': ['/', [{'get_param': 'ControlPlaneIp'}, {'get_param': 'ControlPlaneSubnetCidr'}]]}}], 'routes': [{'ip_netmask': '0.0.0.0/0', 'next_hop': {'get_param': 'ControlPlaneDefaultRoute'}, 'default': True}, {'ip_netmask': '169.254.169.254/32', 'next_hop': {'get_param': 'EC2MetadataIp'}}]}, {'type': 'ovs_bridge', 'name': 'br-isolated', 'use_dhcp': False, 'members': [{'type': 'interface', 'name': 'nic2', 'primary': True}, {'type': 'vlan', 'vlan_id': {'get_param': 'InternalApiNetworkVlanID'}, 'addresses': [{'ip_netmask': {'get_param': 'InternalApiIpSubnet'}}]}, {'type': 'vlan', 'vlan_id': {'get_param': 'StorageNetworkVlanID'}, 'addresses': [{'ip_netmask': {'get_param': 'StorageIpSubnet'}}]}, {'type': 'vlan', 'vlan_id': {'get_param': 'StorageMgmtNetworkVlanID'}, 'addresses': [{'ip_netmask': {'get_param': 'StorageMgmtIpSubnet'}}]}, {'type': 'vlan', 'vlan_id': {'get_param': 'TenantNetworkVlanID'}, 'addresses': [{'ip_netmask': {'get_param': 'TenantIpSubnet'}}]}]}, {'type': 'ovs_bridge', 'name': 'br-ex', 'use_dhcp': False, 'addresses': [{'ip_netmask': {'get_param': 'ExternalIpSubnet'}}], 'routes': [{'ip_netmask': '0.0.0.0/0', 'next_hop': {'get_param': 'ExternalInterfaceDefaultRoute'}}], 'members': [{'type': 'interface', 'name': 'nic3', 'primary': True}]}]

replaced value:

<function replace_links_in_template.<locals>.replaced_list_value at 0x7fea0d31ab70>