4a46eb
From ad54d6d1c78d007c1ee35fe421d946a6def5ee18 Mon Sep 17 00:00:00 2001
4a46eb
From: Eduardo Otubo <otubo@redhat.com>
4a46eb
Date: Fri, 10 Jul 2020 09:44:34 -0400
4a46eb
Subject: [PATCH 1/3] When tools.conf does not exist, running cmd
4a46eb
 "vmware-toolbox-cmd config get deployPkg enable-custom-scripts", the return
4a46eb
 code will be EX_UNAVAILABLE(69), on this condition, it should not take it as
4a46eb
 error. (#413)
4a46eb
4a46eb
RH-Author: Eduardo Otubo <otubo@redhat.com>
4a46eb
Message-id: <20200710094434.9711-1-otubo@redhat.com>
4a46eb
Patchwork-id: 97934
4a46eb
O-Subject: [RHEL-7.9.z/RHEL-8.2.1/RHEL-8.3.0 cloud-init PATCH] When tools.conf does not exist, running cmd "vmware-toolbox-cmd config get deployPkg enable-custom-scripts", the return code will be EX_UNAVAILABLE(69), on this condition, it should not take it as error. (#413)
4a46eb
Bugzilla: 1839619
4a46eb
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4a46eb
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
4a46eb
4a46eb
From: chengcheng-chcheng <63850735+chengcheng-chcheng@users.noreply.github.com>
4a46eb
4a46eb
The diff seems slightly different from upstream because of some parts
4a46eb
being in different positions. But the final result is the file patched
4a46eb
guestcust_util.py (within this block) exactly identical to the one
4a46eb
upstream.
4a46eb
4a46eb
Also: Sorry for the commit message being just a Subject and this being
4a46eb
enormous. I kept the original from upstream.
4a46eb
4a46eb
commit c6d09af67626c2f2241c64c10c9e27e8752ba87b
4a46eb
Author: chengcheng-chcheng <63850735+chengcheng-chcheng@users.noreply.github.com>
4a46eb
Date:   Wed Jun 10 00:20:47 2020 +0800
4a46eb
4a46eb
    When tools.conf does not exist, running cmd "vmware-toolbox-cmd config get deployPkg enable-custom-scripts", the return code will be EX_UNAVAILABLE(69), on this condition, it should not take it as error. (#413)
4a46eb
4a46eb
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
4a46eb
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
4a46eb
---
4a46eb
 .../helpers/vmware/imc/guestcust_util.py      | 33 +++++++++++--------
4a46eb
 1 file changed, 20 insertions(+), 13 deletions(-)
4a46eb
4a46eb
diff --git a/cloudinit/sources/helpers/vmware/imc/guestcust_util.py b/cloudinit/sources/helpers/vmware/imc/guestcust_util.py
4a46eb
index 3d369d04..a270d9fb 100644
4a46eb
--- a/cloudinit/sources/helpers/vmware/imc/guestcust_util.py
4a46eb
+++ b/cloudinit/sources/helpers/vmware/imc/guestcust_util.py
4a46eb
@@ -133,23 +133,30 @@ def get_tools_config(section, key, defaultVal):
4a46eb
             'vmware-toolbox-cmd not installed, returning default value')
4a46eb
         return defaultVal
4a46eb
 
4a46eb
-    retValue = defaultVal
4a46eb
     cmd = ['vmware-toolbox-cmd', 'config', 'get', section, key]
4a46eb
 
4a46eb
     try:
4a46eb
-        (outText, _) = util.subp(cmd)
4a46eb
-        m = re.match(r'([^=]+)=(.*)', outText)
4a46eb
-        if m:
4a46eb
-            retValue = m.group(2).strip()
4a46eb
-            logger.debug("Get tools config: [%s] %s = %s",
4a46eb
-                         section, key, retValue)
4a46eb
-        else:
4a46eb
+        (outText, _) = subp.subp(cmd)
4a46eb
+    except subp.ProcessExecutionError as e:
4a46eb
+        if e.exit_code == 69:
4a46eb
             logger.debug(
4a46eb
-                "Tools config: [%s] %s is not found, return default value: %s",
4a46eb
-                section, key, retValue)
4a46eb
-    except util.ProcessExecutionError as e:
4a46eb
-        logger.error("Failed running %s[%s]", cmd, e.exit_code)
4a46eb
-        logger.exception(e)
4a46eb
+                "vmware-toolbox-cmd returned 69 (unavailable) for cmd: %s."
4a46eb
+                " Return default value: %s", " ".join(cmd), defaultVal)
4a46eb
+        else:
4a46eb
+            logger.error("Failed running %s[%s]", cmd, e.exit_code)
4a46eb
+            logger.exception(e)
4a46eb
+        return defaultVal
4a46eb
+
4a46eb
+    retValue = defaultVal
4a46eb
+    m = re.match(r'([^=]+)=(.*)', outText)
4a46eb
+    if m:
4a46eb
+        retValue = m.group(2).strip()
4a46eb
+        logger.debug("Get tools config: [%s] %s = %s",
4a46eb
+                     section, key, retValue)
4a46eb
+    else:
4a46eb
+        logger.debug(
4a46eb
+            "Tools config: [%s] %s is not found, return default value: %s",
4a46eb
+            section, key, retValue)
4a46eb
 
4a46eb
     return retValue
4a46eb
 
4a46eb
-- 
4a46eb
2.18.2
4a46eb