41c250
From cc79cb3958b943b755a9b11b3e87ce820058ccaa Mon Sep 17 00:00:00 2001
41c250
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
41c250
Date: Fri, 14 Jan 2022 16:41:47 +0100
41c250
Subject: [PATCH 4/6] Update dscheck_VMware's rpctool check (#970)
41c250
41c250
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
41c250
RH-MergeRequest: 43: Datasource for VMware
41c250
RH-Commit: [4/6] 6f4d732c55c521869210d8aeedfa1150ea5a92f8
41c250
RH-Bugzilla: 2040704
41c250
RH-Acked-by: Mohamed Gamal Morsy <mmorsy@redhat.com>
41c250
RH-Acked-by: Eduardo Otubo <otubo@redhat.com>
41c250
41c250
commit 7781dec3306e9467f216cfcb36b7e10a8b38547a
41c250
Author: Shreenidhi Shedi <53473811+sshedi@users.noreply.github.com>
41c250
Date:   Fri Aug 13 00:40:39 2021 +0530
41c250
41c250
    Update dscheck_VMware's rpctool check (#970)
41c250
41c250
    This patch updates the dscheck_VMware function's use of "vmware-rpctool".
41c250
41c250
    When checking to see if a "guestinfo" property is set.
41c250
    Because a successful exit code can occur even if there is an empty
41c250
    string returned, it is possible that the VMware datasource will be
41c250
    loaded as a false-positive. This patch ensures that in addition to
41c250
    validating the exit code, the emitted output is also examined to ensure
41c250
    a non-empty value is returned by rpctool before returning "${DS_FOUND}"
41c250
    from "dscheck_VMware()".
41c250
41c250
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
41c250
---
41c250
 tools/ds-identify | 15 +++++++++------
41c250
 1 file changed, 9 insertions(+), 6 deletions(-)
41c250
41c250
diff --git a/tools/ds-identify b/tools/ds-identify
41c250
index c01eae3d..0e12298f 100755
41c250
--- a/tools/ds-identify
41c250
+++ b/tools/ds-identify
41c250
@@ -141,6 +141,7 @@ error() {
41c250
     debug 0 "$@"
41c250
     stderr "$@"
41c250
 }
41c250
+
41c250
 warn() {
41c250
     set -- "WARN:" "$@"
41c250
     debug 0 "$@"
41c250
@@ -344,7 +345,6 @@ geom_label_status_as() {
41c250
     return $ret
41c250
 }
41c250
 
41c250
-
41c250
 read_fs_info_freebsd() {
41c250
     local oifs="$IFS" line="" delim=","
41c250
     local ret=0 labels="" dev="" label="" ftype="" isodevs=""
41c250
@@ -404,7 +404,6 @@ cached() {
41c250
     [ -n "$1" ] && _RET="$1" && return || return 1
41c250
 }
41c250
 
41c250
-
41c250
 detect_virt() {
41c250
     local virt="${UNAVAILABLE}" r="" out=""
41c250
     if [ -d /run/systemd ]; then
41c250
@@ -450,7 +449,7 @@ detect_virt() {
41c250
 read_virt() {
41c250
     cached "$DI_VIRT" && return 0
41c250
     detect_virt
41c250
-    DI_VIRT=${_RET}
41c250
+    DI_VIRT="$(echo "${_RET}" | tr '[:upper:]' '[:lower:]')"
41c250
 }
41c250
 
41c250
 is_container() {
41c250
@@ -1370,16 +1369,20 @@ vmware_has_rpctool() {
41c250
     command -v vmware-rpctool >/dev/null 2>&1
41c250
 }
41c250
 
41c250
+vmware_rpctool_guestinfo() {
41c250
+    vmware-rpctool "info-get guestinfo.${1}" 2>/dev/null | grep "[[:alnum:]]"
41c250
+}
41c250
+
41c250
 vmware_rpctool_guestinfo_metadata() {
41c250
-    vmware-rpctool "info-get guestinfo.metadata"
41c250
+    vmware_rpctool_guestinfo "metadata"
41c250
 }
41c250
 
41c250
 vmware_rpctool_guestinfo_userdata() {
41c250
-    vmware-rpctool "info-get guestinfo.userdata"
41c250
+    vmware_rpctool_guestinfo "userdata"
41c250
 }
41c250
 
41c250
 vmware_rpctool_guestinfo_vendordata() {
41c250
-    vmware-rpctool "info-get guestinfo.vendordata"
41c250
+    vmware_rpctool_guestinfo "vendordata"
41c250
 }
41c250
 
41c250
 dscheck_VMware() {
41c250
-- 
41c250
2.27.0
41c250