From e2a8a494c5abf64ac5ed16e7f2b20edd4535c2d4 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Tue, 19 Feb 2019 12:50:16 -0700 Subject: [PATCH] Handle upper and lower case system uuids We need to be able to handle when system uuids are upper or lower case because newer versions of dmidecode have normalized to lower case. Users who were on CentOS/RHEL 7.5 and older may have per-node customizations with upper case which turn lowercase with an update to 7.6. This affects hieradata customizations as well as os-net-config mapping files. This change outputs both an upper and lowercase hieradata uuid file to handle the both versions of the UUID. Additionally this change normalizes the id comparison for os-net-config mappings to lower case. Change-Id: I65f46056f8a908c60c99d1cee3738344a0bce6b7 Closes-Bug: #1816652 --- firstboot/os-net-config-mappings.yaml | 5 +++-- puppet/extraconfig/pre_deploy/per_node.yaml | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/firstboot/os-net-config-mappings.yaml b/firstboot/os-net-config-mappings.yaml index 7cab34687e..3cb4f2a8ec 100644 --- a/firstboot/os-net-config-mappings.yaml +++ b/firstboot/os-net-config-mappings.yaml @@ -105,9 +105,10 @@ resources: if 'dmiString' in data[node] and 'id' in data[node]: ps = Popen([ 'dmidecode', '--string', data[node].get('dmiString') ], - stdout=PIPE) + stdout=PIPE, universal_newlines=True) out, err = ps.communicate() - if data[node].get('id') == out.rstrip(): + # See LP#1816652 + if data[node].get('id').lower() == out.rstrip().lower(): write_mapping_file(lc_interface_mapping) break " diff --git a/puppet/extraconfig/pre_deploy/per_node.yaml b/puppet/extraconfig/pre_deploy/per_node.yaml index 5e79748108..3cc046c822 100644 --- a/puppet/extraconfig/pre_deploy/per_node.yaml +++ b/puppet/extraconfig/pre_deploy/per_node.yaml @@ -32,6 +32,10 @@ resources: node_id=$(dmidecode --s system-uuid | awk 'match($0, \ /[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/) \ { print substr($0, RSTART, RLENGTH) }' | tr '[:upper:]' '[:lower:]') + # thanks to dmidecode 3.1, we have to handle both the upper case + # and lower case versions of the UUID from dmidecode. LP#1816652 + # upper for dmidecode < 3.1 and lower for dmidecode >= 3.1 + node_id_upper=$(echo $node_id | tr '[:lower:]' '[:upper:]') # needed to handle where python lives function get_python() { @@ -47,6 +51,14 @@ resources: cnt = json.loads(input) print json.dumps(cnt.get('${node_id}', {})) " > /etc/puppet/hieradata/${node_id}.json + # handle upper case node id LP#1816652 + echo $node_lookup | $(get_python) -c " + import json + import sys + input = sys.stdin.readline() or '{}' + cnt = json.loads(input) + print json.dumps(cnt.get('${node_id_upper}', {})) + " > /etc/puppet/hieradata/${node_id_upper}.json NodeSpecificDeployment: type: OS::Heat::SoftwareDeployment