Blob Blame History Raw
From 51ff3dc6705217f52e4b4810fa9b6eac406ca84e Mon Sep 17 00:00:00 2001
From: Vitaly Kuznetsov <vkuznets@redhat.com>
Date: Thu, 17 Dec 2020 06:50:11 +0100
Subject: [PATCH] Fixed faulty check for run_command (#2093)

RH-Author: Vitaly Kuznetsov <vkuznets@redhat.com>
Message-id: <20201209101549.2667108-1-vkuznets@redhat.com>
Patchwork-id: 100366
O-Subject: [RHEL8 WALinuxAgent PATCH] Fixed faulty check for run_command (#2093)
Bugzilla: 1903074
RH-Acked-by: Cathy Avery <cavery@redhat.com>
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1903074
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=33563215
Tested: by QE
Branch: rhel840/master-2.2.49

commit b1799aef33f1213ef8828d5ba1838582026d5030
Author: Laveesh Rohra <larohra@microsoft.com>
Date:   Tue Dec 1 16:13:03 2020 -0800

    Fixed faulty check for run_command (#2093)

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 azurelinuxagent/common/osutil/redhat.py | 5 ++++-
 azurelinuxagent/common/osutil/suse.py   | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py
index 8974ecc..1b3ae0e 100644
--- a/azurelinuxagent/common/osutil/redhat.py
+++ b/azurelinuxagent/common/osutil/redhat.py
@@ -106,7 +106,10 @@ class RedhatOSUtil(Redhat6xOSUtil):
         to hostname.
         """
         hostnamectl_cmd = ['hostnamectl', 'set-hostname', hostname, '--static']
-        if self._run_command_without_raising(hostnamectl_cmd, log_error=False) != 0:
+
+        try:
+            shellutil.run_command(hostnamectl_cmd, log_error=False)
+        except shellutil.CommandError:
             logger.warn("[{0}] failed, attempting fallback".format(' '.join(hostnamectl_cmd)))
             DefaultOSUtil.set_hostname(self, hostname)
 
diff --git a/azurelinuxagent/common/osutil/suse.py b/azurelinuxagent/common/osutil/suse.py
index 2192c67..0b5fc8d 100644
--- a/azurelinuxagent/common/osutil/suse.py
+++ b/azurelinuxagent/common/osutil/suse.py
@@ -80,7 +80,7 @@ class SUSEOSUtil(SUSE11OSUtil):
         self._run_command_without_raising(["systemctl", "start", "{}.service".format(self.dhclient_name)],
                                           log_error=False)
 
-    def start_network(self) :
+    def start_network(self):
         self._run_command_without_raising(["systemctl", "start", "network.service"], log_error=False)
 
     def restart_ssh_service(self):
-- 
2.18.4