sailesh1993 / rpms / cloud-init

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