From aeb783fdcfd40584e00206a947f391f8fc182126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Jens=C3=A5s?= Date: Fri, 13 Jul 2018 10:47:28 +0200 Subject: [PATCH] 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 --- puppet/role.role.j2.yaml | 8 +++++--- ...ix-str-replace-hostname-issue-393fb6954f12f7e6.yaml | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/fix-str-replace-hostname-issue-393fb6954f12f7e6.yaml diff --git a/puppet/role.role.j2.yaml b/puppet/role.role.j2.yaml index 9ff4da7992..627384f0e8 100644 --- a/puppet/role.role.j2.yaml +++ b/puppet/role.role.j2.yaml @@ -360,9 +360,11 @@ resources: user_data_format: SOFTWARE_CONFIG user_data: {get_resource: UserData} name: - str_replace: - template: {get_param: Hostname} - params: {get_param: HostnameMap} + yaql: + expression: $.data.hostname_map.get($.data.hostname, $.data.hostname) + data: + hostname: {get_param: Hostname} + hostname_map: {get_param: HostnameMap} software_config_transport: {get_param: SoftwareConfigTransport} metadata: map_merge: diff --git a/releasenotes/notes/fix-str-replace-hostname-issue-393fb6954f12f7e6.yaml b/releasenotes/notes/fix-str-replace-hostname-issue-393fb6954f12f7e6.yaml new file mode 100644 index 0000000000..0241364526 --- /dev/null +++ b/releasenotes/notes/fix-str-replace-hostname-issue-393fb6954f12f7e6.yaml @@ -0,0 +1,10 @@ +--- +fixes: + - | + Fixes an issue where Custom Hostnames is in use. Previously it was possible + that the ``HostnameMap`` lookup lookup would return unexpected and + incorrect results if the hostname (the key) is not in the map. The string + replacement mechanism used previously was replaced by a yaql expression + that will do exact matching only. If no matching key is in the + HostnameMap, the default hostname is returned. + `bug 1781560 `_.