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