Skip to content

Commit

Permalink
Pass 'universal_newlines=True' arg to all relevant subprocess functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jleveque committed Nov 25, 2020
1 parent c313fa6 commit 3fab9f4
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __run_command(self, command):
# Run bash command and print output to stdout
try:
process = subprocess.Popen(
shlex.split(command), stdout=subprocess.PIPE)
shlex.split(command), universal_newlines=True, stdout=subprocess.PIPE)
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def reset(self, port_num):
return False

mod_rst_cmd = "ipmitool raw 0x34 0x11 " + str(port_num+1) + " 0x11 0x1"
subprocess.check_output(mod_rst_cmd)
subprocess.check_output(mod_rst_cmd, universal_newlines=True)
return True

def get_transceiver_change_event(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __run_command(self, command):
# Run bash command and print output to stdout
try:
process = subprocess.Popen(
shlex.split(command), stdout=subprocess.PIPE)
shlex.split(command), universal_newlines=True, stdout=subprocess.PIPE)
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
Expand All @@ -66,7 +66,7 @@ def get_register_value(self, register):
# Retrieves the cpld register value
cmd = "echo {1} > {0}; cat {0}".format(GETREG_PATH, register)
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err is not '':
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_register_value(self, register):
# Retrieves the cpld register value
cmd = "echo {1} > {0}; cat {0}".format(GETREG_PATH, register)
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err is not '':
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def run_command(self, cmd):
result = ""
try:
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
result = raw_data.strip()
Expand Down Expand Up @@ -87,7 +87,7 @@ def ipmi_raw(self, netfn, cmd):
try:
cmd = "ipmitool raw {} {}".format(str(netfn), str(cmd))
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
result = raw_data.strip()
Expand All @@ -105,7 +105,7 @@ def ipmi_fru_id(self, id, key=None):
id)) if not key else "ipmitool fru print {0} | grep '{1}' ".format(str(id), str(key))

p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
result = raw_data.strip()
Expand All @@ -122,7 +122,7 @@ def ipmi_set_ss_thres(self, id, threshold_key, value):
cmd = "ipmitool sensor thresh '{}' {} {}".format(
str(id), str(threshold_key), str(value))
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
result = raw_data.strip()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):
PsuBase.__init__(self)

def run_command(self, command):
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
proc = subprocess.Popen(command, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
(out, err) = proc.communicate()

if proc.returncode != 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
PsuBase.__init__(self)

def run_command(self, command):
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
proc = subprocess.Popen(command, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
(out, err) = proc.communicate()

if proc.returncode != 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def run_command(self, cmd):
result = ""
try:
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
result = raw_data.strip()
Expand Down Expand Up @@ -63,7 +63,7 @@ def ipmi_raw(self, netfn, cmd):
try:
cmd = "ipmitool raw {} {}".format(str(netfn), str(cmd))
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
result = raw_data.strip()
Expand All @@ -81,7 +81,7 @@ def ipmi_fru_id(self, id, key=None):
id)) if not key else "ipmitool fru print {0} | grep '{1}' ".format(str(id), str(key))

p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
result = raw_data.strip()
Expand All @@ -97,7 +97,7 @@ def ipmi_set_ss_thres(self, id, threshold_key, value):
try:
cmd = "ipmitool sensor thresh '{}' {} {}".format(str(id), str(threshold_key), str(value))
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
result = raw_data.strip()
Expand Down
2 changes: 1 addition & 1 deletion device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self):
self.num_of_fan, self.num_of_drawer = self._extract_num_of_fans_and_fan_drawers()

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

Expand Down
2 changes: 1 addition & 1 deletion device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self):
self.fan_speed = "thermal/psu{}_fan1_speed_get"

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

Expand Down
12 changes: 6 additions & 6 deletions device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def port_to_eeprom_mapping(self):
raise Exception()

def get_port_position_tuple_by_platform_name(self):
p = subprocess.Popen(GET_PLATFORM_CMD, shell=True, stdout=subprocess.PIPE)
p = subprocess.Popen(GET_PLATFORM_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
out, err = p.communicate()
position_tuple = port_position_tuple_list[platform_dict[out.rstrip('\n')]]
return position_tuple
Expand Down Expand Up @@ -120,7 +120,7 @@ def get_presence(self, port_num):

ethtool_cmd = "ethtool -m {} 2>/dev/null".format(sfpname)
try:
proc = subprocess.Popen(ethtool_cmd, stdout=subprocess.PIPE, shell=True, stderr=subprocess.STDOUT)
proc = subprocess.Popen(ethtool_cmd, stdout=subprocess.PIPE, shell=True, universal_newlines=True, stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
result = stdout.rstrip('\n')
Expand All @@ -140,7 +140,7 @@ def get_low_power_mode(self, port_num):
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmget.py {}".format(port_num)

try:
output = subprocess.check_output(lpm_cmd, shell=True)
output = subprocess.check_output(lpm_cmd, shell=True, universal_newlines=True)
if 'LPM ON' in output:
return True
except subprocess.CalledProcessError as e:
Expand All @@ -164,7 +164,7 @@ def set_low_power_mode(self, port_num, lpmode):

# Set LPM
try:
subprocess.check_output(lpm_cmd, shell=True)
subprocess.check_output(lpm_cmd, shell=True, universal_newlines=True)
except subprocess.CalledProcessError as e:
print("Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output))
return False
Expand All @@ -179,7 +179,7 @@ def reset(self, port_num):
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfpreset.py {}".format(port_num)

try:
subprocess.check_output(lpm_cmd, shell=True)
subprocess.check_output(lpm_cmd, shell=True, universal_newlines=True)
return True
except subprocess.CalledProcessError as e:
print("Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output))
Expand Down Expand Up @@ -252,7 +252,7 @@ def _read_eeprom_specific_bytes_via_ethtool(self, port_num, offset, num_bytes):
eeprom_raw = []
ethtool_cmd = "ethtool -m {} hex on offset {} length {}".format(sfpname, offset, num_bytes)
try:
output = subprocess.check_output(ethtool_cmd, shell=True)
output = subprocess.check_output(ethtool_cmd, shell=True, universal_newlines=True)
output_lines = output.splitlines()
first_line_raw = output_lines[0]
if "Offset" in first_line_raw:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class ThermalUtil(ThermalBase):
thermal_list = []

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

Expand Down
4 changes: 2 additions & 2 deletions device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def show_log(txt):
def exec_cmd(cmd, show):
logging.info('Run :'+cmd)
try:
output = subprocess.check_output(cmd, shell=True)
output = subprocess.check_output(cmd, shell=True, universal_newlines=True)
show_log(cmd + "output:"+str(output))
except subprocess.CalledProcessError as e:
logging.info("Failed :"+cmd)
Expand All @@ -45,7 +45,7 @@ def log_os_system(cmd, show):
status = 1
output = ""
try:
output = subprocess.check_output(cmd, shell=True)
output = subprocess.check_output(cmd, shell=True, universal_newlines=True)
my_log(cmd + "output:"+str(output))
except subprocess.CalledProcessError as e:
logging.info('Failed :'+cmd)
Expand Down

0 comments on commit 3fab9f4

Please sign in to comment.