HostnameMap lookup may return unexpected results if hostname is not in the map

Bug #1781560 reported by Harald Jensås
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tripleo
Fix Released
Medium
Steven Hardy

Bug Description

The use of str_replace to do lookup hostnames in HostnameMap may return unexptected resutls.

The code[1]:
        str_replace:
            template: {get_param: Hostname}
            params: {get_param: HostnameMap}

For example passing this data:

Hostname: overcloud-controller-123 HostnameMap: '{"overcloud-controller-12": "server-b", "overcloud-controller-1": "server-a"}'

Result value: server-b3

The str_replace will match on a substring if a key with the full string is not available in the map.

Most likely there are also other cases where the string matching would pick the wrong value.

[1] https://github.com/openstack/tripleo-heat-templates/blob/master/puppet/role.role.j2.yaml#L363-L365

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to tripleo-heat-templates (master)

Fix proposed to branch: master
Review: https://review.openstack.org/582475

Changed in tripleo:
assignee: nobody → Harald Jensås (harald-jensas)
status: Triaged → In Progress
Changed in tripleo:
assignee: Harald Jensås (harald-jensas) → Steven Hardy (shardy)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to tripleo-heat-templates (master)

Reviewed: https://review.openstack.org/582475
Committed: https://git.openstack.org/cgit/openstack/tripleo-heat-templates/commit/?id=aeb783fdcfd40584e00206a947f391f8fc182126
Submitter: Zuul
Branch: master

commit aeb783fdcfd40584e00206a947f391f8fc182126
Author: Harald Jensås <email address hidden>
Date: Fri Jul 13 10:47:28 2018 +0200

    Fix HostnameMap lookup - replace str_replace with yaql

    Using str_replace when looking up hostnames in
    HostnameMap may return unpredictable results.
    For example if the map contain:

    HostnameMap:
      overcloud-compute-12: cmp-12-london
      overcloud-compute-123: cmp-123-berlin

    When we do string replace for a hostname that is
    not in the map (example: 'overcloud-compute-124')
    it will match on the substring. The result would
    be 'cmp-12-london4'.

    This change replaces the str_replace with a yaql
    expression that will return the value of they key
    matching the hostname provided. If the key is not
    in the map, the hostname is returned.

    Closes-Bug: #1781560
    Change-Id: Ia3a6a3539cd566131cd81b4d755190aa5b61a573

Changed in tripleo:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/tripleo-heat-templates 9.0.0.0b4

This issue was fixed in the openstack/tripleo-heat-templates 9.0.0.0b4 development milestone.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.