From 3740f1efb7be8be325e93f37834adf7cc61e169f Mon Sep 17 00:00:00 2001 From: roger530-ho <109951240+roger530-ho@users.noreply.github.com> Date: Wed, 21 Dec 2022 05:13:42 +0800 Subject: [PATCH] [Edgecore][device/accton] Fix subprocess.call issue in is_host(). (#13111) Signed-off-by: roger530-ho --- .../x86_64-accton_as4630_54pe-r0/sonic_platform/helper.py | 8 ++++++-- .../x86_64-accton_as4630_54te-r0/sonic_platform/helper.py | 8 ++++++-- .../x86_64-accton_as5835_54x-r0/sonic_platform/helper.py | 8 ++++++-- .../x86_64-accton_as7312_54x-r0/sonic_platform/helper.py | 8 ++++++-- .../x86_64-accton_as7816_64x-r0/sonic_platform/helper.py | 8 ++++++-- .../x86_64-accton_as9726_32d-r0/sonic_platform/helper.py | 8 ++++++-- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/device/accton/x86_64-accton_as4630_54pe-r0/sonic_platform/helper.py b/device/accton/x86_64-accton_as4630_54pe-r0/sonic_platform/helper.py index b19fab85de..fdbd0f46a0 100644 --- a/device/accton/x86_64-accton_as4630_54pe-r0/sonic_platform/helper.py +++ b/device/accton/x86_64-accton_as4630_54pe-r0/sonic_platform/helper.py @@ -1,8 +1,8 @@ import os import struct -import subprocess from mmap import * from sonic_py_common import device_info +from sonic_py_common.general import getstatusoutput_noshell HOST_CHK_CMD = ["docker"] EMPTY_STRING = "" @@ -14,7 +14,11 @@ class APIHelper(): (self.platform, self.hwsku) = device_info.get_platform_and_hwsku() def is_host(self): - return subprocess.call(HOST_CHK_CMD) == 0 + try: + status, output = getstatusoutput_noshell(HOST_CHK_CMD) + return status == 0 + except Exception: + return False def pci_get_value(self, resource, offset): status = True diff --git a/device/accton/x86_64-accton_as4630_54te-r0/sonic_platform/helper.py b/device/accton/x86_64-accton_as4630_54te-r0/sonic_platform/helper.py index b19fab85de..fdbd0f46a0 100644 --- a/device/accton/x86_64-accton_as4630_54te-r0/sonic_platform/helper.py +++ b/device/accton/x86_64-accton_as4630_54te-r0/sonic_platform/helper.py @@ -1,8 +1,8 @@ import os import struct -import subprocess from mmap import * from sonic_py_common import device_info +from sonic_py_common.general import getstatusoutput_noshell HOST_CHK_CMD = ["docker"] EMPTY_STRING = "" @@ -14,7 +14,11 @@ class APIHelper(): (self.platform, self.hwsku) = device_info.get_platform_and_hwsku() def is_host(self): - return subprocess.call(HOST_CHK_CMD) == 0 + try: + status, output = getstatusoutput_noshell(HOST_CHK_CMD) + return status == 0 + except Exception: + return False def pci_get_value(self, resource, offset): status = True diff --git a/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/helper.py b/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/helper.py index b19fab85de..fdbd0f46a0 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/helper.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/helper.py @@ -1,8 +1,8 @@ import os import struct -import subprocess from mmap import * from sonic_py_common import device_info +from sonic_py_common.general import getstatusoutput_noshell HOST_CHK_CMD = ["docker"] EMPTY_STRING = "" @@ -14,7 +14,11 @@ class APIHelper(): (self.platform, self.hwsku) = device_info.get_platform_and_hwsku() def is_host(self): - return subprocess.call(HOST_CHK_CMD) == 0 + try: + status, output = getstatusoutput_noshell(HOST_CHK_CMD) + return status == 0 + except Exception: + return False def pci_get_value(self, resource, offset): status = True diff --git a/device/accton/x86_64-accton_as7312_54x-r0/sonic_platform/helper.py b/device/accton/x86_64-accton_as7312_54x-r0/sonic_platform/helper.py index 2c644ecbfb..ea73a06253 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/sonic_platform/helper.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/sonic_platform/helper.py @@ -1,8 +1,8 @@ import os import struct -import subprocess from mmap import * from sonic_py_common import device_info +from sonic_py_common.general import getstatusoutput_noshell HOST_CHK_CMD = ["docker"] EMPTY_STRING = "" @@ -14,7 +14,11 @@ class APIHelper(): (self.platform, self.hwsku) = device_info.get_platform_and_hwsku() def is_host(self): - return subprocess.call(HOST_CHK_CMD) == 0 + try: + status, output = getstatusoutput_noshell(HOST_CHK_CMD) + return status == 0 + except Exception: + return False def pci_get_value(self, resource, offset): status = True diff --git a/device/accton/x86_64-accton_as7816_64x-r0/sonic_platform/helper.py b/device/accton/x86_64-accton_as7816_64x-r0/sonic_platform/helper.py index b19fab85de..fdbd0f46a0 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/sonic_platform/helper.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/sonic_platform/helper.py @@ -1,8 +1,8 @@ import os import struct -import subprocess from mmap import * from sonic_py_common import device_info +from sonic_py_common.general import getstatusoutput_noshell HOST_CHK_CMD = ["docker"] EMPTY_STRING = "" @@ -14,7 +14,11 @@ class APIHelper(): (self.platform, self.hwsku) = device_info.get_platform_and_hwsku() def is_host(self): - return subprocess.call(HOST_CHK_CMD) == 0 + try: + status, output = getstatusoutput_noshell(HOST_CHK_CMD) + return status == 0 + except Exception: + return False def pci_get_value(self, resource, offset): status = True diff --git a/device/accton/x86_64-accton_as9726_32d-r0/sonic_platform/helper.py b/device/accton/x86_64-accton_as9726_32d-r0/sonic_platform/helper.py index 2c644ecbfb..ea73a06253 100644 --- a/device/accton/x86_64-accton_as9726_32d-r0/sonic_platform/helper.py +++ b/device/accton/x86_64-accton_as9726_32d-r0/sonic_platform/helper.py @@ -1,8 +1,8 @@ import os import struct -import subprocess from mmap import * from sonic_py_common import device_info +from sonic_py_common.general import getstatusoutput_noshell HOST_CHK_CMD = ["docker"] EMPTY_STRING = "" @@ -14,7 +14,11 @@ class APIHelper(): (self.platform, self.hwsku) = device_info.get_platform_and_hwsku() def is_host(self): - return subprocess.call(HOST_CHK_CMD) == 0 + try: + status, output = getstatusoutput_noshell(HOST_CHK_CMD) + return status == 0 + except Exception: + return False def pci_get_value(self, resource, offset): status = True