Skip to content

[device/wistron] Replace os.system and remove subprocess with shell=True #12102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#############################################################################
try:
import sys
import os
import time
import subprocess
from sonic_platform_base.chassis_base import ChassisBase
Expand All @@ -23,9 +22,9 @@
PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/"
REBOOT_CAUSE_FILE = "reboot-cause.txt"
PREV_REBOOT_CAUSE_FILE = "previous-reboot-cause.txt"
HOST_CHK_CMD = "docker > /dev/null 2>&1"
GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku"
GET_PLATFORM_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.platform"
HOST_CHK_CMD = ["docker"]
GET_HWSKU_CMD = ["sonic-cfggen", "-d", "-v", "DEVICE_METADATA.localhost.hwsku"]
GET_PLATFORM_CMD = ["sonic-cfggen", "-d", "-v", "DEVICE_METADATA.localhost.platform"]

class Chassis(ChassisBase):
"""Platform-specific Chassis class"""
Expand Down Expand Up @@ -76,7 +75,7 @@ def __initialize_eeprom(self):
self._eeprom = Tlv()

def __is_host(self):
return os.system(HOST_CHK_CMD) == 0
return subprocess.run(HOST_CHK_CMD).returncode == 0

def __read_txt_file(self, file_path):
try:
Expand Down Expand Up @@ -141,12 +140,12 @@ def get_reboot_cause(self):
return (reboot_cause, description)

def _get_sku_name(self):
p = subprocess.Popen(GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE)
p = subprocess.Popen(GET_HWSKU_CMD, stdout=subprocess.PIPE)
out, err = p.communicate()
return out.decode().rstrip('\n')

def _get_platform_name(self):
p = subprocess.Popen(GET_PLATFORM_CMD, shell=True, stdout=subprocess.PIPE)
p = subprocess.Popen(GET_PLATFORM_CMD, stdout=subprocess.PIPE)
out, err = p.communicate()
return out.decode().rstrip('\n')

Expand Down Expand Up @@ -206,7 +205,7 @@ def get_change_event(self, timeout=0):
port_dict[port] = '0'

self._transceiver_presence = cur_presence
if change_event == True:
if change_event is True:
break

if not forever:
Expand Down