From 1d054b8d891330061581b18f1026c3310291c690 Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Fri, 5 Aug 2022 11:30:13 -0500 Subject: [PATCH] (FACT-3140) Add partition type GUID Co-authored-by: Michael Hashizume --- lib/facter/resolvers/partitions.rb | 39 ++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/facter/resolvers/partitions.rb b/lib/facter/resolvers/partitions.rb index fc70a14485..3e0e391124 100644 --- a/lib/facter/resolvers/partitions.rb +++ b/lib/facter/resolvers/partitions.rb @@ -122,7 +122,18 @@ def execute_and_extract_blkid_info def populate_from_lsblk(partition_name, blkid_and_lsblk) return {} unless available?('lsblk', blkid_and_lsblk) - blkid_and_lsblk[:lsblk] ||= Facter::Core::Execution.execute('lsblk -fp', logger: log) + lsblk_version_raw = Facter::Core::Execution.execute('lsblk --version 2>&1', logger: log) + lsblk_version = lsblk_version_raw.match(/ \d\.\d+/)[0].to_f + + # The -p or --paths option was added in lsblk 2.23, anything before that it makes more sense to return and fall back to blkid + return {} if lsblk_version < 2.23 + + # lsblk 2.25 added support for GPT partition type GUIDs + blkid_and_lsblk[:lsblk] ||= if lsblk_version >= 2.25 + Facter::Core::Execution.execute('lsblk -p -P -o NAME,FSTYPE,UUID,LABEL,PARTUUID,PARTLABEL,PARTTYPE', logger: log) + else + Facter::Core::Execution.execute('lsblk -p -P -o NAME,FSTYPE,LABEL,UUID,PARTUUID,PARTLABEL', logger: log) + end part_info = blkid_and_lsblk[:lsblk].match(/#{partition_name}.*/).to_s.split(' ') return {} if part_info.empty? @@ -131,13 +142,25 @@ def populate_from_lsblk(partition_name, blkid_and_lsblk) end def parse_part_info(part_info) - result = { filesystem: part_info[1] } - - if part_info.count.eql?(5) - result[:label] = part_info[2] - result[:uuid] = part_info[3] - else - result[:uuid] = part_info[2] + result = {} + + part_info.each do |setting| + simple_string = setting.delete('"') + key, value = simple_string.split('=') + case key + when 'FSTYPE' + result['filesystem'] = value + when 'UUID' + result['uuid'] = value + when 'LABEL' + result['label'] = value + when 'PARTUUID' + result['part_uuid'] = value + when 'PARTLABEL' + result['part_label'] = value + when 'PARTTYPE' + result['part_type'] = value + end end result