Skip to content

Commit

Permalink
Change sp run to call and add \n
Browse files Browse the repository at this point in the history
Signed-off-by: maipbui <maibui@microsoft.com>
  • Loading branch information
maipbui committed Sep 21, 2022
1 parent f1365f5 commit 96bc208
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions device/celestica/x86_64-cel_e1031-r0/sonic_platform/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ def _get_class(self, config):

def get_reg(self, path, reg_addr):
with open(path, 'w') as file:
file.write(reg_addr)
file.write(reg_addr + '\n')
with open(path, 'r') as file:
output = file.readline().strip()
return output

def set_reg(self, path, reg_addr, value):
with open(path, 'w') as file:
file.write("{0} {1}".format(reg_addr, value))
file.write("{0} {1}\n".format(reg_addr, value))
return None

def read_txt_file(self, path):
Expand Down Expand Up @@ -185,7 +185,7 @@ def write_txt_file(self, file_path, value):
return True

def is_host(self):
return subprocess.run(self.HOST_CHK_CMD, stdout=None, stderr=None).returncode == 0
return subprocess.call(self.HOST_CHK_CMD) == 0

def load_json_file(self, path):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __get_bios_version(self):
def get_register_value(self, register):
# Retrieves the cpld register value
with open(GETREG_PATH, 'w') as file:
file.write(register)
file.write(register + '\n')
with open(GETREG_PATH, 'r') as file:
raw_data = file.readline()
return raw_data.strip()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __get_bios_version(self):
def get_register_value(self, register):
# Retrieves the cpld register value
with open(GETREG_PATH, 'w') as file:
file.write(register)
file.write(register + '\n')
with open(GETREG_PATH, 'r') as file:
raw_data = file.readline()
return raw_data.strip()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self):
(self.platform, self.hwsku) = device_info.get_platform_and_hwsku()

def is_host(self):
return subprocess.run(HOST_CHK_CMD, stdout=None, stderr=None).returncode == 0
return subprocess.call(HOST_CHK_CMD) == 0

def pci_get_value(self, resource, offset):
status = True
Expand Down Expand Up @@ -71,7 +71,7 @@ def write_txt_file(self, file_path, value):

def get_cpld_reg_value(self, getreg_path, register):
with open(getreg_path, 'w') as file:
file.write(register)
file.write(register + '\n')
with open(getreg_path, 'r') as file:
result = file.readline()
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self):
pass

def is_host(self):
return subprocess.run(HOST_CHK_CMD, stdout=None, stderr=None).returncode == 0
return subprocess.call(HOST_CHK_CMD) == 0

def pci_get_value(self, resource, offset):
status = True
Expand All @@ -40,8 +40,8 @@ def run_command(self, cmd1_args, cmd2_args):

def run_interactive_command(self, cmd):
try:
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError:
subprocess.call(cmd)
except:
return False
return True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def __convert_string_to_num(self, value_str):
return 'N/A'

def __is_host(self):
return subprocess.run(self.HOST_CHK_CMD, stdout=None, stderr=None).returncode == 0
return subprocess.call(self.HOST_CHK_CMD) == 0

def __get_path_to_port_config_file(self):
platform_path = "/".join([self.PLATFORM_ROOT_PATH, self.PLATFORM])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ def _get_class(self, config):
return class_

def get_reg(self, path, reg_addr):
cmd = "echo {1} > {0}; cat {0}".format(path, reg_addr)
status, output = self._run_command(cmd)
return output if status else None
with open(path, 'w') as file:
file.write(reg_addr + '\n')
with open(path, 'r') as file:
output = file.readline().strip()
return output

def read_txt_file(self, path):
with open(path, 'r') as f:
Expand All @@ -167,7 +169,7 @@ def write_txt_file(self, file_path, value):
return True

def is_host(self):
return subprocess.run(self.HOST_CHK_CMD).returncode == 0
return subprocess.call(self.HOST_CHK_CMD) == 0

def load_json_file(self, path):
"""
Expand Down

0 comments on commit 96bc208

Please sign in to comment.