[device/dell] Mitigation for security vulnerability (#11875)
Dependency: [PR (#12065)](https://github.com/sonic-net/sonic-buildimage/pull/12065) needs to merge first. #### Why I did it `commands` module is not protected against malicious input `getstatusoutput` is detected without a static string, uses `shell=True` #### How I did it Eliminate the use of `commands` Use `subprocess.run()`, commands in `subprorcess.run()` are totally static Fix indentation #### How to verify it Tested on DUT [dell_log.txt](https://github.com/sonic-net/sonic-buildimage/files/9561332/dell_log.txt)
This commit is contained in:
parent
ba5c26a16f
commit
06e1a0bc14
@ -3,10 +3,10 @@
|
||||
# Platform-specific FAN status interface for SONiC
|
||||
#
|
||||
|
||||
import commands
|
||||
import sys
|
||||
from sonic_py_common.general import getstatusoutput_noshell
|
||||
|
||||
SENSORS_CMD = "docker exec -i pmon /usr/bin/sensors"
|
||||
SENSORS_CMD = ["docker", "exec", "-i", "pmon", "/usr/bin/sensors"]
|
||||
DOCKER_SENSORS_CMD = "/usr/bin/sensors"
|
||||
|
||||
|
||||
@ -33,24 +33,23 @@ class FanUtil(FanBase):
|
||||
return True
|
||||
|
||||
def get_num_fans(self):
|
||||
n3248pxe_MAX_FANTRAYS = 3
|
||||
return n3248pxe_MAX_FANTRAYS
|
||||
n3248pxe_MAX_FANTRAYS = 3
|
||||
return n3248pxe_MAX_FANTRAYS
|
||||
|
||||
def get_presence(self, idx):
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
|
||||
return int(open(sysfs_path).read(), 16)
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
|
||||
return int(open(sysfs_path).read(), 16)
|
||||
|
||||
def get_direction(self, idx):
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_dir"
|
||||
return open(sysfs_path).read()
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_dir"
|
||||
return open(sysfs_path).read()
|
||||
|
||||
def get_speed(self, idx):
|
||||
dockerenv = self.isDockerEnv()
|
||||
if not dockerenv:
|
||||
status, cmd_output = commands.getstatusoutput(SENSORS_CMD)
|
||||
else :
|
||||
status, cmd_output = commands.getstatusoutput(DOCKER_SENSORS_CMD)
|
||||
|
||||
status, cmd_output = getstatusoutput_noshell(SENSORS_CMD)
|
||||
else:
|
||||
status, cmd_output = getstatusoutput_noshell(DOCKER_SENSORS_CMD)
|
||||
if status:
|
||||
print('Failed to execute sensors command')
|
||||
sys.exit(0)
|
||||
@ -64,9 +63,9 @@ class FanUtil(FanBase):
|
||||
return 0.0
|
||||
|
||||
def get_status(self, idx):
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
|
||||
return int(open(sysfs_path).read(), 16)
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
|
||||
return int(open(sysfs_path).read(), 16)
|
||||
|
||||
|
||||
def set_speed(self, idx):
|
||||
return False
|
||||
return False
|
||||
|
@ -3,11 +3,11 @@
|
||||
# Platform-specific PSU status interface for SONiC
|
||||
#
|
||||
|
||||
import commands
|
||||
import os
|
||||
import sys
|
||||
from sonic_py_common.general import getstatusoutput_noshell
|
||||
|
||||
SENSORS_CMD = "docker exec -i pmon /usr/bin/sensors"
|
||||
SENSORS_CMD = ["docker", "exec", "-i", "pmon", "/usr/bin/sensors"]
|
||||
DOCKER_SENSORS_CMD = "/usr/bin/sensors"
|
||||
|
||||
try:
|
||||
@ -95,10 +95,9 @@ class PsuUtil(PsuBase):
|
||||
def get_sensor(self):
|
||||
dockerenv = self.isDockerEnv()
|
||||
if not dockerenv:
|
||||
status, cmd_output = commands.getstatusoutput(SENSORS_CMD)
|
||||
else :
|
||||
status, cmd_output = commands.getstatusoutput(DOCKER_SENSORS_CMD)
|
||||
|
||||
status, cmd_output = getstatusoutput_noshell(SENSORS_CMD)
|
||||
else:
|
||||
status, cmd_output = getstatusoutput_noshell(DOCKER_SENSORS_CMD)
|
||||
if status:
|
||||
print('Failed to execute sensors command')
|
||||
sys.exit(0)
|
||||
|
@ -3,10 +3,10 @@
|
||||
# Platform-specific FAN status interface for SONiC
|
||||
#
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from sonic_py_common.general import getstatusoutput_noshell
|
||||
|
||||
SENSORS_CMD = "docker exec -i pmon /usr/bin/sensors"
|
||||
SENSORS_CMD = ["docker", "exec", "-i", "pmon", "/usr/bin/sensors"]
|
||||
DOCKER_SENSORS_CMD = "/usr/bin/sensors"
|
||||
|
||||
|
||||
@ -33,24 +33,23 @@ class FanUtil(FanBase):
|
||||
return True
|
||||
|
||||
def get_num_fans(self):
|
||||
N3248TE_MAX_FANTRAYS = 3
|
||||
return N3248TE_MAX_FANTRAYS
|
||||
N3248TE_MAX_FANTRAYS = 3
|
||||
return N3248TE_MAX_FANTRAYS
|
||||
|
||||
def get_presence(self, idx):
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
|
||||
return int(open(sysfs_path).read(), 16)
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
|
||||
return int(open(sysfs_path).read(), 16)
|
||||
|
||||
def get_direction(self, idx):
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_dir"
|
||||
return open(sysfs_path).read()
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_dir"
|
||||
return open(sysfs_path).read()
|
||||
|
||||
def get_speed(self, idx):
|
||||
dockerenv = self.isDockerEnv()
|
||||
if not dockerenv:
|
||||
status, cmd_output = subprocess.getstatusoutput(SENSORS_CMD)
|
||||
else :
|
||||
status, cmd_output = subprocess.getstatusoutput(DOCKER_SENSORS_CMD)
|
||||
|
||||
status, cmd_output = getstatusoutput_noshell(SENSORS_CMD)
|
||||
else:
|
||||
status, cmd_output = getstatusoutput_noshell(DOCKER_SENSORS_CMD)
|
||||
if status:
|
||||
print('Failed to execute sensors command')
|
||||
sys.exit(0)
|
||||
@ -64,9 +63,9 @@ class FanUtil(FanBase):
|
||||
return 0.0
|
||||
|
||||
def get_status(self, idx):
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
|
||||
return int(open(sysfs_path).read(), 16)
|
||||
sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
|
||||
return int(open(sysfs_path).read(), 16)
|
||||
|
||||
|
||||
def set_speed(self, idx):
|
||||
return False
|
||||
return False
|
||||
|
@ -3,11 +3,11 @@
|
||||
# Platform-specific PSU status interface for SONiC
|
||||
#
|
||||
|
||||
import commands
|
||||
import os
|
||||
import sys
|
||||
from sonic_py_common.general import getstatusoutput_noshell
|
||||
|
||||
SENSORS_CMD = "docker exec -i pmon /usr/bin/sensors"
|
||||
SENSORS_CMD = ["docker", "exec", "-i", "pmon", "/usr/bin/sensors"]
|
||||
DOCKER_SENSORS_CMD = "/usr/bin/sensors"
|
||||
|
||||
try:
|
||||
@ -95,10 +95,9 @@ class PsuUtil(PsuBase):
|
||||
def get_sensor(self):
|
||||
dockerenv = self.isDockerEnv()
|
||||
if not dockerenv:
|
||||
status, cmd_output = commands.getstatusoutput(SENSORS_CMD)
|
||||
else :
|
||||
status, cmd_output = commands.getstatusoutput(DOCKER_SENSORS_CMD)
|
||||
|
||||
status, cmd_output = getstatusoutput_noshell(SENSORS_CMD)
|
||||
else:
|
||||
status, cmd_output = getstatusoutput_noshell(DOCKER_SENSORS_CMD)
|
||||
if status:
|
||||
print('Failed to execute sensors command')
|
||||
sys.exit(0)
|
||||
|
@ -5,11 +5,11 @@
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import subprocess
|
||||
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
|
||||
|
||||
S5212F_MAX_PSUS = 2
|
||||
IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list"
|
||||
IPMI_PSU_DATA_DOCKER = "ipmitool sdr list"
|
||||
IPMI_PSU_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "sdr", "list"]
|
||||
IPMI_PSU_DATA_DOCKER = ["ipmitool", "sdr", "list"]
|
||||
PSU_PRESENCE = "PSU{0}_stat"
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
@ -44,7 +44,7 @@ class PsuUtil(PsuBase):
|
||||
if dockerenv == True:
|
||||
ipmi_cmd = IPMI_PSU_DATA_DOCKER
|
||||
|
||||
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute:' + ipmi_sdr_list)
|
||||
@ -91,6 +91,8 @@ class PsuUtil(PsuBase):
|
||||
:param index: An integer, index of the PSU of which to query status
|
||||
:return: Boolean, True if PSU is plugged, False if not
|
||||
"""
|
||||
cmd_status, psu_status = subprocess.getstatusoutput('ipmitool raw 0x04 0x2d ' + hex(0x30 + index) + " | awk '{print substr($0,9,1)}'")
|
||||
ipmi_cmd = ["ipmitool", "raw", "0x04", "0x2d", hex(0x30 + index)]
|
||||
awk_cmd = ['awk', '{print substr($0,9,1)}']
|
||||
cmd_status, psu_status = getstatusoutput_noshell_pipe(ipmi_cmd, awk_cmd)
|
||||
return 1 if psu_status == '1' else 0
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import subprocess
|
||||
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
|
||||
|
||||
S5224F_MAX_PSUS = 2
|
||||
IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list"
|
||||
@ -45,7 +45,7 @@ class PsuUtil(PsuBase):
|
||||
if dockerenv == True:
|
||||
ipmi_cmd = IPMI_PSU_DATA_DOCKER
|
||||
|
||||
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute:' + ipmi_sdr_list)
|
||||
@ -92,6 +92,8 @@ class PsuUtil(PsuBase):
|
||||
:param index: An integer, index of the PSU of which to query status
|
||||
:return: Boolean, True if PSU is plugged, False if not
|
||||
"""
|
||||
cmd_status, psu_status = subprocess.getstatusoutput('ipmitool raw 0x04 0x2d ' + hex(0x30 + index) + " | awk '{print substr($0,9,1)}'")
|
||||
ipmi_cmd = ["ipmitool", "raw", "0x04", "0x2d", hex(0x30 + index)]
|
||||
awk_cmd = ['awk', '{print substr($0,9,1)}']
|
||||
cmd_status, psu_status = getstatusoutput_noshell_pipe(ipmi_cmd, awk_cmd)
|
||||
return 1 if psu_status == '1' else 0
|
||||
|
||||
|
@ -4,22 +4,17 @@
|
||||
#
|
||||
|
||||
|
||||
import os.path
|
||||
import logging
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
import commands
|
||||
else:
|
||||
import subprocess as commands
|
||||
|
||||
from sonic_py_common.general import getstatusoutput_noshell_pipe
|
||||
|
||||
S5232F_MAX_PSUS = 2
|
||||
IPMI_PSU1_DATA = "docker exec -it pmon ipmitool raw 0x04 0x2d 0x31 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x31 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU2_DATA = "docker exec -it pmon ipmitool raw 0x04 0x2d 0x32 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU2_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x32 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU1_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "raw", "0x04", "0x2d", "0x31"]
|
||||
IPMI_PSU1_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x31"]
|
||||
IPMI_PSU2_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "raw", "0x04", "0x2d", "0x32"]
|
||||
IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x32"]
|
||||
PSU_PRESENCE = "PSU{0}_stat"
|
||||
awk_cmd = ['awk', '{print substr($0,9,1)}']
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
|
||||
@ -44,23 +39,24 @@ class PsuUtil(PsuBase):
|
||||
return False
|
||||
|
||||
# Fetch a BMC register
|
||||
def get_pmc_register(self, reg_name):
|
||||
def get_pmc_register(self, index):
|
||||
|
||||
status = 1
|
||||
ipmi_cmd_1 = IPMI_PSU1_DATA
|
||||
ipmi_cmd_2 = IPMI_PSU1_DATA
|
||||
ipmi_cmd = ''
|
||||
dockerenv = self.isDockerEnv()
|
||||
if dockerenv == True:
|
||||
if index == 1:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
ipmi_cmd = IPMI_PSU1_DATA_DOCKER
|
||||
elif index == 2:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ipmi_cmd = IPMI_PSU2_DATA_DOCKER
|
||||
else:
|
||||
if index == 1:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA)
|
||||
ipmi_cmd = IPMI_PSU1_DATA
|
||||
elif index == 2:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA)
|
||||
|
||||
ipmi_cmd = IPMI_PSU2_DATA
|
||||
if ipmi_cmd != '':
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell_pipe(ipmi_cmd, awk_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute ipmitool')
|
||||
sys.exit(0)
|
||||
@ -87,22 +83,25 @@ class PsuUtil(PsuBase):
|
||||
"""
|
||||
# Until psu_status is implemented this is hardcoded temporarily
|
||||
|
||||
psu_status = 'f'
|
||||
psu_status = ''
|
||||
ret_status = 1
|
||||
ipmi_cmd = ''
|
||||
dockerenv = self.isDockerEnv()
|
||||
if dockerenv == True:
|
||||
if index == 1:
|
||||
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
ipmi_cmd = IPMI_PSU1_DATA_DOCKER
|
||||
elif index == 2:
|
||||
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ipmi_cmd = IPMI_PSU2_DATA_DOCKER
|
||||
else:
|
||||
if index == 1:
|
||||
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA)
|
||||
ipmi_cmd = IPMI_PSU1_DATA
|
||||
elif index == 2:
|
||||
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA)
|
||||
ipmi_cmd = IPMI_PSU2_DATA
|
||||
if ipmi_cmd != '':
|
||||
ret_status, ipmi_sdr_list = getstatusoutput_noshell_pipe(ipmi_cmd, awk_cmd)
|
||||
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool : ')
|
||||
logging.error('Failed to execute ipmitool')
|
||||
sys.exit(0)
|
||||
|
||||
psu_status = ipmi_sdr_list
|
||||
@ -117,20 +116,23 @@ class PsuUtil(PsuBase):
|
||||
"""
|
||||
psu_status = '0'
|
||||
ret_status = 1
|
||||
ipmi_cmd = ''
|
||||
dockerenv = self.isDockerEnv()
|
||||
if dockerenv == True:
|
||||
if index == 1:
|
||||
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
ipmi_cmd = IPMI_PSU1_DATA_DOCKER
|
||||
elif index == 2:
|
||||
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ipmi_cmd = IPMI_PSU2_DATA_DOCKER
|
||||
else:
|
||||
if index == 1:
|
||||
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA)
|
||||
ipmi_cmd = IPMI_PSU1_DATA
|
||||
elif index == 2:
|
||||
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA)
|
||||
ipmi_cmd = IPMI_PSU2_DATA
|
||||
if ipmi_cmd != '':
|
||||
ret_status, ipmi_sdr_list = getstatusoutput_noshell_pipe(ipmi_cmd, awk_cmd)
|
||||
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool : ')
|
||||
logging.error('Failed to execute ipmitool')
|
||||
sys.exit(0)
|
||||
|
||||
psu_status = ipmi_sdr_list
|
||||
|
@ -4,19 +4,14 @@
|
||||
#
|
||||
|
||||
|
||||
import os.path
|
||||
import logging
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
import commands
|
||||
else:
|
||||
import subprocess as commands
|
||||
from sonic_py_common.general import getstatusoutput_noshell
|
||||
|
||||
|
||||
S5248F_MAX_PSUS = 2
|
||||
IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list"
|
||||
IPMI_PSU_DATA_DOCKER = "ipmitool sdr list"
|
||||
IPMI_PSU_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "sdr", "list"]
|
||||
IPMI_PSU_DATA_DOCKER = ["ipmitool", "sdr", "list"]
|
||||
PSU_PRESENCE = "PSU{0}_stat"
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
@ -53,7 +48,7 @@ class PsuUtil(PsuBase):
|
||||
if dockerenv == True:
|
||||
ipmi_cmd = IPMI_PSU_DATA_DOCKER
|
||||
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute:' + ipmi_sdr_list)
|
||||
|
@ -6,16 +6,12 @@
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
import commands
|
||||
else:
|
||||
import subprocess as commands
|
||||
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
|
||||
|
||||
|
||||
S5296F_MAX_PSUS = 2
|
||||
IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list"
|
||||
IPMI_PSU_DATA_DOCKER = "ipmitool sdr list"
|
||||
IPMI_PSU_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "sdr", "list"]
|
||||
IPMI_PSU_DATA_DOCKER = ["ipmitool", "sdr", "list"]
|
||||
PSU_PRESENCE = "PSU{0}_stat"
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
@ -50,7 +46,7 @@ class PsuUtil(PsuBase):
|
||||
if dockerenv == True:
|
||||
ipmi_cmd = IPMI_PSU_DATA_DOCKER
|
||||
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute:' + ipmi_sdr_list)
|
||||
@ -97,6 +93,7 @@ class PsuUtil(PsuBase):
|
||||
:param index: An integer, index of the PSU of which to query status
|
||||
:return: Boolean, True if PSU is plugged, False if not
|
||||
"""
|
||||
cmd_status, psu_status = commands.getstatusoutput(
|
||||
'ipmitool raw 0x04 0x2d ' + hex(0x30 + index) + " | awk '{print substr($0,9,1)}'")
|
||||
ipmi_cmd = ["ipmitool", "raw", "0x04", "0x2d", hex(0x30 + index)]
|
||||
awk_cmd = ["awk", "{print substr($0,9,1)}"]
|
||||
cmd_status, psu_status = getstatusoutput_noshell_pipe(ipmi_cmd, awk_cmd)
|
||||
return 1 if psu_status == '1' else 0
|
||||
|
@ -4,19 +4,14 @@
|
||||
#
|
||||
|
||||
|
||||
import os.path
|
||||
import logging
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
import commands
|
||||
else:
|
||||
import subprocess as commands
|
||||
from sonic_py_common.general import getstatusoutput_noshell
|
||||
|
||||
|
||||
Z9264F_MAX_PSUS = 2
|
||||
IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list"
|
||||
IPMI_PSU_DATA_DOCKER = "ipmitool sdr list"
|
||||
IPMI_PSU_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "sdr", "list"]
|
||||
IPMI_PSU_DATA_DOCKER = ["ipmitool", "sdr", "list"]
|
||||
PSU_PRESENCE = "PSU{0}_state"
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
@ -53,7 +48,7 @@ class PsuUtil(PsuBase):
|
||||
if dockerenv == True:
|
||||
ipmi_cmd = IPMI_PSU_DATA_DOCKER
|
||||
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute:' + ipmi_sdr_list)
|
||||
|
@ -4,25 +4,21 @@
|
||||
#
|
||||
|
||||
|
||||
import os.path
|
||||
import logging
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
import commands
|
||||
else:
|
||||
import subprocess as commands
|
||||
from sonic_py_common.general import getstatusoutput_noshell_pipe
|
||||
|
||||
|
||||
Z9332F_MAX_PSUS = 2
|
||||
IPMI_PSU1_DATA = "docker exec -it pmon ipmitool raw 0x04 0x2d 0x2f | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x2f | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU2_DATA = "docker exec -it pmon ipmitool raw 0x04 0x2d 0x39 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU2_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x39 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU1_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "raw", "0x04", "0x2d", "0x2f"]
|
||||
IPMI_PSU1_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x2f"]
|
||||
IPMI_PSU2_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "raw", "0x04", "0x2d", "0x39"]
|
||||
IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x39"]
|
||||
PSU_PRESENCE = "PSU{0}_Status"
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
ipmi_sdr_list = ""
|
||||
awk_cmd = ['awk', '{print substr($0,9,1)}']
|
||||
|
||||
|
||||
try:
|
||||
@ -46,28 +42,24 @@ class PsuUtil(PsuBase):
|
||||
|
||||
# Fetch a BMC register
|
||||
def get_pmc_register(self, reg_name):
|
||||
|
||||
status = 1
|
||||
global ipmi_sdr_list
|
||||
ipmi_dev_node = "/dev/pmi0"
|
||||
ipmi_cmd_1 = IPMI_PSU1_DATA
|
||||
ipmi_cmd_2 = IPMI_PSU1_DATA
|
||||
ipmi_cmd = ''
|
||||
dockerenv = self.isDockerEnv()
|
||||
if dockerenv == True:
|
||||
if index == 1:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
ipmi_cmd = IPMI_PSU1_DATA_DOCKER
|
||||
elif index == 2:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ipmi_cmd = IPMI_PSU2_DATA_DOCKER
|
||||
else:
|
||||
if index == 1:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA)
|
||||
ipmi_cmd = IPMI_PSU1_DATA
|
||||
elif index == 2:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute ipmitool')
|
||||
sys.exit(0)
|
||||
|
||||
ipmi_cmd = IPMI_PSU2_DATA
|
||||
if ipmi_cmd != '':
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell_pipe(ipmi_cmd, awk_cmd)
|
||||
if status:
|
||||
logging.error('Failed to execute ipmitool')
|
||||
sys.exit(0)
|
||||
output = ipmi_sdr_list
|
||||
|
||||
return output
|
||||
@ -100,22 +92,23 @@ class PsuUtil(PsuBase):
|
||||
:param index: An integer, index of the PSU of which to query status
|
||||
:return: Boolean, True if PSU is plugged, False if not
|
||||
"""
|
||||
ipmi_cmd = ''
|
||||
status = 0
|
||||
ret_status = 1
|
||||
# ret_status = 1
|
||||
global ipmi_sdr_list
|
||||
ipmi_dev_node = "/dev/pmi0"
|
||||
dockerenv = self.isDockerEnv()
|
||||
if dockerenv == True:
|
||||
if index == 1:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
ipmi_cmd = IPMI_PSU1_DATA_DOCKER
|
||||
elif index == 2:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ipmi_cmd = IPMI_PSU2_DATA_DOCKER
|
||||
else:
|
||||
if index == 1:
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA)
|
||||
ipmi_cmd = IPMI_PSU1_DATA
|
||||
elif index == 2:
|
||||
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA)
|
||||
|
||||
ipmi_cmd = IPMI_PSU2_DATA
|
||||
if ipmi_cmd != '':
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell_pipe(ipmi_cmd, awk_cmd)
|
||||
# if ret_status:
|
||||
# print ipmi_sdr_list
|
||||
# logging.error('Failed to execute ipmitool')
|
||||
|
@ -7,7 +7,7 @@
|
||||
#
|
||||
#############################################################################
|
||||
import logging
|
||||
import commands
|
||||
from sonic_py_common.general import getstatusoutput_noshell
|
||||
|
||||
try:
|
||||
from sonic_fan.fan_base import FanBase
|
||||
@ -20,10 +20,10 @@ class FanUtil(FanBase):
|
||||
NUM_FANS_PERTRAY = 2
|
||||
FANTRAY_NUM_START_IDX = 1
|
||||
FRU_FAN_START_IDX = 1
|
||||
IPMI_FAN_PRESENCE = "ipmitool sensor get FAN{0}_prsnt"
|
||||
IPMI_FAN_FRONT_SPEED = "ipmitool sdr get Fan{0}_Front_rpm"
|
||||
IPMI_FAN_REAR_SPEED = "ipmitool sdr get Fan{0}_Rear_rpm"
|
||||
IPMI_FRU_DATA = "ipmitool fru print {0}"
|
||||
IPMI_FAN_PRESENCE = ["ipmitool", "sensor", "get", ""]
|
||||
IPMI_FAN_FRONT_SPEED = ["ipmitool", "sdr", "get", ""]
|
||||
IPMI_FAN_REAR_SPEED = ["ipmitool", "sdr", "get", ""]
|
||||
IPMI_FRU_DATA = ["ipmitool", "fru", "print", ""]
|
||||
|
||||
def __init__(self, log_level=logging.DEBUG):
|
||||
FanBase.__init__(self)
|
||||
@ -31,59 +31,63 @@ class FanUtil(FanBase):
|
||||
|
||||
def get_fan_status(self,fan_id):
|
||||
try:
|
||||
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_FAN_PRESENCE.format(fan_id))
|
||||
if ret_status == 0:
|
||||
return(ipmi_cmd_ret.splitlines()[5].strip(' ').strip('[]'))
|
||||
self.IPMI_FAN_PRESENCE[3] = 'FAN' + str(fan_id) + '_prsnt'
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_FAN_PRESENCE)
|
||||
if ret_status == 0:
|
||||
return(ipmi_cmd_ret.splitlines()[5].strip(' ').strip('[]'))
|
||||
except Exception:
|
||||
logging.error('Failed to execute : %s'%self.IPMI_FAN_PRESENCE.format(fan_id))
|
||||
logging.error('Failed to execute : %s'%(' '.join(self.IPMI_FAN_PRESENCE)))
|
||||
|
||||
def get_front_fan_speed(self,fan_id):
|
||||
try:
|
||||
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_FAN_FRONT_SPEED.format(fan_id))
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
self.IPMI_FAN_FRONT_SPEED[3] = 'Fan' + str(fan_id) + '_Front_rpm'
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_FAN_FRONT_SPEED)
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
except Exception:
|
||||
logging.error('Failed to execute : %s'%self.IPMI_FAN_FRONT_SPEED.format(fan_id))
|
||||
logging.error('Failed to execute : %s'%(' '.join(self.IPMI_FAN_FRONT_SPEED)))
|
||||
|
||||
def get_rear_fan_speed(self,fan_id):
|
||||
try:
|
||||
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_FAN_REAR_SPEED.format(fan_id))
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
self.IPMI_FAN_REAR_SPEED[3] = 'Fan' + str(fan_id) + '_Rear_rpm'
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_FAN_REAR_SPEED)
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
|
||||
except Exception:
|
||||
logging.error('Failed to execute : %s'%self.IPMI_FAN_REAR_SPEED.format(fan_id))
|
||||
logging.error('Failed to execute : %s'%(' '.join(self.IPMI_FAN_REAR_SPEED)))
|
||||
|
||||
|
||||
# Read FAN FRU info
|
||||
def get_fan_direction_from_fru(self,fru_id,reg_name):
|
||||
output = None
|
||||
try:
|
||||
status, ipmi_fru_list = commands.getstatusoutput(self.IPMI_FRU_DATA.format(fru_id))
|
||||
if status == 0:
|
||||
for item in ipmi_fru_list.split("\n"):
|
||||
if reg_name in item:
|
||||
output = item.strip()
|
||||
if output is None:
|
||||
logging.error('\nFailed to fetch: ' + reg_name + ' sensor ')
|
||||
output = output.split(':')[1].strip(' ')
|
||||
if output == 'F2B' or output == 'B2F':
|
||||
return output
|
||||
self.IPMI_FRU_DATA[3] = str(fru_id)
|
||||
status, ipmi_fru_list = getstatusoutput_noshell(self.IPMI_FRU_DATA)
|
||||
if status == 0:
|
||||
for item in ipmi_fru_list.split("\n"):
|
||||
if reg_name in item:
|
||||
output = item.strip()
|
||||
if output is None:
|
||||
logging.error('\nFailed to fetch: ' + reg_name + ' sensor ')
|
||||
output = output.split(':')[1].strip(' ')
|
||||
if output == 'F2B' or output == 'B2F':
|
||||
return output
|
||||
except Exception:
|
||||
logging.error('Failed to execute:' + ipmi_fru_list)
|
||||
logging.error('Failed to execute:' + ipmi_fru_list)
|
||||
|
||||
def get_num_fans(self):
|
||||
return self.num_fans
|
||||
|
||||
def get_presence(self, index):
|
||||
if index is None:
|
||||
return False
|
||||
return False
|
||||
|
||||
if index < self.FANTRAY_NUM_START_IDX or index > self.FANTRAY_NUM_START_IDX + self.num_fans - 1:
|
||||
logging.error('Invalid FAN index:%d', index)
|
||||
return False
|
||||
logging.error('Invalid FAN index:%d', index)
|
||||
return False
|
||||
|
||||
tray_index = ((index-1)/self.NUM_FANS_PERTRAY) + 1
|
||||
|
||||
@ -94,11 +98,11 @@ class FanUtil(FanBase):
|
||||
|
||||
def get_status(self, index):
|
||||
if index is None:
|
||||
return False
|
||||
return False
|
||||
|
||||
if index < self.FANTRAY_NUM_START_IDX or index > self.FANTRAY_NUM_START_IDX + self.num_fans - 1:
|
||||
logging.error('Invalid FAN index:%d', index)
|
||||
return False
|
||||
logging.error('Invalid FAN index:%d', index)
|
||||
return False
|
||||
|
||||
tray_index = ((index-1)/self.NUM_FANS_PERTRAY) + 1
|
||||
fantray_front_speed=self.get_front_fan_speed(tray_index)
|
||||
@ -112,38 +116,38 @@ class FanUtil(FanBase):
|
||||
|
||||
def get_direction(self, index):
|
||||
if index is None:
|
||||
return None
|
||||
return None
|
||||
|
||||
if index < self.FANTRAY_NUM_START_IDX or index > self.FANTRAY_NUM_START_IDX + self.num_fans - 1:
|
||||
logging.error('Invalid FAN index:%d', index)
|
||||
return None
|
||||
logging.error('Invalid FAN index:%d', index)
|
||||
return None
|
||||
|
||||
tray_index = ((index-1)/self.NUM_FANS_PERTRAY)
|
||||
fru_id = self.FRU_FAN_START_IDX + tray_index
|
||||
direction = self.get_fan_direction_from_fru(fru_id,'Board Extra')
|
||||
|
||||
if direction == 'B2F':
|
||||
return "INTAKE"
|
||||
return "INTAKE"
|
||||
elif direction == 'F2B':
|
||||
return "EXHAUST"
|
||||
return "EXHAUST"
|
||||
else:
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
def get_speed(self, index):
|
||||
if index is None:
|
||||
return 0
|
||||
return 0
|
||||
|
||||
if index < self.FANTRAY_NUM_START_IDX or index > self.FANTRAY_NUM_START_IDX + self.num_fans - 1:
|
||||
logging.error('Invalid FAN index:%d', index)
|
||||
return 0
|
||||
logging.error('Invalid FAN index:%d', index)
|
||||
return 0
|
||||
|
||||
tray_index = ((index-1)/self.NUM_FANS_PERTRAY) + 1
|
||||
|
||||
if (index % 2 != 0):
|
||||
fantray_speed=self.get_front_fan_speed(tray_index)
|
||||
fantray_speed=self.get_front_fan_speed(tray_index)
|
||||
else:
|
||||
fantray_speed=self.get_rear_fan_speed(tray_index)
|
||||
fantray_speed=self.get_rear_fan_speed(tray_index)
|
||||
|
||||
if (self.get_presence(index) == True):
|
||||
return int(fantray_speed.strip())
|
||||
|
@ -3,7 +3,7 @@
|
||||
# Platform-specific PSU status interface for SONiC
|
||||
#
|
||||
import logging
|
||||
import commands
|
||||
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
|
||||
|
||||
Z9332F_MAX_PSUS = 2
|
||||
FRU_PSUL = 11
|
||||
@ -18,14 +18,15 @@ except ImportError as e:
|
||||
|
||||
class PsuUtil(PsuBase):
|
||||
"""Platform-specific PSUutil class"""
|
||||
IPMI_PSU1_DATA = "ipmitool raw 0x04 0x2d 0x2f | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU2_DATA = "ipmitool raw 0x04 0x2d 0x39 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU_VOUT = "ipmitool sdr get PSU{0}_VOut"
|
||||
IPMI_PSU_POUT = "ipmitool sdr get PSU{0}_POut"
|
||||
IPMI_PSU_COUT = "ipmitool sdr get PSU{0}_COut"
|
||||
IPMI_PSU_FAN_SPEED = "ipmitool sdr get PSU{0}_Fan"
|
||||
IPMI_FRU = "ipmitool fru"
|
||||
IPMI_FRU_DATA = "ipmitool fru print {0}"
|
||||
IPMI_PSU1_DATA = ["ipmitool", "raw", "0x04", "0x2d", "0x2f"]
|
||||
IPMI_PSU2_DATA = ["ipmitool", "raw", "0x04", "0x2d", "0x39"]
|
||||
IPMI_PSU_VOUT = ["ipmitool", "sdr", "get", ""]
|
||||
IPMI_PSU_POUT = ["ipmitool", "sdr", "get", ""]
|
||||
IPMI_PSU_COUT = ["ipmitool", "sdr", "get", ""]
|
||||
IPMI_PSU_FAN_SPEED = ["ipmitool", "sdr", "get", ""]
|
||||
IPMI_FRU = ["ipmitool", "fru"]
|
||||
IPMI_FRU_DATA = ["ipmitool", "fru", "print", ""]
|
||||
awk_cmd = ['awk', '{print substr($0,9,1)}']
|
||||
|
||||
def __init__(self):
|
||||
PsuBase.__init__(self)
|
||||
@ -39,62 +40,66 @@ class PsuUtil(PsuBase):
|
||||
|
||||
def get_psu_vout(self,index):
|
||||
try:
|
||||
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_PSU_VOUT.format(index))
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
self.IPMI_PSU_VOUT[3] = 'PSU' + str(index) + '_VOut'
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_PSU_VOUT)
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
|
||||
except Exception:
|
||||
logging.error('Failed to execute : %s'%self.IPMI_PSU_VOUT.format(index))
|
||||
logging.error('Failed to execute : %s'%(' '.join(self.IPMI_PSU_VOUT)))
|
||||
|
||||
def get_psu_cout(self,index):
|
||||
try:
|
||||
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_PSU_COUT.format(index))
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
self.IPMI_PSU_COUT[3] = 'PSU' + str(index) + 'POut'
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_PSU_COUT)
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
|
||||
except Exception:
|
||||
logging.error('Failed to execute : %s'%self.IPMI_PSU_COUT.format(index))
|
||||
logging.error('Failed to execute : %s'%(' '.join(self.IPMI_PSU_COUT)))
|
||||
|
||||
def get_psu_pout(self,index):
|
||||
try:
|
||||
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_PSU_POUT.format(index))
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
self.IPMI_PSU_POUT[3] = 'PSU' + str(index) + '_COut'
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_PSU_POUT)
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
|
||||
except Exception:
|
||||
logging.error('Failed to execute : %s'%self.IPMI_PSU_POUT.format(index))
|
||||
logging.error('Failed to execute : %s'%(' '.join(self.IPMI_PSU_POUT)))
|
||||
|
||||
def get_psu_fan_speed(self,index):
|
||||
try:
|
||||
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_PSU_FAN_SPEED.format(index))
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
self.IPMI_PSU_FAN_SPEED[3] = 'PSU' + str(index) + '_Fan'
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_PSU_FAN_SPEED)
|
||||
if ret_status == 0:
|
||||
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
|
||||
return rdata
|
||||
|
||||
except Exception:
|
||||
logging.error('Failed to execute : %s'%self.IPMI_PSU_FAN_SPEED.format(index))
|
||||
logging.error('Failed to execute : %s'%(' '.join(self.IPMI_PSU_FAN_SPEED)))
|
||||
|
||||
|
||||
#Fetch FRU Data for given fruid
|
||||
def get_psu_airflow(self, index):
|
||||
if index == 1:
|
||||
fru_id = 'FRU_PSUL'
|
||||
fru_id = 'FRU_PSUL'
|
||||
else:
|
||||
fru_id = 'FRU_PSUR'
|
||||
fru_id = 'FRU_PSUR'
|
||||
|
||||
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_FRU)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_FRU)
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool: '+ self.IPMI_FRU)
|
||||
logging.error('Failed to execute ipmitool: '+ self.IPMI_FRU)
|
||||
|
||||
found_fru = False
|
||||
for line in ipmi_cmd_ret.splitlines():
|
||||
if line.startswith('FRU Device Description') and fru_id in line.split(':')[1] :
|
||||
found_fru = True
|
||||
found_fru = True
|
||||
if found_fru and line.startswith(' Board Product '):
|
||||
return ' B2F' if 'PS/IO' in line else ' F2B'
|
||||
return ' B2F' if 'PS/IO' in line else ' F2B'
|
||||
return ''
|
||||
|
||||
# Read FRU info
|
||||
@ -102,21 +107,22 @@ class PsuUtil(PsuBase):
|
||||
output = None
|
||||
Found = False
|
||||
try:
|
||||
status, ipmi_fru_list = commands.getstatusoutput(self.IPMI_FRU_DATA.format(fru_id))
|
||||
if status == 0:
|
||||
for item in ipmi_fru_list.split("\n"):
|
||||
if reg_name == item.split(':')[0].strip(' '):
|
||||
output = item.strip()
|
||||
output = output.split(':')[1]
|
||||
Found = True
|
||||
break;
|
||||
self.IPMI_FRU_DATA[3] = str(fru_id)
|
||||
status, ipmi_fru_list = getstatusoutput_noshell(self.IPMI_FRU_DATA)
|
||||
if status == 0:
|
||||
for item in ipmi_fru_list.split("\n"):
|
||||
if reg_name == item.split(':')[0].strip(' '):
|
||||
output = item.strip()
|
||||
output = output.split(':')[1]
|
||||
Found = True
|
||||
break;
|
||||
|
||||
if not Found:
|
||||
logging.error('\nFailed to fetch: ' + reg_name + ' sensor ')
|
||||
if not Found:
|
||||
logging.error('\nFailed to fetch: ' + reg_name + ' sensor ')
|
||||
|
||||
return output
|
||||
return output
|
||||
except Exception:
|
||||
logging.error('Failed to execute:' + ipmi_fru_list)
|
||||
logging.error('Failed to execute:' + ipmi_fru_list)
|
||||
|
||||
def get_num_psus(self):
|
||||
"""
|
||||
@ -135,17 +141,18 @@ class PsuUtil(PsuBase):
|
||||
faulty
|
||||
"""
|
||||
psu_status = '0'
|
||||
|
||||
ipmi_cmd = ''
|
||||
if index == 1:
|
||||
cmd_status, psu_status = commands.getstatusoutput(self.IPMI_PSU1_DATA)
|
||||
ipmi_cmd = self.IPMI_PSU1_DATA
|
||||
elif index == 2:
|
||||
cmd_status, psu_status = commands.getstatusoutput(self.IPMI_PSU2_DATA)
|
||||
ipmi_cmd = self.IPMI_PSU2_DATA
|
||||
else:
|
||||
logging.error("Invalid PSU number:" + index)
|
||||
|
||||
if cmd_status:
|
||||
logging.error('Failed to execute ipmitool')
|
||||
logging.error("Invalid PSU number:" + index)
|
||||
|
||||
if ipmi_cmd != '':
|
||||
cmd_status, psu_status = getstatusoutput_noshell_pipe(ipmi_cmd, self.awk_cmd)
|
||||
if cmd_status:
|
||||
logging.error('Failed to execute ipmitool')
|
||||
return (not int(psu_status, 16) > 1)
|
||||
|
||||
def get_psu_presence(self, index):
|
||||
@ -155,82 +162,85 @@ class PsuUtil(PsuBase):
|
||||
:param index: An integer, index of the PSU of which to query status
|
||||
:return: Boolean, True if PSU is plugged, False if not
|
||||
"""
|
||||
psu_status = '0'
|
||||
|
||||
psu_status = '0'
|
||||
ipmi_cmd = ''
|
||||
if index == 1:
|
||||
cmd_status, psu_status = commands.getstatusoutput(self.IPMI_PSU1_DATA)
|
||||
ipmi_cmd = self.IPMI_PSU1_DATA
|
||||
elif index == 2:
|
||||
cmd_status, psu_status = commands.getstatusoutput(self.IPMI_PSU2_DATA)
|
||||
ipmi_cmd = self.IPMI_PSU2_DATA
|
||||
else:
|
||||
logging.error("Invalid PSU number:" + index)
|
||||
|
||||
logging.error("Invalid PSU number:" + index)
|
||||
|
||||
if ipmi_cmd != '':
|
||||
cmd_status, psu_status = getstatusoutput_noshell_pipe(ipmi_cmd, self.awk_cmd)
|
||||
if cmd_status:
|
||||
logging.error('Failed to execute ipmitool')
|
||||
logging.error('Failed to execute ipmitool')
|
||||
|
||||
return (int(psu_status, 16) & 1)
|
||||
|
||||
def get_output_voltage(self, index):
|
||||
if index is None:
|
||||
return 0.0
|
||||
return 0.0
|
||||
psuvoltage=self.get_psu_vout(index)
|
||||
return float(psuvoltage.strip())
|
||||
|
||||
def get_output_current(self, index):
|
||||
if index is None:
|
||||
return 0.0
|
||||
return 0.0
|
||||
psucurrent=self.get_psu_cout(index)
|
||||
return float(psucurrent.strip())
|
||||
|
||||
def get_output_power(self, index):
|
||||
if index is None:
|
||||
return 0.0
|
||||
return 0.0
|
||||
psupower=self.get_psu_pout(index)
|
||||
return float(psupower.strip())
|
||||
|
||||
def get_fan_rpm(self, index, fan_idx):
|
||||
if index is None:
|
||||
return 0
|
||||
return 0
|
||||
fanrpm=self.get_psu_fan_speed(index)
|
||||
return int(fanrpm.strip())
|
||||
|
||||
def get_serial(self, index):
|
||||
if index is None:
|
||||
return None
|
||||
return None
|
||||
if index == 1:
|
||||
fru_id = FRU_PSUL
|
||||
fru_id = FRU_PSUL
|
||||
else:
|
||||
fru_id = FRU_PSUR
|
||||
fru_id = FRU_PSUR
|
||||
|
||||
return self.get_fru_info(fru_id,'Board Serial')
|
||||
|
||||
def get_model(self, index):
|
||||
if index is None:
|
||||
return None
|
||||
return None
|
||||
if index == 1:
|
||||
fru_id = FRU_PSUL
|
||||
fru_id = FRU_PSUL
|
||||
else:
|
||||
fru_id = FRU_PSUR
|
||||
fru_id = FRU_PSUR
|
||||
|
||||
return self.get_fru_info(fru_id,'Board Part Number')
|
||||
|
||||
def get_mfr_id(self, index):
|
||||
if index is None:
|
||||
return None
|
||||
return None
|
||||
if index == 1:
|
||||
fru_id = FRU_PSUL
|
||||
fru_id = FRU_PSUL
|
||||
else:
|
||||
fru_id = FRU_PSUR
|
||||
fru_id = FRU_PSUR
|
||||
|
||||
return self.get_fru_info(fru_id,'Board Mfg')
|
||||
|
||||
def get_direction(self, index):
|
||||
if index is None:
|
||||
return None
|
||||
return None
|
||||
|
||||
direction=self.get_psu_airflow(index).strip()
|
||||
if direction == 'B2F':
|
||||
return "INTAKE"
|
||||
return "INTAKE"
|
||||
elif direction == 'F2B':
|
||||
return "EXHAUST"
|
||||
return "EXHAUST"
|
||||
else:
|
||||
return None
|
||||
return None
|
||||
|
@ -19,8 +19,10 @@ def get_bios_version():
|
||||
return subprocess.check_output(['dmidecode', '-s', 'system-version']).strip().decode()
|
||||
|
||||
def get_cpld_version(cpld):
|
||||
mjr_ver=subprocess.check_output('cat /sys/devices/platform/dell-n3248pxe-cpld.0/' + cpld + '_mjr_ver', shell=True).strip()[2:].decode()
|
||||
mnr_ver=subprocess.check_output('cat /sys/devices/platform/dell-n3248pxe-cpld.0/' + cpld + '_mnr_ver', shell=True).strip()[2:].decode()
|
||||
mjr_ver_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/" + cpld + '_mjr_ver'
|
||||
mnr_ver_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/" + cpld + '_mnr_ver'
|
||||
mjr_ver = subprocess.check_output(['cat', mjr_ver_path]).strip()[2:].decode()
|
||||
mnr_ver = subprocess.check_output(['cat', mnr_ver_path]).strip()[2:].decode()
|
||||
return (str(mjr_ver) + '.' + str(mnr_ver))
|
||||
|
||||
class Component(ComponentBase):
|
||||
|
@ -61,20 +61,24 @@ class Psu(PsuBase):
|
||||
|
||||
def _reload_dps_module(self):
|
||||
try:
|
||||
del_cmd = "echo 0x56 > /sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
|
||||
os.system(del_cmd)
|
||||
file = "/sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
|
||||
with open(file, 'w') as f:
|
||||
f.write("0x56\n")
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
try:
|
||||
del_cmd = "echo 0x5e > /sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
|
||||
os.system(del_cmd)
|
||||
file = "/sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
|
||||
with open(file, 'w') as f:
|
||||
f.write("0x5e\n")
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
try:
|
||||
ins_cmd = "echo '24c02 0x56' > /sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1)
|
||||
os.system(ins_cmd)
|
||||
ins_cmd = "echo 'dps460 0x5e' > /sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1)
|
||||
os.system(ins_cmd)
|
||||
file = "/sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1)
|
||||
with open(file, 'w') as f:
|
||||
f.write('24c02 0x56\n')
|
||||
file = "/sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1)
|
||||
with open(file, 'w') as f:
|
||||
f.write('dps460 0x5e\n')
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
|
||||
|
@ -19,8 +19,10 @@ def get_bios_version():
|
||||
return subprocess.check_output(['dmidecode', '-s', 'system-version']).strip().decode()
|
||||
|
||||
def get_cpld_version(cpld):
|
||||
mjr_ver=subprocess.check_output('cat /sys/devices/platform/dell-n3248te-cpld.0/' + cpld + '_mjr_ver', shell=True).strip()[2:].decode()
|
||||
mnr_ver=subprocess.check_output('cat /sys/devices/platform/dell-n3248te-cpld.0/' + cpld + '_mnr_ver', shell=True).strip()[2:].decode()
|
||||
mjr_ver_path = '/sys/devices/platform/dell-n3248te-cpld.0/' + cpld + '_mjr_ver'
|
||||
mnr_ver_path = '/sys/devices/platform/dell-n3248te-cpld.0/' + cpld + '_mnr_ver'
|
||||
mjr_ver = subprocess.check_output(['cat', mjr_ver_path]).strip()[2:].decode()
|
||||
mnr_ver = subprocess.check_output(['cat', mnr_ver_path]).strip()[2:].decode()
|
||||
return (str(mjr_ver) + '.' + str(mnr_ver))
|
||||
|
||||
class Component(ComponentBase):
|
||||
|
@ -63,20 +63,24 @@ class Psu(PsuBase):
|
||||
|
||||
def _reload_dps_module(self):
|
||||
try:
|
||||
del_cmd = "echo 0x56 > /sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
|
||||
os.system(del_cmd)
|
||||
file = "/sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
|
||||
with open(file, 'w') as f:
|
||||
f.write('0x56\n')
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
try:
|
||||
del_cmd = "echo 0x5e > /sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
|
||||
os.system(del_cmd)
|
||||
file = "/sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
|
||||
with open(file, 'w') as f:
|
||||
f.write('0x5e\n')
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
try:
|
||||
ins_cmd = "echo '24c02 0x56' > /sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1)
|
||||
os.system(ins_cmd)
|
||||
ins_cmd = "echo 'dps460 0x5e' > /sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1)
|
||||
os.system(ins_cmd)
|
||||
file = "/sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1)
|
||||
with open(file, 'w') as f:
|
||||
f.write('24c02 0x56\n')
|
||||
file = "/sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1)
|
||||
with open(file, 'w') as f:
|
||||
f.write('dps460 0x5e\n')
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
|
||||
|
@ -13,10 +13,10 @@
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import commands
|
||||
from sonic_py_common.general import getstatusoutput_noshell
|
||||
|
||||
S5212F_MAX_FAN_TRAYS = 4
|
||||
IPMI_SENSOR_DATA = "ipmitool sdr list"
|
||||
IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
|
||||
|
||||
switch_sku = {
|
||||
"0K6MG9":(' AC', ' Exhaust'),
|
||||
@ -36,7 +36,7 @@ switch_sku = {
|
||||
"04T94Y":(' DC', ' Intake')
|
||||
}
|
||||
|
||||
ipmi_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_SENSOR_DATA)
|
||||
ipmi_status, ipmi_sdr_list = getstatusoutput_noshell(IPMI_SENSOR_DATA)
|
||||
|
||||
def get_pmc_register(reg_name):
|
||||
if ipmi_status:
|
||||
@ -56,21 +56,21 @@ def print_temperature_sensors():
|
||||
|
||||
print("\nOnboard Temperature Sensors:")
|
||||
|
||||
print ' PT_Left_temp: ',\
|
||||
(get_pmc_register('PT_Left_temp'))
|
||||
print ' PT_Mid_temp: ',\
|
||||
(get_pmc_register('PT_Mid_temp'))
|
||||
print ' PT_Right_temp: ',\
|
||||
(get_pmc_register('PT_Right_temp'))
|
||||
print ' Broadcom Temp: ',\
|
||||
(get_pmc_register('NPU_Near_temp'))
|
||||
print ' Inlet Airflow Temp: ',\
|
||||
(get_pmc_register('ILET_AF_temp'))
|
||||
print ' CPU Temp: ',\
|
||||
(get_pmc_register('CPU_temp'))
|
||||
print(' PT_Left_temp: ',\
|
||||
(get_pmc_register('PT_Left_temp')))
|
||||
print(' PT_Mid_temp: ',\
|
||||
(get_pmc_register('PT_Mid_temp')))
|
||||
print(' PT_Right_temp: ',\
|
||||
(get_pmc_register('PT_Right_temp')))
|
||||
print(' Broadcom Temp: ',\
|
||||
(get_pmc_register('NPU_Near_temp')))
|
||||
print(' Inlet Airflow Temp: ',\
|
||||
(get_pmc_register('ILET_AF_temp')))
|
||||
print(' CPU Temp: ',\
|
||||
(get_pmc_register('CPU_temp')))
|
||||
|
||||
def get_switch_details():
|
||||
status, ipmi_fru = commands.getstatusoutput('/usr/bin/ipmitool fru')
|
||||
status, ipmi_fru = getstatusoutput_noshell(['/usr/bin/ipmitool', 'fru'])
|
||||
for line in ipmi_fru.splitlines():
|
||||
info = line.split(':')
|
||||
if 'Board Part Number' in info[0] :
|
||||
@ -78,7 +78,9 @@ def get_switch_details():
|
||||
if (partno in switch_sku): return switch_sku[partno]
|
||||
return None
|
||||
|
||||
commands.getstatusoutput('echo 0 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us')
|
||||
file = '/sys/module/ipmi_si/parameters/kipmid_max_busy_us'
|
||||
with open(file, 'w') as f:
|
||||
f.write('0\n')
|
||||
print_temperature_sensors()
|
||||
|
||||
# Print the information for 1 Fan Tray
|
||||
@ -86,40 +88,42 @@ print_temperature_sensors()
|
||||
|
||||
def print_fan_tray(tray):
|
||||
|
||||
print ' Fan Tray ' + str(tray) + ':'
|
||||
print(' Fan Tray ' + str(tray) + ':')
|
||||
|
||||
if (tray == 1):
|
||||
print ' Fan1 Speed: ',\
|
||||
get_pmc_register('FAN1_Front_rpm')
|
||||
print ' Fan2 Speed: ',\
|
||||
get_pmc_register('FAN1_Rear_rpm')
|
||||
print(' Fan1 Speed: ',\
|
||||
get_pmc_register('FAN1_Front_rpm'))
|
||||
print(' Fan2 Speed: ',\
|
||||
get_pmc_register('FAN1_Rear_rpm'))
|
||||
|
||||
elif (tray == 2):
|
||||
print ' Fan1 Speed: ',\
|
||||
get_pmc_register('FAN2_Front_rpm')
|
||||
print ' Fan2 Speed: ',\
|
||||
get_pmc_register('FAN2_Rear_rpm')
|
||||
print(' Fan1 Speed: ',\
|
||||
get_pmc_register('FAN2_Front_rpm'))
|
||||
print(' Fan2 Speed: ',\
|
||||
get_pmc_register('FAN2_Rear_rpm'))
|
||||
|
||||
elif (tray == 3):
|
||||
print ' Fan1 Speed: ',\
|
||||
get_pmc_register('FAN3_Front_rpm')
|
||||
print ' Fan2 Speed: ',\
|
||||
get_pmc_register('FAN3_Rear_rpm')
|
||||
print(' Fan1 Speed: ',\
|
||||
get_pmc_register('FAN3_Front_rpm'))
|
||||
print(' Fan2 Speed: ',\
|
||||
get_pmc_register('FAN3_Rear_rpm'))
|
||||
|
||||
elif (tray == 4):
|
||||
print ' Fan1 Speed: ',\
|
||||
get_pmc_register('FAN4_Front_rpm')
|
||||
print ' Fan2 Speed: ',\
|
||||
get_pmc_register('FAN4_Rear_rpm')
|
||||
print(' Fan1 Speed: ',\
|
||||
get_pmc_register('FAN4_Front_rpm'))
|
||||
print(' Fan2 Speed: ',\
|
||||
get_pmc_register('FAN4_Rear_rpm'))
|
||||
|
||||
type, dir = get_switch_details()
|
||||
print('\nFan Trays(Fixed):')
|
||||
print ' Fan Tray Direction: ', dir
|
||||
print(' Fan Tray Direction: ', dir)
|
||||
for tray in range(1, S5212F_MAX_FAN_TRAYS + 1):
|
||||
print_fan_tray(tray)
|
||||
|
||||
print('\nPSU Tray(Fixed):')
|
||||
print ' PSU Tray Direction: ', dir
|
||||
print ' PSU Tray Type: ', type
|
||||
print(' PSU Tray Direction: ', dir)
|
||||
print(' PSU Tray Type: ', type)
|
||||
|
||||
ret_status, ipmi_cmd_ret = commands.getstatusoutput('echo 1000 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us')
|
||||
file = '/sys/module/ipmi_si/parameters/kipmid_max_busy_us'
|
||||
with open(file, 'w') as f:
|
||||
f.write('1000\n')
|
||||
|
@ -13,7 +13,6 @@ try:
|
||||
import time
|
||||
import struct
|
||||
import mmap
|
||||
import subprocess
|
||||
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
|
||||
|
||||
except ImportError as e:
|
||||
@ -300,7 +299,6 @@ class Sfp(SfpOptoeBase):
|
||||
del_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/delete_device".format(self.index+1)
|
||||
new_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/new_device".format(self.index+1)
|
||||
driver_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/name".format(self.index+1)
|
||||
delete_device = "echo 0x50 >" + del_sfp_path
|
||||
|
||||
if not os.path.isfile(driver_path):
|
||||
print(driver_path, "does not exist")
|
||||
@ -314,22 +312,25 @@ class Sfp(SfpOptoeBase):
|
||||
|
||||
#Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
|
||||
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe2 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe2 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe1 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe1 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe3 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe3 0x50\n')
|
||||
time.sleep(2)
|
||||
|
||||
except IOError as e:
|
||||
|
@ -10,25 +10,25 @@
|
||||
# * FAN trays
|
||||
# * PSU
|
||||
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import subprocess
|
||||
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
|
||||
|
||||
S5224F_MAX_FAN_TRAYS = 4
|
||||
S5224F_MAX_PSUS = 2
|
||||
IPMI_SENSOR_DATA = "ipmitool sdr list"
|
||||
IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
|
||||
IPMI_SENSOR_DUMP = "/tmp/sdr"
|
||||
|
||||
PSU_PRESENCE = "PSU{0}_stat"
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
|
||||
IPMI_FAN_PRESENCE = "ipmitool sensor get FAN{0}_prsnt"
|
||||
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x31 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU2_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x32 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_RAW_STORAGE_READ = "ipmitool raw 0x0a 0x11 {0} 0 0 0xa0"
|
||||
IPMI_FRU = "ipmitool fru"
|
||||
IPMI_FAN_PRESENCE = ["ipmitool", "sensor", "get", "FAN{0}_prsnt"]
|
||||
IPMI_PSU1_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x31"]
|
||||
IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x32"]
|
||||
awk_cmd = ['awk', '{print substr($0,9,1)}']
|
||||
IPMI_RAW_STORAGE_READ = ["ipmitool", "raw", "0x0a", "0x11", "", "0", "0", "0xa0"]
|
||||
IPMI_FRU = ["ipmitool", "fru"]
|
||||
ipmi_sdr_list = ""
|
||||
|
||||
# Dump sensor registers
|
||||
@ -38,7 +38,7 @@ def ipmi_sensor_dump():
|
||||
|
||||
global ipmi_sdr_list
|
||||
ipmi_cmd = IPMI_SENSOR_DATA
|
||||
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute:' + ipmi_sdr_list)
|
||||
@ -47,9 +47,10 @@ def ipmi_sensor_dump():
|
||||
# Fetch a Fan Status
|
||||
|
||||
def get_fan_status(fan_id):
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_FAN_PRESENCE.format(fan_id))
|
||||
IPMI_FAN_PRESENCE[3] = 'FAN' + str(fan_id) + '_prsnt'
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(IPMI_FAN_PRESENCE)
|
||||
if ret_status:
|
||||
logging.error('Failed to execute : %s'%IPMI_FAN_PRESENCE.format(fan_id))
|
||||
logging.error('Failed to execute : %s'% (' '.join(IPMI_FAN_PRESENCE)))
|
||||
sys.exit(0)
|
||||
return(' ' + ipmi_cmd_ret.splitlines()[5].strip(' ').strip('[]'))
|
||||
|
||||
@ -75,9 +76,9 @@ def get_pmc_register(reg_name):
|
||||
#Fetch FRU Data for given fruid
|
||||
def get_psu_airflow(psu_id):
|
||||
fru_id = 'PSU' + str(psu_id) + '_fru'
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_FRU)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(IPMI_FRU)
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool: '+ IPMI_FRU)
|
||||
logging.error('Failed to execute ipmitool: '+ ' '.join(IPMI_FRU))
|
||||
sys.exit(0)
|
||||
found_fru = False
|
||||
for line in ipmi_cmd_ret.splitlines():
|
||||
@ -89,9 +90,10 @@ def get_psu_airflow(psu_id):
|
||||
|
||||
# Fetch FRU on given offset
|
||||
def fetch_raw_fru(dev_id, offset):
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_RAW_STORAGE_READ.format(dev_id))
|
||||
IPMI_RAW_STORAGE_READ[3] = str(dev_id)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(IPMI_RAW_STORAGE_READ)
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool :' + IPMI_RAW_STORAGE_READ.format(dev_id))
|
||||
logging.error('Failed to execute ipmitool :' + ' '.join(IPMI_RAW_STORAGE_READ))
|
||||
sys.exit(0)
|
||||
return int((ipmi_cmd_ret.splitlines()[int(offset/16)]).split(' ')[(int(offset%16)+1)])
|
||||
|
||||
@ -119,8 +121,11 @@ def print_temperature_sensors():
|
||||
print (' CPU Temp: ',\
|
||||
(get_pmc_register('CPU_temp')))
|
||||
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput('echo 0 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us')
|
||||
if ret_status:
|
||||
file = '/sys/module/ipmi_si/parameters/kipmid_max_busy_us'
|
||||
try:
|
||||
with open(file, 'w') as f:
|
||||
f.write('0\n')
|
||||
except (IOError, FileNotFoundError):
|
||||
logging.error("platform_sensors: Failed to set kipmid_max_busy_us to 0")
|
||||
ipmi_sensor_dump()
|
||||
|
||||
@ -212,12 +217,12 @@ def get_psu_presence(index):
|
||||
ret_status = 1
|
||||
|
||||
if index == 1:
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU1_DATA_DOCKER, awk_cmd)
|
||||
elif index == 2:
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU2_DATA_DOCKER, awk_cmd)
|
||||
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool :' + IPMI_PSU1_DATA_DOCKER)
|
||||
logging.error('Failed to execute ipmitool :' + ' '.join(IPMI_PSU1_DATA_DOCKER))
|
||||
sys.exit(0)
|
||||
|
||||
psu_status = ipmi_cmd_ret
|
||||
@ -234,12 +239,12 @@ def get_psu_status(index):
|
||||
ipmi_cmd_ret = 'f'
|
||||
|
||||
if index == 1:
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU1_DATA_DOCKER, awk_cmd)
|
||||
elif index == 2:
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU2_DATA_DOCKER, awk_cmd)
|
||||
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool : ' + IPMI_PSU2_DATA_DOCKER)
|
||||
logging.error('Failed to execute ipmitool : ' + ' '.join(IPMI_PSU2_DATA_DOCKER))
|
||||
sys.exit(0)
|
||||
|
||||
psu_status = ipmi_cmd_ret
|
||||
@ -316,6 +321,9 @@ for psu in range(1, S5224F_MAX_PSUS + 1):
|
||||
print ('\n Total Power: ',\
|
||||
get_pmc_register('PSU_Total_watt'))
|
||||
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput('echo 1000 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us')
|
||||
if ret_status:
|
||||
file = '/sys/module/ipmi_si/parameters/kipmid_max_busy_us'
|
||||
try:
|
||||
with open(file, 'w') as f:
|
||||
f.write('1000\n')
|
||||
except (IOError, FileNotFoundError):
|
||||
logging.error("platform_sensors: Failed to set kipmid_max_busy_us to 1000")
|
||||
|
@ -13,7 +13,6 @@ try:
|
||||
import time
|
||||
import struct
|
||||
import mmap
|
||||
import subprocess
|
||||
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
|
||||
|
||||
except ImportError as e:
|
||||
@ -300,7 +299,6 @@ class Sfp(SfpOptoeBase):
|
||||
del_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/delete_device".format(self.index+1)
|
||||
new_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/new_device".format(self.index+1)
|
||||
driver_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/name".format(self.index+1)
|
||||
delete_device = "echo 0x50 >" + del_sfp_path
|
||||
|
||||
if not os.path.isfile(driver_path):
|
||||
print(driver_path, "does not exist")
|
||||
@ -314,22 +312,25 @@ class Sfp(SfpOptoeBase):
|
||||
|
||||
#Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
|
||||
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe2 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe2 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe1 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe1 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe3 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe3 0x50\n')
|
||||
time.sleep(2)
|
||||
|
||||
except IOError as e:
|
||||
|
@ -13,21 +13,23 @@
|
||||
|
||||
import sys
|
||||
import logging
|
||||
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
|
||||
|
||||
S5232F_MAX_FAN_TRAYS = 4
|
||||
S5232F_MAX_PSUS = 2
|
||||
IPMI_SENSOR_DATA = "ipmitool sdr list"
|
||||
IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
|
||||
IPMI_SENSOR_DUMP = "/tmp/sdr"
|
||||
|
||||
PSU_PRESENCE = "PSU{0}_stat"
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
|
||||
IPMI_FAN_PRESENCE = "ipmitool sensor get FAN{0}_prsnt"
|
||||
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x31 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU2_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x32 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_RAW_STORAGE_READ = "ipmitool raw 0x0a 0x11 {0} 0 0 0xa0"
|
||||
IPMI_FRU = "ipmitool fru"
|
||||
IPMI_FAN_PRESENCE = ["ipmitool", "sensor", "get", ""]
|
||||
IPMI_PSU1_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x31"]
|
||||
IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x32"]
|
||||
awk_cmd = ['awk', '{print substr($0,9,1)}']
|
||||
IPMI_RAW_STORAGE_READ = ["ipmitool", "raw", "0x0a", "0x11", "", "0", "0", "0xa0"]
|
||||
IPMI_FRU = ["ipmitool", "fru"]
|
||||
ipmi_sdr_list = ""
|
||||
|
||||
# Dump sensor registers
|
||||
@ -38,7 +40,7 @@ def ipmi_sensor_dump():
|
||||
status = 1
|
||||
global ipmi_sdr_list
|
||||
ipmi_cmd = IPMI_SENSOR_DATA
|
||||
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute: ' + ipmi_sdr_list)
|
||||
@ -47,9 +49,10 @@ def ipmi_sensor_dump():
|
||||
# Fetch a Fan Status
|
||||
|
||||
def get_fan_status(fan_id):
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_FAN_PRESENCE.format(fan_id))
|
||||
IPMI_FAN_PRESENCE[3] = "FAN" + str(fan_id) + "_prsnt"
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(IPMI_FAN_PRESENCE)
|
||||
if ret_status:
|
||||
logging.error('Failed to execute : %s' % IPMI_FAN_PRESENCE.format(fan_id))
|
||||
logging.error('Failed to execute : %s' % ' '.join(IPMI_FAN_PRESENCE))
|
||||
sys.exit(0)
|
||||
return(' ' + ipmi_cmd_ret.splitlines()[5].strip(' ').strip('[]'))
|
||||
|
||||
@ -75,9 +78,9 @@ def get_pmc_register(reg_name):
|
||||
# Fetch FRU Data for given fruid
|
||||
def get_psu_airflow(psu_id):
|
||||
fru_id = 'PSU' + str(psu_id) + '_fru'
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_FRU)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(IPMI_FRU)
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool: ' + IPMI_FRU)
|
||||
logging.error('Failed to execute ipmitool: ' + ' '.join(IPMI_FRU))
|
||||
sys.exit(0)
|
||||
found_fru = False
|
||||
for line in ipmi_cmd_ret.splitlines():
|
||||
@ -89,9 +92,10 @@ def get_psu_airflow(psu_id):
|
||||
|
||||
# Fetch FRU on given offset
|
||||
def fetch_raw_fru(dev_id, offset):
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_RAW_STORAGE_READ.format(dev_id))
|
||||
IPMI_RAW_STORAGE_READ[4] = str(dev_id)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell(IPMI_RAW_STORAGE_READ)
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool :' + IPMI_RAW_STORAGE_READ.format(dev_id))
|
||||
logging.error('Failed to execute ipmitool :' + ' '.join(IPMI_RAW_STORAGE_READ))
|
||||
sys.exit(0)
|
||||
return int((ipmi_cmd_ret.splitlines()[offset//16]).split(' ')[(offset%16+1)])
|
||||
|
||||
@ -118,7 +122,9 @@ def print_temperature_sensors():
|
||||
print(' CPU Temp: ',
|
||||
get_pmc_register('CPU_temp'))
|
||||
|
||||
subprocess.getstatusoutput('echo 0 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us')
|
||||
file = '/sys/module/ipmi_si/parameters/kipmid_max_busy_us'
|
||||
with open(file, 'w') as f:
|
||||
f.write('0\n')
|
||||
ipmi_sensor_dump()
|
||||
|
||||
print_temperature_sensors()
|
||||
@ -209,12 +215,12 @@ for tray in range(1, S5232F_MAX_FAN_TRAYS + 1):
|
||||
ret_status = 1
|
||||
|
||||
if index == 1:
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU1_DATA_DOCKER, awk_cmd)
|
||||
elif index == 2:
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU2_DATA_DOCKER, awk_cmd)
|
||||
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool :' + IPMI_PSU1_DATA_DOCKER)
|
||||
logging.error('Failed to execute ipmitool :' + ' '.join(IPMI_PSU1_DATA_DOCKER))
|
||||
sys.exit(0)
|
||||
|
||||
psu_status = ipmi_cmd_ret
|
||||
@ -232,12 +238,12 @@ for tray in range(1, S5232F_MAX_FAN_TRAYS + 1):
|
||||
ipmi_cmd_ret = 'f'
|
||||
|
||||
if index == 1:
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU1_DATA_DOCKER, awk_cmd)
|
||||
elif index == 2:
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU2_DATA_DOCKER, awk_cmd)
|
||||
|
||||
if ret_status:
|
||||
logging.error('Failed to execute ipmitool : ' + IPMI_PSU2_DATA_DOCKER)
|
||||
logging.error('Failed to execute ipmitool : ' + ' '.join(IPMI_PSU2_DATA_DOCKER))
|
||||
sys.exit(0)
|
||||
|
||||
psu_status = ipmi_cmd_ret
|
||||
@ -330,4 +336,6 @@ for psu in range(1, S5232F_MAX_PSUS + 1):
|
||||
print('\n Total Power: ',
|
||||
get_pmc_register('PSU_Total_watt'))
|
||||
|
||||
subprocess.getstatusoutput('echo 1000 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us')
|
||||
file = '/sys/module/ipmi_si/parameters/kipmid_max_busy_us'
|
||||
with open(file, 'w') as f:
|
||||
f.write('1000\n')
|
||||
|
@ -13,7 +13,6 @@ try:
|
||||
import time
|
||||
import struct
|
||||
import mmap
|
||||
import subprocess
|
||||
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
|
||||
|
||||
except ImportError as e:
|
||||
@ -278,7 +277,6 @@ class Sfp(SfpOptoeBase):
|
||||
del_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/delete_device".format(self.index+1)
|
||||
new_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/new_device".format(self.index+1)
|
||||
driver_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/name".format(self.index+1)
|
||||
delete_device = "echo 0x50 >" + del_sfp_path
|
||||
|
||||
if not os.path.isfile(driver_path):
|
||||
print(driver_path, "does not exist")
|
||||
@ -292,22 +290,25 @@ class Sfp(SfpOptoeBase):
|
||||
|
||||
#Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
|
||||
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe2 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe2 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe1 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe1 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe3 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe3 0x50\n')
|
||||
time.sleep(2)
|
||||
|
||||
except IOError as e:
|
||||
|
@ -13,11 +13,11 @@
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import subprocess
|
||||
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
|
||||
|
||||
S5248F_MAX_FAN_TRAYS = 4
|
||||
S5248F_MAX_PSUS = 2
|
||||
IPMI_SENSOR_DATA = "ipmitool sdr list"
|
||||
IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
|
||||
IPMI_SENSOR_DUMP = "/tmp/sdr"
|
||||
|
||||
FAN_PRESENCE = "FAN{0}_prsnt"
|
||||
@ -25,8 +25,9 @@ PSU_PRESENCE = "PSU{0}_stat"
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
|
||||
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x31 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU2_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x32 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU1_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x31"]
|
||||
IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x32"]
|
||||
awk_cmd = ['awk', '{print substr($0,9,1)}']
|
||||
ipmi_sdr_list = ""
|
||||
|
||||
# Dump sensor registers
|
||||
@ -37,7 +38,7 @@ def ipmi_sensor_dump():
|
||||
status = 1
|
||||
global ipmi_sdr_list
|
||||
ipmi_cmd = IPMI_SENSOR_DATA
|
||||
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute:' + ipmi_sdr_list)
|
||||
@ -174,9 +175,9 @@ for tray in range(1, S5248F_MAX_FAN_TRAYS + 1):
|
||||
ret_status = 1
|
||||
|
||||
if index == 1:
|
||||
status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU1_DATA_DOCKER, awk_cmd)
|
||||
elif index == 2:
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU2_DATA_DOCKER, awk_cmd)
|
||||
|
||||
#if ret_status:
|
||||
# print ipmi_cmd_ret
|
||||
@ -186,7 +187,7 @@ for tray in range(1, S5248F_MAX_FAN_TRAYS + 1):
|
||||
psu_status = ipmi_cmd_ret
|
||||
|
||||
if psu_status == '1':
|
||||
status = 1
|
||||
status = 1
|
||||
|
||||
return status
|
||||
|
||||
|
@ -13,7 +13,6 @@ try:
|
||||
import time
|
||||
import struct
|
||||
import mmap
|
||||
import subprocess
|
||||
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
|
||||
|
||||
except ImportError as e:
|
||||
@ -242,7 +241,7 @@ class Sfp(SfpOptoeBase):
|
||||
"""
|
||||
reset = self.get_reset_status()
|
||||
|
||||
if (reset == True):
|
||||
if (reset is True):
|
||||
status = False
|
||||
else:
|
||||
status = True
|
||||
@ -278,7 +277,6 @@ class Sfp(SfpOptoeBase):
|
||||
del_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/delete_device".format(self.index+1)
|
||||
new_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/new_device".format(self.index+1)
|
||||
driver_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/name".format(self.index+1)
|
||||
delete_device = "echo 0x50 >" + del_sfp_path
|
||||
|
||||
if not os.path.isfile(driver_path):
|
||||
print(driver_path, "does not exist")
|
||||
@ -292,22 +290,25 @@ class Sfp(SfpOptoeBase):
|
||||
|
||||
#Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
|
||||
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe2 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe2 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe1 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe1 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe3 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe3 0x50\n')
|
||||
time.sleep(2)
|
||||
|
||||
except IOError as e:
|
||||
|
@ -13,11 +13,11 @@
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import commands
|
||||
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
|
||||
|
||||
S5296F_MAX_FAN_TRAYS = 4
|
||||
S5296F_MAX_PSUS = 2
|
||||
IPMI_SENSOR_DATA = "ipmitool sdr list"
|
||||
IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
|
||||
IPMI_SENSOR_DUMP = "/tmp/sdr"
|
||||
|
||||
FAN_PRESENCE = "FAN{0}_prsnt"
|
||||
@ -25,8 +25,9 @@ PSU_PRESENCE = "PSU{0}_stat"
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
|
||||
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x31 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU2_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x32 | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU1_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x31"]
|
||||
IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x32"]
|
||||
awk_cmd = ['awk', '{print substr($0,9,1)}']
|
||||
ipmi_sdr_list = ""
|
||||
|
||||
# Dump sensor registers
|
||||
@ -36,7 +37,7 @@ def ipmi_sensor_dump():
|
||||
|
||||
global ipmi_sdr_list
|
||||
ipmi_cmd = IPMI_SENSOR_DATA
|
||||
status, ipmi_sdr_list = commands.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute:' + ipmi_sdr_list)
|
||||
@ -69,18 +70,18 @@ def print_temperature_sensors():
|
||||
|
||||
print("\nOnboard Temperature Sensors:")
|
||||
|
||||
print ' PT_Left_temp: ',\
|
||||
(get_pmc_register('PT_Left_temp'))
|
||||
print ' PT_Mid_temp: ',\
|
||||
(get_pmc_register('PT_Mid_temp'))
|
||||
print ' PT_Right_temp: ',\
|
||||
(get_pmc_register('PT_Right_temp'))
|
||||
print ' Broadcom Temp: ',\
|
||||
(get_pmc_register('NPU_Near_temp'))
|
||||
print ' Inlet Airflow Temp: ',\
|
||||
(get_pmc_register('ILET_AF_temp'))
|
||||
print ' CPU Temp: ',\
|
||||
(get_pmc_register('CPU_temp'))
|
||||
print(' PT_Left_temp: ',\
|
||||
(get_pmc_register('PT_Left_temp')))
|
||||
print(' PT_Mid_temp: ',\
|
||||
(get_pmc_register('PT_Mid_temp')))
|
||||
print(' PT_Right_temp: ',\
|
||||
(get_pmc_register('PT_Right_temp')))
|
||||
print(' Broadcom Temp: ',\
|
||||
(get_pmc_register('NPU_Near_temp')))
|
||||
print(' Inlet Airflow Temp: ',\
|
||||
(get_pmc_register('ILET_AF_temp')))
|
||||
print(' CPU Temp: ',\
|
||||
(get_pmc_register('CPU_temp')))
|
||||
|
||||
ipmi_sensor_dump()
|
||||
|
||||
@ -93,43 +94,43 @@ def print_fan_tray(tray):
|
||||
|
||||
Fan_Status = [' Normal', ' Abnormal']
|
||||
|
||||
print ' Fan Tray ' + str(tray) + ':'
|
||||
print(' Fan Tray ' + str(tray) + ':')
|
||||
|
||||
if (tray == 1):
|
||||
|
||||
fan2_status = int(get_pmc_register('FAN1_Rear_stat'), 16)
|
||||
|
||||
print ' Fan Speed: ',\
|
||||
get_pmc_register('FAN1_Rear_rpm')
|
||||
print ' Fan State: ',\
|
||||
Fan_Status[fan2_status]
|
||||
print(' Fan Speed: ',\
|
||||
get_pmc_register('FAN1_Rear_rpm'))
|
||||
print(' Fan State: ',\
|
||||
Fan_Status[fan2_status])
|
||||
|
||||
elif (tray == 2):
|
||||
|
||||
fan2_status = int(get_pmc_register('FAN2_Rear_stat'), 16)
|
||||
|
||||
print ' Fan Speed: ',\
|
||||
get_pmc_register('FAN2_Rear_rpm')
|
||||
print ' Fan State: ',\
|
||||
Fan_Status[fan2_status]
|
||||
print(' Fan Speed: ',\
|
||||
get_pmc_register('FAN2_Rear_rpm'))
|
||||
print(' Fan State: ',\
|
||||
Fan_Status[fan2_status])
|
||||
|
||||
elif (tray == 3):
|
||||
|
||||
fan2_status = int(get_pmc_register('FAN3_Rear_stat'), 16)
|
||||
|
||||
print ' Fan Speed: ',\
|
||||
get_pmc_register('FAN3_Rear_rpm')
|
||||
print ' Fan State: ',\
|
||||
Fan_Status[fan2_status]
|
||||
print(' Fan Speed: ',\
|
||||
get_pmc_register('FAN3_Rear_rpm'))
|
||||
print(' Fan State: ',\
|
||||
Fan_Status[fan2_status])
|
||||
|
||||
elif (tray == 4):
|
||||
|
||||
fan2_status = int(get_pmc_register('FAN4_Rear_stat'), 16)
|
||||
|
||||
print ' Fan Speed: ',\
|
||||
get_pmc_register('FAN4_Rear_rpm')
|
||||
print ' Fan State: ',\
|
||||
Fan_Status[fan2_status]
|
||||
print(' Fan Speed: ',\
|
||||
get_pmc_register('FAN4_Rear_rpm'))
|
||||
print(' Fan State: ',\
|
||||
Fan_Status[fan2_status])
|
||||
|
||||
|
||||
print('\nFan Trays:')
|
||||
@ -139,7 +140,7 @@ for tray in range(1, S5296F_MAX_FAN_TRAYS + 1):
|
||||
if (get_pmc_register(fan_presence)):
|
||||
print_fan_tray(tray)
|
||||
else:
|
||||
print '\n Fan Tray ' + str(tray + 1) + ': Not present'
|
||||
print('\n Fan Tray ' + str(tray + 1) + ': Not present')
|
||||
|
||||
def get_psu_presence(index):
|
||||
"""
|
||||
@ -151,9 +152,9 @@ for tray in range(1, S5296F_MAX_FAN_TRAYS + 1):
|
||||
status = 0
|
||||
|
||||
if index == 1:
|
||||
status, ipmi_cmd_ret = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU1_DATA_DOCKER, awk_cmd)
|
||||
elif index == 2:
|
||||
ret_status, ipmi_cmd_ret = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU2_DATA_DOCKER, awk_cmd)
|
||||
|
||||
#if ret_status:
|
||||
# print ipmi_cmd_ret
|
||||
@ -163,7 +164,7 @@ for tray in range(1, S5296F_MAX_FAN_TRAYS + 1):
|
||||
psu_status = ipmi_cmd_ret
|
||||
|
||||
if psu_status == '1':
|
||||
status = 1
|
||||
status = 1
|
||||
|
||||
return status
|
||||
|
||||
@ -179,54 +180,54 @@ def print_psu(psu):
|
||||
|
||||
# psu1_fan_status = int(get_pmc_register('PSU1_status'),16)
|
||||
|
||||
print ' PSU1:'
|
||||
print ' FAN Normal Temperature: ',\
|
||||
get_pmc_register('PSU1_temp')
|
||||
print ' FAN AirFlow Temperature: ',\
|
||||
get_pmc_register('PSU1_AF_temp')
|
||||
print ' FAN RPM: ',\
|
||||
get_pmc_register('PSU1_rpm')
|
||||
print(' PSU1:')
|
||||
print(' FAN Normal Temperature: ',\
|
||||
get_pmc_register('PSU1_temp'))
|
||||
print(' FAN AirFlow Temperature: ',\
|
||||
get_pmc_register('PSU1_AF_temp'))
|
||||
print(' FAN RPM: ',\
|
||||
get_pmc_register('PSU1_rpm'))
|
||||
# print ' FAN Status: ', Psu_Fan_Status[psu1_fan_status]
|
||||
|
||||
# PSU input & output monitors
|
||||
print ' Input Voltage: ',\
|
||||
get_pmc_register('PSU1_In_volt')
|
||||
print ' Output Voltage: ',\
|
||||
get_pmc_register('PSU1_Out_volt')
|
||||
print ' Input Power: ',\
|
||||
get_pmc_register('PSU1_In_watt')
|
||||
print ' Output Power: ',\
|
||||
get_pmc_register('PSU1_Out_watt')
|
||||
print ' Input Current: ',\
|
||||
get_pmc_register('PSU1_In_amp')
|
||||
print ' Output Current: ',\
|
||||
get_pmc_register('PSU1_Out_amp')
|
||||
print(' Input Voltage: ',\
|
||||
get_pmc_register('PSU1_In_volt'))
|
||||
print(' Output Voltage: ',\
|
||||
get_pmc_register('PSU1_Out_volt'))
|
||||
print(' Input Power: ',\
|
||||
get_pmc_register('PSU1_In_watt'))
|
||||
print(' Output Power: ',\
|
||||
get_pmc_register('PSU1_Out_watt'))
|
||||
print(' Input Current: ',\
|
||||
get_pmc_register('PSU1_In_amp'))
|
||||
print(' Output Current: ',\
|
||||
get_pmc_register('PSU1_Out_amp'))
|
||||
|
||||
else:
|
||||
|
||||
# psu2_fan_status = int(get_pmc_register('PSU1_status'),16)
|
||||
print ' PSU2:'
|
||||
print ' FAN Normal Temperature: ',\
|
||||
get_pmc_register('PSU2_temp')
|
||||
print ' FAN AirFlow Temperature: ',\
|
||||
get_pmc_register('PSU2_AF_temp')
|
||||
print ' FAN RPM: ',\
|
||||
get_pmc_register('PSU2_rpm')
|
||||
print(' PSU2:')
|
||||
print(' FAN Normal Temperature: ',\
|
||||
get_pmc_register('PSU2_temp'))
|
||||
print(' FAN AirFlow Temperature: ',\
|
||||
get_pmc_register('PSU2_AF_temp'))
|
||||
print(' FAN RPM: ',\
|
||||
get_pmc_register('PSU2_rpm'))
|
||||
# print ' FAN Status: ', Psu_Fan_Status[psu2_fan_status]
|
||||
|
||||
# PSU input & output monitors
|
||||
print ' Input Voltage: ',\
|
||||
get_pmc_register('PSU2_In_volt')
|
||||
print ' Output Voltage: ',\
|
||||
get_pmc_register('PSU2_Out_volt')
|
||||
print ' Input Power: ',\
|
||||
get_pmc_register('PSU2_In_watt')
|
||||
print ' Output Power: ',\
|
||||
get_pmc_register('PSU2_Out_watt')
|
||||
print ' Input Current: ',\
|
||||
get_pmc_register('PSU2_In_amp')
|
||||
print ' Output Current: ',\
|
||||
get_pmc_register('PSU2_Out_amp')
|
||||
print(' Input Voltage: ',\
|
||||
get_pmc_register('PSU2_In_volt'))
|
||||
print(' Output Voltage: ',\
|
||||
get_pmc_register('PSU2_Out_volt'))
|
||||
print(' Input Power: ',\
|
||||
get_pmc_register('PSU2_In_watt'))
|
||||
print(' Output Power: ',\
|
||||
get_pmc_register('PSU2_Out_watt'))
|
||||
print(' Input Current: ',\
|
||||
get_pmc_register('PSU2_In_amp'))
|
||||
print(' Output Current: ',\
|
||||
get_pmc_register('PSU2_Out_amp'))
|
||||
|
||||
|
||||
print('\nPSUs:')
|
||||
@ -235,8 +236,8 @@ for psu in range(1, S5296F_MAX_PSUS + 1):
|
||||
if (get_psu_presence(psu)):
|
||||
print_psu(psu)
|
||||
else:
|
||||
print '\n PSU ', psu, 'Not present'
|
||||
print('\n PSU ', psu, 'Not present')
|
||||
|
||||
print '\n Total Power: ',\
|
||||
get_pmc_register('PSU_Total_watt')
|
||||
print('\n Total Power: ',\
|
||||
get_pmc_register('PSU_Total_watt'))
|
||||
|
||||
|
@ -14,6 +14,7 @@ try:
|
||||
import subprocess
|
||||
from sonic_platform_base.component_base import ComponentBase
|
||||
import sonic_platform.hwaccess as hwaccess
|
||||
from sonic_py_common.general import check_output_pipe
|
||||
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
@ -31,9 +32,7 @@ def get_bmc_version():
|
||||
""" Returns BMC Version """
|
||||
bmc_ver = ''
|
||||
try:
|
||||
bmc_ver = subprocess.check_output(
|
||||
"ipmitool mc info | awk '/Firmware Revision/ { print $NF }'",
|
||||
shell=True, text=True).strip()
|
||||
bmc_ver = check_output_pipe(["ipmitool", "mc", "info"], ["awk", "/Firmware Revision/ { print $NF }"])
|
||||
except (FileNotFoundError, subprocess.CalledProcessError):
|
||||
pass
|
||||
return bmc_ver
|
||||
|
@ -257,7 +257,7 @@ class Sfp(SfpOptoeBase):
|
||||
"""
|
||||
reset = self.get_reset_status()
|
||||
|
||||
if (reset == True):
|
||||
if (reset is True):
|
||||
status = False
|
||||
else:
|
||||
status = True
|
||||
@ -293,7 +293,6 @@ class Sfp(SfpOptoeBase):
|
||||
del_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/delete_device".format(self.index+1)
|
||||
new_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/new_device".format(self.index+1)
|
||||
driver_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/name".format(self.index+1)
|
||||
delete_device = "echo 0x50 >" + del_sfp_path
|
||||
|
||||
if not os.path.isfile(driver_path):
|
||||
print(driver_path, "does not exist")
|
||||
@ -307,22 +306,25 @@ class Sfp(SfpOptoeBase):
|
||||
|
||||
#Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
|
||||
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe2 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe2 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe1 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe1 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe3 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe3 0x50\n')
|
||||
time.sleep(2)
|
||||
|
||||
except IOError as e:
|
||||
|
@ -13,11 +13,11 @@
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import subprocess
|
||||
from sonic_py_common.general import getstatusoutput_noshell
|
||||
|
||||
Z9264F_MAX_FAN_TRAYS = 4
|
||||
Z9264F_MAX_PSUS = 2
|
||||
IPMI_SENSOR_DATA = "ipmitool sdr list"
|
||||
IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
|
||||
IPMI_SENSOR_DUMP = "/tmp/sdr"
|
||||
|
||||
FAN_PRESENCE = "FAN{0}_prsnt"
|
||||
@ -34,7 +34,7 @@ def ipmi_sensor_dump():
|
||||
status = 1
|
||||
global ipmi_sdr_list
|
||||
ipmi_cmd = IPMI_SENSOR_DATA
|
||||
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute:' + ipmi_sdr_list)
|
||||
|
@ -13,7 +13,6 @@ try:
|
||||
import time
|
||||
import struct
|
||||
import mmap
|
||||
import subprocess
|
||||
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
|
||||
|
||||
except ImportError as e:
|
||||
@ -244,7 +243,7 @@ class Sfp(SfpOptoeBase):
|
||||
"""
|
||||
reset = self.get_reset_status()
|
||||
|
||||
if (reset == True):
|
||||
if (reset is True):
|
||||
status = False
|
||||
else:
|
||||
status = True
|
||||
@ -280,7 +279,6 @@ class Sfp(SfpOptoeBase):
|
||||
del_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/delete_device".format(self.index+1)
|
||||
new_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/new_device".format(self.index+1)
|
||||
driver_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/name".format(self.index+1)
|
||||
delete_device = "echo 0x50 >" + del_sfp_path
|
||||
|
||||
if not os.path.isfile(driver_path):
|
||||
print(driver_path, "does not exist")
|
||||
@ -294,22 +292,25 @@ class Sfp(SfpOptoeBase):
|
||||
|
||||
#Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
|
||||
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe2 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe2 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe1 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe1 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe3 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe3 0x50\n')
|
||||
time.sleep(2)
|
||||
|
||||
except IOError as e:
|
||||
|
@ -13,11 +13,11 @@
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import subprocess
|
||||
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
|
||||
|
||||
Z9332F_MAX_FAN_TRAYS = 7
|
||||
Z9332F_MAX_PSUS = 2
|
||||
IPMI_SENSOR_DATA = "ipmitool sdr list"
|
||||
IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
|
||||
IPMI_SENSOR_DUMP = "/tmp/sdr"
|
||||
|
||||
FAN_PRESENCE = "Fan{0}_Status"
|
||||
@ -25,9 +25,9 @@ PSU_PRESENCE = "PSU{0}_Status"
|
||||
# Use this for older firmware
|
||||
# PSU_PRESENCE="PSU{0}_prsnt"
|
||||
|
||||
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x2f | awk '{print substr($0,9,1)}'"
|
||||
IPMI_PSU2_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x39 | awk '{print substr($0,9,1)}'"
|
||||
|
||||
IPMI_PSU1_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x2f"]
|
||||
IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x39"]
|
||||
awk_cmd = ['awk', '{print substr($0,9,1)}']
|
||||
ipmi_sdr_list = ""
|
||||
|
||||
# Dump sensor registers
|
||||
@ -38,7 +38,7 @@ def ipmi_sensor_dump():
|
||||
status = 1
|
||||
global ipmi_sdr_list
|
||||
ipmi_cmd = IPMI_SENSOR_DATA
|
||||
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd)
|
||||
status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
|
||||
|
||||
if status:
|
||||
logging.error('Failed to execute:' + ipmi_sdr_list)
|
||||
@ -130,9 +130,9 @@ for tray in range(1, Z9332F_MAX_FAN_TRAYS + 1):
|
||||
ret_status = 1
|
||||
|
||||
if index == 1:
|
||||
status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU1_DATA_DOCKER)
|
||||
status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU1_DATA_DOCKER, awk_cmd)
|
||||
elif index == 2:
|
||||
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput(IPMI_PSU2_DATA_DOCKER)
|
||||
ret_status, ipmi_cmd_ret = getstatusoutput_noshell_pipe(IPMI_PSU2_DATA_DOCKER, awk_cmd)
|
||||
|
||||
#if ret_status:
|
||||
# print ipmi_cmd_ret
|
||||
|
@ -18,6 +18,7 @@ try:
|
||||
import tempfile
|
||||
from sonic_platform_base.component_base import ComponentBase
|
||||
import sonic_platform.hwaccess as hwaccess
|
||||
from sonic_py_common.general import check_output_pipe
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
@ -161,10 +162,10 @@ class Component(ComponentBase):
|
||||
return False, "ERROR: File not found"
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
cmd = "sed -e '1,/^exit_marker$/d' {} | tar -x -C {} installer/onie-update.tar.xz".format(image_path, tmpdir)
|
||||
cmd1 = ["sed", "-e", '1,/^exit_marker$/d', image_path]
|
||||
cmd2 = ["tar", "-x", "-C", tmpdir, "installer/onie-update.tar.xz"]
|
||||
try:
|
||||
subprocess.check_call(cmd, stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL, shell=True)
|
||||
check_output_pipe(cmd1, cmd2)
|
||||
except subprocess.CalledProcessError:
|
||||
return False, "ERROR: Unable to extract firmware updater"
|
||||
|
||||
@ -200,18 +201,18 @@ class Component(ComponentBase):
|
||||
@staticmethod
|
||||
def _stage_firmware_package(image_path):
|
||||
stage_msg = None
|
||||
cmd = "onie_stage_fwpkg -a {}".format(image_path)
|
||||
cmd = ["onie_stage_fwpkg", "-a", image_path]
|
||||
try:
|
||||
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT, text=True)
|
||||
subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
if e.returncode != 2:
|
||||
return False, e.output.strip()
|
||||
else:
|
||||
stage_msg = e.output.strip()
|
||||
|
||||
cmd = "onie_mode_set -o update"
|
||||
cmd = ["onie_mode_set", "-o", "update"]
|
||||
try:
|
||||
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT, text=True)
|
||||
subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
return False, e.output.strip()
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
try:
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
import mmap
|
||||
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
|
||||
|
||||
@ -335,7 +334,6 @@ class Sfp(SfpOptoeBase):
|
||||
self._port_to_i2c_mapping[self.index])
|
||||
driver_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/name".format(
|
||||
self._port_to_i2c_mapping[self.index])
|
||||
delete_device = "echo 0x50 >" + del_sfp_path
|
||||
|
||||
if not os.path.isfile(driver_path):
|
||||
print(driver_path, "does not exist")
|
||||
@ -349,22 +347,25 @@ class Sfp(SfpOptoeBase):
|
||||
|
||||
#Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
|
||||
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe2 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe2 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe1 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe1 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe3 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe3 0x50\n')
|
||||
time.sleep(2)
|
||||
|
||||
except IOError as err:
|
||||
|
@ -12,20 +12,20 @@
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import commands
|
||||
from sonic_py_common.general import getstatusoutput_noshell
|
||||
|
||||
Z9432F_MAX_FAN_TRAYS = 7
|
||||
Z9432F_MAX_PSUS = 2
|
||||
IPMI_SENSOR_DATA = "ipmitool sdr elist"
|
||||
IPMI_SENSOR_DATA = ["ipmitool", "sdr", "elist"]
|
||||
|
||||
IPMI_RAW_STORAGE_READ = "ipmitool raw 0x0a 0x11 {0} {1} 0 1"
|
||||
IPMI_RAW_STORAGE_READ = ["ipmitool", "raw", "0x0a", "0x11", "", "", "0", "1"]
|
||||
|
||||
# Dump sensor registers
|
||||
class SdrStatus(object):
|
||||
""" Contains IPMI SDR List """
|
||||
def __init__(self):
|
||||
ipmi_cmd = IPMI_SENSOR_DATA
|
||||
status, resp = commands.getstatusoutput(ipmi_cmd)
|
||||
status, resp = getstatusoutput_noshell(ipmi_cmd)
|
||||
if status:
|
||||
logging.error('Failed to execute: ' + ipmi_cmd)
|
||||
sys.exit(0)
|
||||
@ -43,14 +43,6 @@ class SdrStatus(object):
|
||||
|
||||
# Fetch a Fan Status
|
||||
SDR_STATUS = SdrStatus()
|
||||
def get_fan_status(fan_id):
|
||||
""" Get Fan Status of give Id """
|
||||
status, cmd_ret = commands.getstatusoutput(IPMI_FAN_PRESENCE.format(fan_id))
|
||||
if status:
|
||||
logging.error('Failed to execute : %s', IPMI_FAN_PRESENCE.format(fan_id))
|
||||
sys.exit(0)
|
||||
return ' ' + cmd_ret.splitlines()[5].strip(' ').strip('[]')
|
||||
|
||||
# Fetch a BMC register
|
||||
|
||||
|
||||
@ -62,7 +54,7 @@ def get_pmc_register(reg_name):
|
||||
if reg_name in sdr_status:
|
||||
output = sdr_status[reg_name]
|
||||
else:
|
||||
print '\nFailed to fetch: ' + reg_name + ' sensor '
|
||||
print('\nFailed to fetch: ' + reg_name + ' sensor ')
|
||||
sys.exit(0)
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
@ -71,9 +63,11 @@ def get_pmc_register(reg_name):
|
||||
# Fetch FRU on given offset
|
||||
def fetch_raw_fru(dev_id, offset):
|
||||
""" Fetch RAW value from FRU (dev_id) @ given offset """
|
||||
status, cmd_ret = commands.getstatusoutput(IPMI_RAW_STORAGE_READ.format(dev_id, offset))
|
||||
IPMI_RAW_STORAGE_READ[4] = str(dev_id)
|
||||
IPMI_RAW_STORAGE_READ[5] = offset
|
||||
status, cmd_ret = getstatusoutput_noshell(IPMI_RAW_STORAGE_READ)
|
||||
if status:
|
||||
logging.error('Failed to execute ipmitool :' + IPMI_RAW_STORAGE_READ.format(dev_id, offset))
|
||||
logging.error('Failed to execute ipmitool :' + ' '.join(IPMI_RAW_STORAGE_READ))
|
||||
return -1
|
||||
return int(cmd_ret.strip().split(' ')[1])
|
||||
|
||||
@ -83,7 +77,7 @@ def fetch_raw_fru(dev_id, offset):
|
||||
def get_fan_airflow(fan_id):
|
||||
""" Return Airflow of direction of FANTRAY(fan_id) """
|
||||
airflow_direction = ['Exhaust', 'Intake']
|
||||
dir_idx = fetch_raw_fru(fan_id+2, 0x45)
|
||||
dir_idx = fetch_raw_fru(fan_id+2, "0x45")
|
||||
if dir_idx == -1:
|
||||
return 'N/A'
|
||||
return airflow_direction[dir_idx]
|
||||
@ -92,7 +86,7 @@ def get_fan_airflow(fan_id):
|
||||
def get_psu_airflow(psu_id):
|
||||
""" Return Airflow Direction of psu_id """
|
||||
airflow_direction = ['Exhaust', 'Intake']
|
||||
dir_idx = fetch_raw_fru(psu_id, 0x2F)
|
||||
dir_idx = fetch_raw_fru(psu_id, "0x2F")
|
||||
if dir_idx == -1:
|
||||
return 'N/A'
|
||||
return airflow_direction[dir_idx]
|
||||
@ -103,37 +97,39 @@ def get_psu_airflow(psu_id):
|
||||
def print_temperature_sensors():
|
||||
""" Prints Temperature Sensor """
|
||||
|
||||
print "\nOnboard Temperature Sensors:"
|
||||
print("\nOnboard Temperature Sensors:")
|
||||
|
||||
print ' PT Left Temp: ',\
|
||||
(get_pmc_register('PT_Left_temp'))
|
||||
print ' NPU Rear Temp: ',\
|
||||
(get_pmc_register('NPU_Rear_temp'))
|
||||
print ' PT Right Temp: ',\
|
||||
(get_pmc_register('PT_Right_temp'))
|
||||
print ' NPU Front Temp: ',\
|
||||
(get_pmc_register('NPU_Front_temp'))
|
||||
print ' FAN Right Temp: ',\
|
||||
(get_pmc_register('FAN_Right_temp'))
|
||||
print ' NPU Temp: ',\
|
||||
(get_pmc_register('NPU_temp'))
|
||||
print ' CPU Temp: ',\
|
||||
(get_pmc_register('CPU_temp'))
|
||||
print ' PSU1 AF Temp: ',\
|
||||
(get_pmc_register('PSU1_AF_temp'))
|
||||
print ' PSU1 Mid Temp: ',\
|
||||
(get_pmc_register('PSU1_Mid_temp'))
|
||||
print ' PSU1 Rear Temp: ',\
|
||||
(get_pmc_register('PSU1_Rear_temp'))
|
||||
print ' PSU2 AF Temp: ',\
|
||||
(get_pmc_register('PSU2_AF_temp'))
|
||||
print ' PSU2 Mid Temp: ',\
|
||||
(get_pmc_register('PSU2_Mid_temp'))
|
||||
print ' PSU2 Rear Temp: ',\
|
||||
(get_pmc_register('PSU2_Rear_temp'))
|
||||
print(' PT Left Temp: ',\
|
||||
(get_pmc_register('PT_Left_temp')))
|
||||
print(' NPU Rear Temp: ',\
|
||||
(get_pmc_register('NPU_Rear_temp')))
|
||||
print(' PT Right Temp: ',\
|
||||
(get_pmc_register('PT_Right_temp')))
|
||||
print(' NPU Front Temp: ',\
|
||||
(get_pmc_register('NPU_Front_temp')))
|
||||
print(' FAN Right Temp: ',\
|
||||
(get_pmc_register('FAN_Right_temp')))
|
||||
print(' NPU Temp: ',\
|
||||
(get_pmc_register('NPU_temp')))
|
||||
print(' CPU Temp: ',\
|
||||
(get_pmc_register('CPU_temp')))
|
||||
print(' PSU1 AF Temp: ',\
|
||||
(get_pmc_register('PSU1_AF_temp')))
|
||||
print(' PSU1 Mid Temp: ',\
|
||||
(get_pmc_register('PSU1_Mid_temp')))
|
||||
print(' PSU1 Rear Temp: ',\
|
||||
(get_pmc_register('PSU1_Rear_temp')))
|
||||
print(' PSU2 AF Temp: ',\
|
||||
(get_pmc_register('PSU2_AF_temp')))
|
||||
print(' PSU2 Mid Temp: ',\
|
||||
(get_pmc_register('PSU2_Mid_temp')))
|
||||
print(' PSU2 Rear Temp: ',\
|
||||
(get_pmc_register('PSU2_Rear_temp')))
|
||||
|
||||
|
||||
commands.getstatusoutput('echo 0 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us')
|
||||
file = '/sys/module/ipmi_si/parameters/kipmid_max_busy_us'
|
||||
with open(file, 'w') as f:
|
||||
f.write('0\n')
|
||||
|
||||
print_temperature_sensors()
|
||||
|
||||
@ -144,26 +140,26 @@ def print_fan_tray(fan_tray):
|
||||
""" Prints given Fan Tray information """
|
||||
fan_status = ['Abnormal', 'Normal']
|
||||
|
||||
print ' Fan Tray ' + str(fan_tray) + ':'
|
||||
print(' Fan Tray ' + str(fan_tray) + ':')
|
||||
|
||||
fan_front_status = (get_pmc_register('Fan{0}_Front_state'.format(str(fan_tray))) == '')
|
||||
fan_rear_status = (get_pmc_register('Fan{0}_Rear_state'.format(str(fan_tray))) == '')
|
||||
print ' Fan1 Speed: ', \
|
||||
get_pmc_register('FAN{0}_Front_rpm'.format(str(fan_tray)))
|
||||
print ' Fan2 Speed: ',\
|
||||
get_pmc_register('FAN{0}_Rear_rpm'.format(str(fan_tray)))
|
||||
print ' Fan1 State: ', fan_status[fan_front_status]
|
||||
print ' Fan2 State: ', fan_status[fan_rear_status]
|
||||
print ' Airflow: ', get_fan_airflow(fan_tray)
|
||||
print(' Fan1 Speed: ', \
|
||||
get_pmc_register('FAN{0}_Front_rpm'.format(str(fan_tray))))
|
||||
print(' Fan2 Speed: ',\
|
||||
get_pmc_register('FAN{0}_Rear_rpm'.format(str(fan_tray))))
|
||||
print(' Fan1 State: ', fan_status[fan_front_status])
|
||||
print(' Fan2 State: ', fan_status[fan_rear_status])
|
||||
print(' Airflow: ', get_fan_airflow(fan_tray))
|
||||
|
||||
|
||||
print '\nFan Trays:'
|
||||
print('\nFan Trays:')
|
||||
|
||||
for tray in range(1, Z9432F_MAX_FAN_TRAYS + 1):
|
||||
if get_pmc_register('FAN{0}_prsnt'.format(str(tray))) == 'Present':
|
||||
print_fan_tray(tray)
|
||||
else:
|
||||
print ' Fan Tray {}: NOT PRESENT'.format(str(tray))
|
||||
print(' Fan Tray {}: NOT PRESENT'.format(str(tray)))
|
||||
|
||||
def get_psu_status(index):
|
||||
"""
|
||||
@ -188,67 +184,69 @@ def print_psu(psu_id):
|
||||
|
||||
# PSU FAN details
|
||||
if psu_id == 1:
|
||||
print ' PSU1:'
|
||||
print ' AF Temperature: ',\
|
||||
get_pmc_register('PSU1_AF_temp')
|
||||
print ' Mid Temperature: ',\
|
||||
get_pmc_register('PSU1_Mid_temp')
|
||||
print ' Rear Temperature: ',\
|
||||
get_pmc_register('PSU1_Rear_temp')
|
||||
print ' FAN RPM: ',\
|
||||
get_pmc_register('PSU1_rpm')
|
||||
print(' PSU1:')
|
||||
print(' AF Temperature: ',\
|
||||
get_pmc_register('PSU1_AF_temp'))
|
||||
print(' Mid Temperature: ',\
|
||||
get_pmc_register('PSU1_Mid_temp'))
|
||||
print(' Rear Temperature: ',\
|
||||
get_pmc_register('PSU1_Rear_temp'))
|
||||
print(' FAN RPM: ',\
|
||||
get_pmc_register('PSU1_rpm'))
|
||||
|
||||
# PSU input & output monitors
|
||||
print ' Input Voltage: ',\
|
||||
get_pmc_register('PSU1_In_volt')
|
||||
print ' Output Voltage: ',\
|
||||
get_pmc_register('PSU1_Out_volt')
|
||||
print ' Input Power: ',\
|
||||
get_pmc_register('PSU1_In_watt')
|
||||
print ' Output Power: ',\
|
||||
get_pmc_register('PSU1_Out_watt')
|
||||
print ' Input Current: ',\
|
||||
get_pmc_register('PSU1_In_amp')
|
||||
print ' Output Current: ',\
|
||||
get_pmc_register('PSU1_Out_amp')
|
||||
print(' Input Voltage: ',\
|
||||
get_pmc_register('PSU1_In_volt'))
|
||||
print(' Output Voltage: ',\
|
||||
get_pmc_register('PSU1_Out_volt'))
|
||||
print(' Input Power: ',\
|
||||
get_pmc_register('PSU1_In_watt'))
|
||||
print(' Output Power: ',\
|
||||
get_pmc_register('PSU1_Out_watt'))
|
||||
print(' Input Current: ',\
|
||||
get_pmc_register('PSU1_In_amp'))
|
||||
print(' Output Current: ',\
|
||||
get_pmc_register('PSU1_Out_amp'))
|
||||
|
||||
else:
|
||||
|
||||
print ' PSU2:'
|
||||
print ' AF Temperature: ',\
|
||||
get_pmc_register('PSU2_AF_temp')
|
||||
print ' Mid Temperature: ',\
|
||||
get_pmc_register('PSU2_Mid_temp')
|
||||
print ' Rear Temperature: ',\
|
||||
get_pmc_register('PSU2_Rear_temp')
|
||||
print ' FAN RPM: ',\
|
||||
get_pmc_register('PSU2_rpm')
|
||||
print(' PSU2:')
|
||||
print(' AF Temperature: ',\
|
||||
get_pmc_register('PSU2_AF_temp'))
|
||||
print(' Mid Temperature: ',\
|
||||
get_pmc_register('PSU2_Mid_temp'))
|
||||
print(' Rear Temperature: ',\
|
||||
get_pmc_register('PSU2_Rear_temp'))
|
||||
print(' FAN RPM: ',\
|
||||
get_pmc_register('PSU2_rpm'))
|
||||
|
||||
# PSU input & output monitors
|
||||
print ' Input Voltage: ',\
|
||||
get_pmc_register('PSU2_In_volt')
|
||||
print ' Output Voltage: ',\
|
||||
get_pmc_register('PSU2_Out_volt')
|
||||
print ' Input Power: ',\
|
||||
get_pmc_register('PSU2_In_watt')
|
||||
print ' Output Power: ',\
|
||||
get_pmc_register('PSU2_Out_watt')
|
||||
print ' Input Current: ',\
|
||||
get_pmc_register('PSU2_In_amp')
|
||||
print ' Output Current: ',\
|
||||
get_pmc_register('PSU2_Out_amp')
|
||||
print ' Airflow: ',\
|
||||
get_psu_airflow(psu_id)
|
||||
print(' Input Voltage: ',\
|
||||
get_pmc_register('PSU2_In_volt'))
|
||||
print(' Output Voltage: ',\
|
||||
get_pmc_register('PSU2_Out_volt'))
|
||||
print(' Input Power: ',\
|
||||
get_pmc_register('PSU2_In_watt'))
|
||||
print(' Output Power: ',\
|
||||
get_pmc_register('PSU2_Out_watt'))
|
||||
print(' Input Current: ',\
|
||||
get_pmc_register('PSU2_In_amp'))
|
||||
print(' Output Current: ',\
|
||||
get_pmc_register('PSU2_Out_amp'))
|
||||
print(' Airflow: ',\
|
||||
get_psu_airflow(psu_id))
|
||||
|
||||
|
||||
print '\nPSUs:'
|
||||
print('\nPSUs:')
|
||||
for psu in range(1, Z9432F_MAX_PSUS + 1):
|
||||
psu_status = get_psu_status(psu)
|
||||
if psu_status is not None:
|
||||
print ' PSU{0}: {1}'.format(psu, psu_status)
|
||||
print(' PSU{0}: {1}'.format(psu, psu_status))
|
||||
else:
|
||||
print_psu(psu)
|
||||
|
||||
print '\n Total Power: ',\
|
||||
get_pmc_register('PSU_Total_watt')
|
||||
commands.getstatusoutput('echo 1000 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us')
|
||||
print('\n Total Power: ',\
|
||||
get_pmc_register('PSU_Total_watt'))
|
||||
file = '/sys/module/ipmi_si/parameters/kipmid_max_busy_us'
|
||||
with open(file, 'w') as f:
|
||||
f.write('1000\n')
|
||||
|
@ -18,6 +18,7 @@ try:
|
||||
import tempfile
|
||||
from sonic_platform_base.component_base import ComponentBase
|
||||
import sonic_platform.hwaccess as hwaccess
|
||||
from sonic_py_common.general import check_output_pipe
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
@ -135,10 +136,11 @@ class Component(ComponentBase):
|
||||
return False, "ERROR: File not found"
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
cmd = "sed -e '1,/^exit_marker$/d' {} | tar -x -C {} installer/onie-update.tar.xz".format(image_path, tmpdir)
|
||||
cmd1 = ["sed", "-e", '1,/^exit_marker$/d', image_path]
|
||||
cmd2 = ["tar", "-x", "-C", tmpdir, "installer/onie-update.tar.xz"]
|
||||
try:
|
||||
subprocess.check_call(cmd, stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL, shell=True)
|
||||
check_output_pipe(cmd1, cmd2)
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
return False, "ERROR: Unable to extract firmware updater"
|
||||
|
||||
@ -166,18 +168,18 @@ class Component(ComponentBase):
|
||||
@staticmethod
|
||||
def _stage_firmware_package(image_path):
|
||||
stage_msg = None
|
||||
cmd = "onie_stage_fwpkg -a {}".format(image_path)
|
||||
cmd = ["onie_stage_fwpkg", "-a", image_path]
|
||||
try:
|
||||
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT, text=True)
|
||||
subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
if e.returncode != 2:
|
||||
return False, e.output.strip()
|
||||
else:
|
||||
stage_msg = e.output.strip()
|
||||
|
||||
cmd = "onie_mode_set -o update"
|
||||
cmd = ["onie_mode_set", "-o", "update"]
|
||||
try:
|
||||
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT, text=True)
|
||||
subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
return False, e.output.strip()
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
try:
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
import mmap
|
||||
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
|
||||
|
||||
@ -302,7 +301,6 @@ class Sfp(SfpOptoeBase):
|
||||
del_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/delete_device".format(i2c_bus)
|
||||
new_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/new_device".format(i2c_bus)
|
||||
driver_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/name".format(i2c_bus)
|
||||
delete_device = "echo 0x50 >" + del_sfp_path
|
||||
|
||||
if not os.path.isfile(driver_path):
|
||||
print(driver_path, "does not exist")
|
||||
@ -316,22 +314,25 @@ class Sfp(SfpOptoeBase):
|
||||
|
||||
#Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
|
||||
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe2 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe2 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe1 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe1 0x50\n')
|
||||
time.sleep(2)
|
||||
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']:
|
||||
subprocess.Popen(delete_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(del_sfp_path, 'w') as f:
|
||||
f.write('0x50\n')
|
||||
time.sleep(0.2)
|
||||
new_device = "echo optoe3 0x50 >" + new_sfp_path
|
||||
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE)
|
||||
with open(new_sfp_path, 'w') as f:
|
||||
f.write('optoe3 0x50\n')
|
||||
time.sleep(2)
|
||||
|
||||
except IOError as err:
|
||||
|
Loading…
Reference in New Issue
Block a user