[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:
Mai Bui 2023-01-05 19:22:09 -05:00 committed by GitHub
parent ba5c26a16f
commit 06e1a0bc14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 715 additions and 676 deletions

View File

@ -3,10 +3,10 @@
# Platform-specific FAN status interface for SONiC # Platform-specific FAN status interface for SONiC
# #
import commands
import sys 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" DOCKER_SENSORS_CMD = "/usr/bin/sensors"
@ -33,24 +33,23 @@ class FanUtil(FanBase):
return True return True
def get_num_fans(self): def get_num_fans(self):
n3248pxe_MAX_FANTRAYS = 3 n3248pxe_MAX_FANTRAYS = 3
return n3248pxe_MAX_FANTRAYS return n3248pxe_MAX_FANTRAYS
def get_presence(self, idx): def get_presence(self, idx):
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_prs" sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
return int(open(sysfs_path).read(), 16) return int(open(sysfs_path).read(), 16)
def get_direction(self, idx): def get_direction(self, idx):
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_dir" sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_dir"
return open(sysfs_path).read() return open(sysfs_path).read()
def get_speed(self, idx): def get_speed(self, idx):
dockerenv = self.isDockerEnv() dockerenv = self.isDockerEnv()
if not dockerenv: if not dockerenv:
status, cmd_output = commands.getstatusoutput(SENSORS_CMD) status, cmd_output = getstatusoutput_noshell(SENSORS_CMD)
else : else:
status, cmd_output = commands.getstatusoutput(DOCKER_SENSORS_CMD) status, cmd_output = getstatusoutput_noshell(DOCKER_SENSORS_CMD)
if status: if status:
print('Failed to execute sensors command') print('Failed to execute sensors command')
sys.exit(0) sys.exit(0)
@ -64,9 +63,9 @@ class FanUtil(FanBase):
return 0.0 return 0.0
def get_status(self, idx): def get_status(self, idx):
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_prs" sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
return int(open(sysfs_path).read(), 16) return int(open(sysfs_path).read(), 16)
def set_speed(self, idx): def set_speed(self, idx):
return False return False

View File

@ -3,11 +3,11 @@
# Platform-specific PSU status interface for SONiC # Platform-specific PSU status interface for SONiC
# #
import commands
import os import os
import sys 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" DOCKER_SENSORS_CMD = "/usr/bin/sensors"
try: try:
@ -95,10 +95,9 @@ class PsuUtil(PsuBase):
def get_sensor(self): def get_sensor(self):
dockerenv = self.isDockerEnv() dockerenv = self.isDockerEnv()
if not dockerenv: if not dockerenv:
status, cmd_output = commands.getstatusoutput(SENSORS_CMD) status, cmd_output = getstatusoutput_noshell(SENSORS_CMD)
else : else:
status, cmd_output = commands.getstatusoutput(DOCKER_SENSORS_CMD) status, cmd_output = getstatusoutput_noshell(DOCKER_SENSORS_CMD)
if status: if status:
print('Failed to execute sensors command') print('Failed to execute sensors command')
sys.exit(0) sys.exit(0)

View File

@ -3,10 +3,10 @@
# Platform-specific FAN status interface for SONiC # Platform-specific FAN status interface for SONiC
# #
import subprocess
import sys 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" DOCKER_SENSORS_CMD = "/usr/bin/sensors"
@ -33,24 +33,23 @@ class FanUtil(FanBase):
return True return True
def get_num_fans(self): def get_num_fans(self):
N3248TE_MAX_FANTRAYS = 3 N3248TE_MAX_FANTRAYS = 3
return N3248TE_MAX_FANTRAYS return N3248TE_MAX_FANTRAYS
def get_presence(self, idx): def get_presence(self, idx):
sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_prs" sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
return int(open(sysfs_path).read(), 16) return int(open(sysfs_path).read(), 16)
def get_direction(self, idx): def get_direction(self, idx):
sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_dir" sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_dir"
return open(sysfs_path).read() return open(sysfs_path).read()
def get_speed(self, idx): def get_speed(self, idx):
dockerenv = self.isDockerEnv() dockerenv = self.isDockerEnv()
if not dockerenv: if not dockerenv:
status, cmd_output = subprocess.getstatusoutput(SENSORS_CMD) status, cmd_output = getstatusoutput_noshell(SENSORS_CMD)
else : else:
status, cmd_output = subprocess.getstatusoutput(DOCKER_SENSORS_CMD) status, cmd_output = getstatusoutput_noshell(DOCKER_SENSORS_CMD)
if status: if status:
print('Failed to execute sensors command') print('Failed to execute sensors command')
sys.exit(0) sys.exit(0)
@ -64,9 +63,9 @@ class FanUtil(FanBase):
return 0.0 return 0.0
def get_status(self, idx): def get_status(self, idx):
sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_prs" sysfs_path = "/sys/devices/platform/dell-n3248te-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
return int(open(sysfs_path).read(), 16) return int(open(sysfs_path).read(), 16)
def set_speed(self, idx): def set_speed(self, idx):
return False return False

View File

@ -3,11 +3,11 @@
# Platform-specific PSU status interface for SONiC # Platform-specific PSU status interface for SONiC
# #
import commands
import os import os
import sys 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" DOCKER_SENSORS_CMD = "/usr/bin/sensors"
try: try:
@ -95,10 +95,9 @@ class PsuUtil(PsuBase):
def get_sensor(self): def get_sensor(self):
dockerenv = self.isDockerEnv() dockerenv = self.isDockerEnv()
if not dockerenv: if not dockerenv:
status, cmd_output = commands.getstatusoutput(SENSORS_CMD) status, cmd_output = getstatusoutput_noshell(SENSORS_CMD)
else : else:
status, cmd_output = commands.getstatusoutput(DOCKER_SENSORS_CMD) status, cmd_output = getstatusoutput_noshell(DOCKER_SENSORS_CMD)
if status: if status:
print('Failed to execute sensors command') print('Failed to execute sensors command')
sys.exit(0) sys.exit(0)

View File

@ -5,11 +5,11 @@
import logging import logging
import sys import sys
import subprocess from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
S5212F_MAX_PSUS = 2 S5212F_MAX_PSUS = 2
IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" IPMI_PSU_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "sdr", "list"]
IPMI_PSU_DATA_DOCKER = "ipmitool sdr list" IPMI_PSU_DATA_DOCKER = ["ipmitool", "sdr", "list"]
PSU_PRESENCE = "PSU{0}_stat" PSU_PRESENCE = "PSU{0}_stat"
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
@ -44,7 +44,7 @@ class PsuUtil(PsuBase):
if dockerenv == True: if dockerenv == True:
ipmi_cmd = IPMI_PSU_DATA_DOCKER ipmi_cmd = IPMI_PSU_DATA_DOCKER
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute:' + ipmi_sdr_list) 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 :param index: An integer, index of the PSU of which to query status
:return: Boolean, True if PSU is plugged, False if not :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 return 1 if psu_status == '1' else 0

View File

@ -6,7 +6,7 @@
import logging import logging
import sys import sys
import subprocess from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
S5224F_MAX_PSUS = 2 S5224F_MAX_PSUS = 2
IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list"
@ -45,7 +45,7 @@ class PsuUtil(PsuBase):
if dockerenv == True: if dockerenv == True:
ipmi_cmd = IPMI_PSU_DATA_DOCKER ipmi_cmd = IPMI_PSU_DATA_DOCKER
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute:' + ipmi_sdr_list) 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 :param index: An integer, index of the PSU of which to query status
:return: Boolean, True if PSU is plugged, False if not :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 return 1 if psu_status == '1' else 0

View File

@ -4,22 +4,17 @@
# #
import os.path
import logging import logging
import sys import sys
from sonic_py_common.general import getstatusoutput_noshell_pipe
if sys.version_info[0] < 3:
import commands
else:
import subprocess as commands
S5232F_MAX_PSUS = 2 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", "exec", "-it", "pmon", "ipmitool", "raw", "0x04", "0x2d", "0x31"]
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x31 | awk '{print substr($0,9,1)}'" IPMI_PSU1_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x31"]
IPMI_PSU2_DATA = "docker exec -it pmon ipmitool raw 0x04 0x2d 0x32 | awk '{print substr($0,9,1)}'" IPMI_PSU2_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "raw", "0x04", "0x2d", "0x32"]
IPMI_PSU2_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x32 | awk '{print substr($0,9,1)}'" IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x32"]
PSU_PRESENCE = "PSU{0}_stat" PSU_PRESENCE = "PSU{0}_stat"
awk_cmd = ['awk', '{print substr($0,9,1)}']
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
@ -44,23 +39,24 @@ class PsuUtil(PsuBase):
return False return False
# Fetch a BMC register # Fetch a BMC register
def get_pmc_register(self, reg_name): def get_pmc_register(self, index):
status = 1 status = 1
ipmi_cmd_1 = IPMI_PSU1_DATA ipmi_cmd = ''
ipmi_cmd_2 = IPMI_PSU1_DATA
dockerenv = self.isDockerEnv() dockerenv = self.isDockerEnv()
if dockerenv == True: if dockerenv == True:
if index == 1: if index == 1:
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) ipmi_cmd = IPMI_PSU1_DATA_DOCKER
elif index == 2: elif index == 2:
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) ipmi_cmd = IPMI_PSU2_DATA_DOCKER
else: else:
if index == 1: if index == 1:
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) ipmi_cmd = IPMI_PSU1_DATA
elif index == 2: 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: if status:
logging.error('Failed to execute ipmitool') logging.error('Failed to execute ipmitool')
sys.exit(0) sys.exit(0)
@ -87,22 +83,25 @@ class PsuUtil(PsuBase):
""" """
# Until psu_status is implemented this is hardcoded temporarily # Until psu_status is implemented this is hardcoded temporarily
psu_status = 'f' psu_status = ''
ret_status = 1 ret_status = 1
ipmi_cmd = ''
dockerenv = self.isDockerEnv() dockerenv = self.isDockerEnv()
if dockerenv == True: if dockerenv == True:
if index == 1: if index == 1:
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) ipmi_cmd = IPMI_PSU1_DATA_DOCKER
elif index == 2: elif index == 2:
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) ipmi_cmd = IPMI_PSU2_DATA_DOCKER
else: else:
if index == 1: if index == 1:
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) ipmi_cmd = IPMI_PSU1_DATA
elif index == 2: 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: if ret_status:
logging.error('Failed to execute ipmitool : ') logging.error('Failed to execute ipmitool')
sys.exit(0) sys.exit(0)
psu_status = ipmi_sdr_list psu_status = ipmi_sdr_list
@ -117,20 +116,23 @@ class PsuUtil(PsuBase):
""" """
psu_status = '0' psu_status = '0'
ret_status = 1 ret_status = 1
ipmi_cmd = ''
dockerenv = self.isDockerEnv() dockerenv = self.isDockerEnv()
if dockerenv == True: if dockerenv == True:
if index == 1: if index == 1:
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) ipmi_cmd = IPMI_PSU1_DATA_DOCKER
elif index == 2: elif index == 2:
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) ipmi_cmd = IPMI_PSU2_DATA_DOCKER
else: else:
if index == 1: if index == 1:
ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) ipmi_cmd = IPMI_PSU1_DATA
elif index == 2: 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: if ret_status:
logging.error('Failed to execute ipmitool : ') logging.error('Failed to execute ipmitool')
sys.exit(0) sys.exit(0)
psu_status = ipmi_sdr_list psu_status = ipmi_sdr_list

View File

@ -4,19 +4,14 @@
# #
import os.path
import logging import logging
import sys import sys
from sonic_py_common.general import getstatusoutput_noshell
if sys.version_info[0] < 3:
import commands
else:
import subprocess as commands
S5248F_MAX_PSUS = 2 S5248F_MAX_PSUS = 2
IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" IPMI_PSU_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "sdr", "list"]
IPMI_PSU_DATA_DOCKER = "ipmitool sdr list" IPMI_PSU_DATA_DOCKER = ["ipmitool", "sdr", "list"]
PSU_PRESENCE = "PSU{0}_stat" PSU_PRESENCE = "PSU{0}_stat"
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
@ -53,7 +48,7 @@ class PsuUtil(PsuBase):
if dockerenv == True: if dockerenv == True:
ipmi_cmd = IPMI_PSU_DATA_DOCKER ipmi_cmd = IPMI_PSU_DATA_DOCKER
status, ipmi_sdr_list = commands.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute:' + ipmi_sdr_list) logging.error('Failed to execute:' + ipmi_sdr_list)

View File

@ -6,16 +6,12 @@
import logging import logging
import sys import sys
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
if sys.version_info[0] < 3:
import commands
else:
import subprocess as commands
S5296F_MAX_PSUS = 2 S5296F_MAX_PSUS = 2
IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" IPMI_PSU_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "sdr", "list"]
IPMI_PSU_DATA_DOCKER = "ipmitool sdr list" IPMI_PSU_DATA_DOCKER = ["ipmitool", "sdr", "list"]
PSU_PRESENCE = "PSU{0}_stat" PSU_PRESENCE = "PSU{0}_stat"
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
@ -50,7 +46,7 @@ class PsuUtil(PsuBase):
if dockerenv == True: if dockerenv == True:
ipmi_cmd = IPMI_PSU_DATA_DOCKER ipmi_cmd = IPMI_PSU_DATA_DOCKER
status, ipmi_sdr_list = commands.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute:' + ipmi_sdr_list) 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 :param index: An integer, index of the PSU of which to query status
:return: Boolean, True if PSU is plugged, False if not :return: Boolean, True if PSU is plugged, False if not
""" """
cmd_status, psu_status = commands.getstatusoutput( ipmi_cmd = ["ipmitool", "raw", "0x04", "0x2d", hex(0x30 + index)]
'ipmitool raw 0x04 0x2d ' + hex(0x30 + index) + " | awk '{print substr($0,9,1)}'") 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 return 1 if psu_status == '1' else 0

View File

@ -4,19 +4,14 @@
# #
import os.path
import logging import logging
import sys import sys
from sonic_py_common.general import getstatusoutput_noshell
if sys.version_info[0] < 3:
import commands
else:
import subprocess as commands
Z9264F_MAX_PSUS = 2 Z9264F_MAX_PSUS = 2
IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" IPMI_PSU_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "sdr", "list"]
IPMI_PSU_DATA_DOCKER = "ipmitool sdr list" IPMI_PSU_DATA_DOCKER = ["ipmitool", "sdr", "list"]
PSU_PRESENCE = "PSU{0}_state" PSU_PRESENCE = "PSU{0}_state"
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
@ -53,7 +48,7 @@ class PsuUtil(PsuBase):
if dockerenv == True: if dockerenv == True:
ipmi_cmd = IPMI_PSU_DATA_DOCKER ipmi_cmd = IPMI_PSU_DATA_DOCKER
status, ipmi_sdr_list = commands.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute:' + ipmi_sdr_list) logging.error('Failed to execute:' + ipmi_sdr_list)

View File

@ -4,25 +4,21 @@
# #
import os.path
import logging import logging
import sys import sys
from sonic_py_common.general import getstatusoutput_noshell_pipe
if sys.version_info[0] < 3:
import commands
else:
import subprocess as commands
Z9332F_MAX_PSUS = 2 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", "exec", "-it", "pmon", "ipmitool", "raw", "0x04", "0x2d", "0x2f"]
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x2f | awk '{print substr($0,9,1)}'" IPMI_PSU1_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x2f"]
IPMI_PSU2_DATA = "docker exec -it pmon ipmitool raw 0x04 0x2d 0x39 | awk '{print substr($0,9,1)}'" IPMI_PSU2_DATA = ["docker", "exec", "-it", "pmon", "ipmitool", "raw", "0x04", "0x2d", "0x39"]
IPMI_PSU2_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x39 | awk '{print substr($0,9,1)}'" IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x39"]
PSU_PRESENCE = "PSU{0}_Status" PSU_PRESENCE = "PSU{0}_Status"
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
ipmi_sdr_list = "" ipmi_sdr_list = ""
awk_cmd = ['awk', '{print substr($0,9,1)}']
try: try:
@ -46,28 +42,24 @@ class PsuUtil(PsuBase):
# Fetch a BMC register # Fetch a BMC register
def get_pmc_register(self, reg_name): def get_pmc_register(self, reg_name):
status = 1
global ipmi_sdr_list global ipmi_sdr_list
ipmi_dev_node = "/dev/pmi0" ipmi_cmd = ''
ipmi_cmd_1 = IPMI_PSU1_DATA
ipmi_cmd_2 = IPMI_PSU1_DATA
dockerenv = self.isDockerEnv() dockerenv = self.isDockerEnv()
if dockerenv == True: if dockerenv == True:
if index == 1: if index == 1:
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) ipmi_cmd = IPMI_PSU1_DATA_DOCKER
elif index == 2: elif index == 2:
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) ipmi_cmd = IPMI_PSU2_DATA_DOCKER
else: else:
if index == 1: if index == 1:
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) ipmi_cmd = IPMI_PSU1_DATA
elif index == 2: elif index == 2:
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) ipmi_cmd = IPMI_PSU2_DATA
if ipmi_cmd != '':
if status: status, ipmi_sdr_list = getstatusoutput_noshell_pipe(ipmi_cmd, awk_cmd)
logging.error('Failed to execute ipmitool') if status:
sys.exit(0) logging.error('Failed to execute ipmitool')
sys.exit(0)
output = ipmi_sdr_list output = ipmi_sdr_list
return output return output
@ -100,22 +92,23 @@ class PsuUtil(PsuBase):
:param index: An integer, index of the PSU of which to query status :param index: An integer, index of the PSU of which to query status
:return: Boolean, True if PSU is plugged, False if not :return: Boolean, True if PSU is plugged, False if not
""" """
ipmi_cmd = ''
status = 0 status = 0
ret_status = 1 # ret_status = 1
global ipmi_sdr_list global ipmi_sdr_list
ipmi_dev_node = "/dev/pmi0"
dockerenv = self.isDockerEnv() dockerenv = self.isDockerEnv()
if dockerenv == True: if dockerenv == True:
if index == 1: if index == 1:
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) ipmi_cmd = IPMI_PSU1_DATA_DOCKER
elif index == 2: elif index == 2:
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) ipmi_cmd = IPMI_PSU2_DATA_DOCKER
else: else:
if index == 1: if index == 1:
status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) ipmi_cmd = IPMI_PSU1_DATA
elif index == 2: 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: # if ret_status:
# print ipmi_sdr_list # print ipmi_sdr_list
# logging.error('Failed to execute ipmitool') # logging.error('Failed to execute ipmitool')

View File

@ -7,7 +7,7 @@
# #
############################################################################# #############################################################################
import logging import logging
import commands from sonic_py_common.general import getstatusoutput_noshell
try: try:
from sonic_fan.fan_base import FanBase from sonic_fan.fan_base import FanBase
@ -20,10 +20,10 @@ class FanUtil(FanBase):
NUM_FANS_PERTRAY = 2 NUM_FANS_PERTRAY = 2
FANTRAY_NUM_START_IDX = 1 FANTRAY_NUM_START_IDX = 1
FRU_FAN_START_IDX = 1 FRU_FAN_START_IDX = 1
IPMI_FAN_PRESENCE = "ipmitool sensor get FAN{0}_prsnt" IPMI_FAN_PRESENCE = ["ipmitool", "sensor", "get", ""]
IPMI_FAN_FRONT_SPEED = "ipmitool sdr get Fan{0}_Front_rpm" IPMI_FAN_FRONT_SPEED = ["ipmitool", "sdr", "get", ""]
IPMI_FAN_REAR_SPEED = "ipmitool sdr get Fan{0}_Rear_rpm" IPMI_FAN_REAR_SPEED = ["ipmitool", "sdr", "get", ""]
IPMI_FRU_DATA = "ipmitool fru print {0}" IPMI_FRU_DATA = ["ipmitool", "fru", "print", ""]
def __init__(self, log_level=logging.DEBUG): def __init__(self, log_level=logging.DEBUG):
FanBase.__init__(self) FanBase.__init__(self)
@ -31,59 +31,63 @@ class FanUtil(FanBase):
def get_fan_status(self,fan_id): def get_fan_status(self,fan_id):
try: try:
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_FAN_PRESENCE.format(fan_id)) self.IPMI_FAN_PRESENCE[3] = 'FAN' + str(fan_id) + '_prsnt'
if ret_status == 0: ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_FAN_PRESENCE)
return(ipmi_cmd_ret.splitlines()[5].strip(' ').strip('[]')) if ret_status == 0:
return(ipmi_cmd_ret.splitlines()[5].strip(' ').strip('[]'))
except Exception: 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): def get_front_fan_speed(self,fan_id):
try: try:
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_FAN_FRONT_SPEED.format(fan_id)) self.IPMI_FAN_FRONT_SPEED[3] = 'Fan' + str(fan_id) + '_Front_rpm'
if ret_status == 0: ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_FAN_FRONT_SPEED)
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1] if ret_status == 0:
return rdata rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
return rdata
except Exception: 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): def get_rear_fan_speed(self,fan_id):
try: try:
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_FAN_REAR_SPEED.format(fan_id)) self.IPMI_FAN_REAR_SPEED[3] = 'Fan' + str(fan_id) + '_Rear_rpm'
if ret_status == 0: ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_FAN_REAR_SPEED)
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1] if ret_status == 0:
return rdata rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
return rdata
except Exception: 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 # Read FAN FRU info
def get_fan_direction_from_fru(self,fru_id,reg_name): def get_fan_direction_from_fru(self,fru_id,reg_name):
output = None output = None
try: try:
status, ipmi_fru_list = commands.getstatusoutput(self.IPMI_FRU_DATA.format(fru_id)) self.IPMI_FRU_DATA[3] = str(fru_id)
if status == 0: status, ipmi_fru_list = getstatusoutput_noshell(self.IPMI_FRU_DATA)
for item in ipmi_fru_list.split("\n"): if status == 0:
if reg_name in item: for item in ipmi_fru_list.split("\n"):
output = item.strip() if reg_name in item:
if output is None: output = item.strip()
logging.error('\nFailed to fetch: ' + reg_name + ' sensor ') if output is None:
output = output.split(':')[1].strip(' ') logging.error('\nFailed to fetch: ' + reg_name + ' sensor ')
if output == 'F2B' or output == 'B2F': output = output.split(':')[1].strip(' ')
return output if output == 'F2B' or output == 'B2F':
return output
except Exception: except Exception:
logging.error('Failed to execute:' + ipmi_fru_list) logging.error('Failed to execute:' + ipmi_fru_list)
def get_num_fans(self): def get_num_fans(self):
return self.num_fans return self.num_fans
def get_presence(self, index): def get_presence(self, index):
if index is None: 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: 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) logging.error('Invalid FAN index:%d', index)
return False return False
tray_index = ((index-1)/self.NUM_FANS_PERTRAY) + 1 tray_index = ((index-1)/self.NUM_FANS_PERTRAY) + 1
@ -94,11 +98,11 @@ class FanUtil(FanBase):
def get_status(self, index): def get_status(self, index):
if index is None: 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: 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) logging.error('Invalid FAN index:%d', index)
return False return False
tray_index = ((index-1)/self.NUM_FANS_PERTRAY) + 1 tray_index = ((index-1)/self.NUM_FANS_PERTRAY) + 1
fantray_front_speed=self.get_front_fan_speed(tray_index) fantray_front_speed=self.get_front_fan_speed(tray_index)
@ -112,38 +116,38 @@ class FanUtil(FanBase):
def get_direction(self, index): def get_direction(self, index):
if index is None: 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: 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) logging.error('Invalid FAN index:%d', index)
return None return None
tray_index = ((index-1)/self.NUM_FANS_PERTRAY) tray_index = ((index-1)/self.NUM_FANS_PERTRAY)
fru_id = self.FRU_FAN_START_IDX + tray_index fru_id = self.FRU_FAN_START_IDX + tray_index
direction = self.get_fan_direction_from_fru(fru_id,'Board Extra') direction = self.get_fan_direction_from_fru(fru_id,'Board Extra')
if direction == 'B2F': if direction == 'B2F':
return "INTAKE" return "INTAKE"
elif direction == 'F2B': elif direction == 'F2B':
return "EXHAUST" return "EXHAUST"
else: else:
return None return None
def get_speed(self, index): def get_speed(self, index):
if index is None: 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: 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) logging.error('Invalid FAN index:%d', index)
return 0 return 0
tray_index = ((index-1)/self.NUM_FANS_PERTRAY) + 1 tray_index = ((index-1)/self.NUM_FANS_PERTRAY) + 1
if (index % 2 != 0): if (index % 2 != 0):
fantray_speed=self.get_front_fan_speed(tray_index) fantray_speed=self.get_front_fan_speed(tray_index)
else: 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): if (self.get_presence(index) == True):
return int(fantray_speed.strip()) return int(fantray_speed.strip())

View File

@ -3,7 +3,7 @@
# Platform-specific PSU status interface for SONiC # Platform-specific PSU status interface for SONiC
# #
import logging import logging
import commands from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
Z9332F_MAX_PSUS = 2 Z9332F_MAX_PSUS = 2
FRU_PSUL = 11 FRU_PSUL = 11
@ -18,14 +18,15 @@ except ImportError as e:
class PsuUtil(PsuBase): class PsuUtil(PsuBase):
"""Platform-specific PSUutil class""" """Platform-specific PSUutil class"""
IPMI_PSU1_DATA = "ipmitool raw 0x04 0x2d 0x2f | awk '{print substr($0,9,1)}'" IPMI_PSU1_DATA = ["ipmitool", "raw", "0x04", "0x2d", "0x2f"]
IPMI_PSU2_DATA = "ipmitool raw 0x04 0x2d 0x39 | awk '{print substr($0,9,1)}'" IPMI_PSU2_DATA = ["ipmitool", "raw", "0x04", "0x2d", "0x39"]
IPMI_PSU_VOUT = "ipmitool sdr get PSU{0}_VOut" IPMI_PSU_VOUT = ["ipmitool", "sdr", "get", ""]
IPMI_PSU_POUT = "ipmitool sdr get PSU{0}_POut" IPMI_PSU_POUT = ["ipmitool", "sdr", "get", ""]
IPMI_PSU_COUT = "ipmitool sdr get PSU{0}_COut" IPMI_PSU_COUT = ["ipmitool", "sdr", "get", ""]
IPMI_PSU_FAN_SPEED = "ipmitool sdr get PSU{0}_Fan" IPMI_PSU_FAN_SPEED = ["ipmitool", "sdr", "get", ""]
IPMI_FRU = "ipmitool fru" IPMI_FRU = ["ipmitool", "fru"]
IPMI_FRU_DATA = "ipmitool fru print {0}" IPMI_FRU_DATA = ["ipmitool", "fru", "print", ""]
awk_cmd = ['awk', '{print substr($0,9,1)}']
def __init__(self): def __init__(self):
PsuBase.__init__(self) PsuBase.__init__(self)
@ -39,62 +40,66 @@ class PsuUtil(PsuBase):
def get_psu_vout(self,index): def get_psu_vout(self,index):
try: try:
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_PSU_VOUT.format(index)) self.IPMI_PSU_VOUT[3] = 'PSU' + str(index) + '_VOut'
if ret_status == 0: ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_PSU_VOUT)
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1] if ret_status == 0:
return rdata rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
return rdata
except Exception: 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): def get_psu_cout(self,index):
try: try:
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_PSU_COUT.format(index)) self.IPMI_PSU_COUT[3] = 'PSU' + str(index) + 'POut'
if ret_status == 0: ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_PSU_COUT)
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1] if ret_status == 0:
return rdata rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
return rdata
except Exception: 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): def get_psu_pout(self,index):
try: try:
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_PSU_POUT.format(index)) self.IPMI_PSU_POUT[3] = 'PSU' + str(index) + '_COut'
if ret_status == 0: ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_PSU_POUT)
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1] if ret_status == 0:
return rdata rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
return rdata
except Exception: 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): def get_psu_fan_speed(self,index):
try: try:
ret_status, ipmi_cmd_ret = commands.getstatusoutput(self.IPMI_PSU_FAN_SPEED.format(index)) self.IPMI_PSU_FAN_SPEED[3] = 'PSU' + str(index) + '_Fan'
if ret_status == 0: ret_status, ipmi_cmd_ret = getstatusoutput_noshell(self.IPMI_PSU_FAN_SPEED)
rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1] if ret_status == 0:
return rdata rdata = ipmi_cmd_ret.splitlines()[3].split(':')[1].split(' ')[1]
return rdata
except Exception: 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 #Fetch FRU Data for given fruid
def get_psu_airflow(self, index): def get_psu_airflow(self, index):
if index == 1: if index == 1:
fru_id = 'FRU_PSUL' fru_id = 'FRU_PSUL'
else: 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: if ret_status:
logging.error('Failed to execute ipmitool: '+ self.IPMI_FRU) logging.error('Failed to execute ipmitool: '+ self.IPMI_FRU)
found_fru = False found_fru = False
for line in ipmi_cmd_ret.splitlines(): for line in ipmi_cmd_ret.splitlines():
if line.startswith('FRU Device Description') and fru_id in line.split(':')[1] : 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 '): 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 '' return ''
# Read FRU info # Read FRU info
@ -102,21 +107,22 @@ class PsuUtil(PsuBase):
output = None output = None
Found = False Found = False
try: try:
status, ipmi_fru_list = commands.getstatusoutput(self.IPMI_FRU_DATA.format(fru_id)) self.IPMI_FRU_DATA[3] = str(fru_id)
if status == 0: status, ipmi_fru_list = getstatusoutput_noshell(self.IPMI_FRU_DATA)
for item in ipmi_fru_list.split("\n"): if status == 0:
if reg_name == item.split(':')[0].strip(' '): for item in ipmi_fru_list.split("\n"):
output = item.strip() if reg_name == item.split(':')[0].strip(' '):
output = output.split(':')[1] output = item.strip()
Found = True output = output.split(':')[1]
break; Found = True
break;
if not Found: if not Found:
logging.error('\nFailed to fetch: ' + reg_name + ' sensor ') logging.error('\nFailed to fetch: ' + reg_name + ' sensor ')
return output return output
except Exception: except Exception:
logging.error('Failed to execute:' + ipmi_fru_list) logging.error('Failed to execute:' + ipmi_fru_list)
def get_num_psus(self): def get_num_psus(self):
""" """
@ -135,17 +141,18 @@ class PsuUtil(PsuBase):
faulty faulty
""" """
psu_status = '0' psu_status = '0'
ipmi_cmd = ''
if index == 1: if index == 1:
cmd_status, psu_status = commands.getstatusoutput(self.IPMI_PSU1_DATA) ipmi_cmd = self.IPMI_PSU1_DATA
elif index == 2: elif index == 2:
cmd_status, psu_status = commands.getstatusoutput(self.IPMI_PSU2_DATA) ipmi_cmd = self.IPMI_PSU2_DATA
else: else:
logging.error("Invalid PSU number:" + index) logging.error("Invalid PSU number:" + index)
if cmd_status:
logging.error('Failed to execute ipmitool')
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) return (not int(psu_status, 16) > 1)
def get_psu_presence(self, index): 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 :param index: An integer, index of the PSU of which to query status
:return: Boolean, True if PSU is plugged, False if not :return: Boolean, True if PSU is plugged, False if not
""" """
psu_status = '0'
psu_status = '0'
ipmi_cmd = ''
if index == 1: if index == 1:
cmd_status, psu_status = commands.getstatusoutput(self.IPMI_PSU1_DATA) ipmi_cmd = self.IPMI_PSU1_DATA
elif index == 2: elif index == 2:
cmd_status, psu_status = commands.getstatusoutput(self.IPMI_PSU2_DATA) ipmi_cmd = self.IPMI_PSU2_DATA
else: 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: if cmd_status:
logging.error('Failed to execute ipmitool') logging.error('Failed to execute ipmitool')
return (int(psu_status, 16) & 1) return (int(psu_status, 16) & 1)
def get_output_voltage(self, index): def get_output_voltage(self, index):
if index is None: if index is None:
return 0.0 return 0.0
psuvoltage=self.get_psu_vout(index) psuvoltage=self.get_psu_vout(index)
return float(psuvoltage.strip()) return float(psuvoltage.strip())
def get_output_current(self, index): def get_output_current(self, index):
if index is None: if index is None:
return 0.0 return 0.0
psucurrent=self.get_psu_cout(index) psucurrent=self.get_psu_cout(index)
return float(psucurrent.strip()) return float(psucurrent.strip())
def get_output_power(self, index): def get_output_power(self, index):
if index is None: if index is None:
return 0.0 return 0.0
psupower=self.get_psu_pout(index) psupower=self.get_psu_pout(index)
return float(psupower.strip()) return float(psupower.strip())
def get_fan_rpm(self, index, fan_idx): def get_fan_rpm(self, index, fan_idx):
if index is None: if index is None:
return 0 return 0
fanrpm=self.get_psu_fan_speed(index) fanrpm=self.get_psu_fan_speed(index)
return int(fanrpm.strip()) return int(fanrpm.strip())
def get_serial(self, index): def get_serial(self, index):
if index is None: if index is None:
return None return None
if index == 1: if index == 1:
fru_id = FRU_PSUL fru_id = FRU_PSUL
else: else:
fru_id = FRU_PSUR fru_id = FRU_PSUR
return self.get_fru_info(fru_id,'Board Serial') return self.get_fru_info(fru_id,'Board Serial')
def get_model(self, index): def get_model(self, index):
if index is None: if index is None:
return None return None
if index == 1: if index == 1:
fru_id = FRU_PSUL fru_id = FRU_PSUL
else: else:
fru_id = FRU_PSUR fru_id = FRU_PSUR
return self.get_fru_info(fru_id,'Board Part Number') return self.get_fru_info(fru_id,'Board Part Number')
def get_mfr_id(self, index): def get_mfr_id(self, index):
if index is None: if index is None:
return None return None
if index == 1: if index == 1:
fru_id = FRU_PSUL fru_id = FRU_PSUL
else: else:
fru_id = FRU_PSUR fru_id = FRU_PSUR
return self.get_fru_info(fru_id,'Board Mfg') return self.get_fru_info(fru_id,'Board Mfg')
def get_direction(self, index): def get_direction(self, index):
if index is None: if index is None:
return None return None
direction=self.get_psu_airflow(index).strip() direction=self.get_psu_airflow(index).strip()
if direction == 'B2F': if direction == 'B2F':
return "INTAKE" return "INTAKE"
elif direction == 'F2B': elif direction == 'F2B':
return "EXHAUST" return "EXHAUST"
else: else:
return None return None

View File

@ -19,8 +19,10 @@ def get_bios_version():
return subprocess.check_output(['dmidecode', '-s', 'system-version']).strip().decode() return subprocess.check_output(['dmidecode', '-s', 'system-version']).strip().decode()
def get_cpld_version(cpld): 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() mjr_ver_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/" + cpld + '_mjr_ver'
mnr_ver=subprocess.check_output('cat /sys/devices/platform/dell-n3248pxe-cpld.0/' + cpld + '_mnr_ver', shell=True).strip()[2:].decode() 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)) return (str(mjr_ver) + '.' + str(mnr_ver))
class Component(ComponentBase): class Component(ComponentBase):

View File

@ -61,20 +61,24 @@ class Psu(PsuBase):
def _reload_dps_module(self): def _reload_dps_module(self):
try: try:
del_cmd = "echo 0x56 > /sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1) file = "/sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
os.system(del_cmd) with open(file, 'w') as f:
f.write("0x56\n")
except (IOError, OSError): except (IOError, OSError):
pass pass
try: try:
del_cmd = "echo 0x5e > /sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1) file = "/sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
os.system(del_cmd) with open(file, 'w') as f:
f.write("0x5e\n")
except (IOError, OSError): except (IOError, OSError):
pass pass
try: try:
ins_cmd = "echo '24c02 0x56' > /sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1) file = "/sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1)
os.system(ins_cmd) with open(file, 'w') as f:
ins_cmd = "echo 'dps460 0x5e' > /sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1) f.write('24c02 0x56\n')
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('dps460 0x5e\n')
except (IOError, OSError): except (IOError, OSError):
pass pass

View File

@ -19,8 +19,10 @@ def get_bios_version():
return subprocess.check_output(['dmidecode', '-s', 'system-version']).strip().decode() return subprocess.check_output(['dmidecode', '-s', 'system-version']).strip().decode()
def get_cpld_version(cpld): 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() mjr_ver_path = '/sys/devices/platform/dell-n3248te-cpld.0/' + cpld + '_mjr_ver'
mnr_ver=subprocess.check_output('cat /sys/devices/platform/dell-n3248te-cpld.0/' + cpld + '_mnr_ver', shell=True).strip()[2:].decode() 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)) return (str(mjr_ver) + '.' + str(mnr_ver))
class Component(ComponentBase): class Component(ComponentBase):

View File

@ -63,20 +63,24 @@ class Psu(PsuBase):
def _reload_dps_module(self): def _reload_dps_module(self):
try: try:
del_cmd = "echo 0x56 > /sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1) file = "/sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
os.system(del_cmd) with open(file, 'w') as f:
f.write('0x56\n')
except (IOError, OSError): except (IOError, OSError):
pass pass
try: try:
del_cmd = "echo 0x5e > /sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1) file = "/sys/bus/i2c/devices/i2c-{}/delete_device".format(10 + self.index - 1)
os.system(del_cmd) with open(file, 'w') as f:
f.write('0x5e\n')
except (IOError, OSError): except (IOError, OSError):
pass pass
try: try:
ins_cmd = "echo '24c02 0x56' > /sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1) file = "/sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1)
os.system(ins_cmd) with open(file, 'w') as f:
ins_cmd = "echo 'dps460 0x5e' > /sys/bus/i2c/devices/i2c-{}/new_device".format(10 + self.index - 1) f.write('24c02 0x56\n')
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('dps460 0x5e\n')
except (IOError, OSError): except (IOError, OSError):
pass pass

View File

@ -13,10 +13,10 @@
import sys import sys
import logging import logging
import commands from sonic_py_common.general import getstatusoutput_noshell
S5212F_MAX_FAN_TRAYS = 4 S5212F_MAX_FAN_TRAYS = 4
IPMI_SENSOR_DATA = "ipmitool sdr list" IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
switch_sku = { switch_sku = {
"0K6MG9":(' AC', ' Exhaust'), "0K6MG9":(' AC', ' Exhaust'),
@ -36,7 +36,7 @@ switch_sku = {
"04T94Y":(' DC', ' Intake') "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): def get_pmc_register(reg_name):
if ipmi_status: if ipmi_status:
@ -56,21 +56,21 @@ def print_temperature_sensors():
print("\nOnboard Temperature Sensors:") print("\nOnboard Temperature Sensors:")
print ' PT_Left_temp: ',\ print(' PT_Left_temp: ',\
(get_pmc_register('PT_Left_temp')) (get_pmc_register('PT_Left_temp')))
print ' PT_Mid_temp: ',\ print(' PT_Mid_temp: ',\
(get_pmc_register('PT_Mid_temp')) (get_pmc_register('PT_Mid_temp')))
print ' PT_Right_temp: ',\ print(' PT_Right_temp: ',\
(get_pmc_register('PT_Right_temp')) (get_pmc_register('PT_Right_temp')))
print ' Broadcom Temp: ',\ print(' Broadcom Temp: ',\
(get_pmc_register('NPU_Near_temp')) (get_pmc_register('NPU_Near_temp')))
print ' Inlet Airflow Temp: ',\ print(' Inlet Airflow Temp: ',\
(get_pmc_register('ILET_AF_temp')) (get_pmc_register('ILET_AF_temp')))
print ' CPU Temp: ',\ print(' CPU Temp: ',\
(get_pmc_register('CPU_temp')) (get_pmc_register('CPU_temp')))
def get_switch_details(): 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(): for line in ipmi_fru.splitlines():
info = line.split(':') info = line.split(':')
if 'Board Part Number' in info[0] : if 'Board Part Number' in info[0] :
@ -78,7 +78,9 @@ def get_switch_details():
if (partno in switch_sku): return switch_sku[partno] if (partno in switch_sku): return switch_sku[partno]
return None 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_temperature_sensors()
# Print the information for 1 Fan Tray # Print the information for 1 Fan Tray
@ -86,40 +88,42 @@ print_temperature_sensors()
def print_fan_tray(tray): def print_fan_tray(tray):
print ' Fan Tray ' + str(tray) + ':' print(' Fan Tray ' + str(tray) + ':')
if (tray == 1): if (tray == 1):
print ' Fan1 Speed: ',\ print(' Fan1 Speed: ',\
get_pmc_register('FAN1_Front_rpm') get_pmc_register('FAN1_Front_rpm'))
print ' Fan2 Speed: ',\ print(' Fan2 Speed: ',\
get_pmc_register('FAN1_Rear_rpm') get_pmc_register('FAN1_Rear_rpm'))
elif (tray == 2): elif (tray == 2):
print ' Fan1 Speed: ',\ print(' Fan1 Speed: ',\
get_pmc_register('FAN2_Front_rpm') get_pmc_register('FAN2_Front_rpm'))
print ' Fan2 Speed: ',\ print(' Fan2 Speed: ',\
get_pmc_register('FAN2_Rear_rpm') get_pmc_register('FAN2_Rear_rpm'))
elif (tray == 3): elif (tray == 3):
print ' Fan1 Speed: ',\ print(' Fan1 Speed: ',\
get_pmc_register('FAN3_Front_rpm') get_pmc_register('FAN3_Front_rpm'))
print ' Fan2 Speed: ',\ print(' Fan2 Speed: ',\
get_pmc_register('FAN3_Rear_rpm') get_pmc_register('FAN3_Rear_rpm'))
elif (tray == 4): elif (tray == 4):
print ' Fan1 Speed: ',\ print(' Fan1 Speed: ',\
get_pmc_register('FAN4_Front_rpm') get_pmc_register('FAN4_Front_rpm'))
print ' Fan2 Speed: ',\ print(' Fan2 Speed: ',\
get_pmc_register('FAN4_Rear_rpm') get_pmc_register('FAN4_Rear_rpm'))
type, dir = get_switch_details() type, dir = get_switch_details()
print('\nFan Trays(Fixed):') print('\nFan Trays(Fixed):')
print ' Fan Tray Direction: ', dir print(' Fan Tray Direction: ', dir)
for tray in range(1, S5212F_MAX_FAN_TRAYS + 1): for tray in range(1, S5212F_MAX_FAN_TRAYS + 1):
print_fan_tray(tray) print_fan_tray(tray)
print('\nPSU Tray(Fixed):') print('\nPSU Tray(Fixed):')
print ' PSU Tray Direction: ', dir print(' PSU Tray Direction: ', dir)
print ' PSU Tray Type: ', type 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')

View File

@ -13,7 +13,6 @@ try:
import time import time
import struct import struct
import mmap import mmap
import subprocess
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
except ImportError as e: 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) 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) 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) 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): if not os.path.isfile(driver_path):
print(driver_path, "does not exist") 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. #Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe2 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe2 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe1 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe1 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']: 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) time.sleep(0.2)
new_device = "echo optoe3 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe3 0x50\n')
time.sleep(2) time.sleep(2)
except IOError as e: except IOError as e:

View File

@ -10,25 +10,25 @@
# * FAN trays # * FAN trays
# * PSU # * PSU
import sys import sys
import logging import logging
import subprocess from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
S5224F_MAX_FAN_TRAYS = 4 S5224F_MAX_FAN_TRAYS = 4
S5224F_MAX_PSUS = 2 S5224F_MAX_PSUS = 2
IPMI_SENSOR_DATA = "ipmitool sdr list" IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
IPMI_SENSOR_DUMP = "/tmp/sdr" IPMI_SENSOR_DUMP = "/tmp/sdr"
PSU_PRESENCE = "PSU{0}_stat" PSU_PRESENCE = "PSU{0}_stat"
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
IPMI_FAN_PRESENCE = "ipmitool sensor get FAN{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_PSU1_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x31"]
IPMI_PSU2_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x32 | awk '{print substr($0,9,1)}'" IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x32"]
IPMI_RAW_STORAGE_READ = "ipmitool raw 0x0a 0x11 {0} 0 0 0xa0" awk_cmd = ['awk', '{print substr($0,9,1)}']
IPMI_FRU = "ipmitool fru" IPMI_RAW_STORAGE_READ = ["ipmitool", "raw", "0x0a", "0x11", "", "0", "0", "0xa0"]
IPMI_FRU = ["ipmitool", "fru"]
ipmi_sdr_list = "" ipmi_sdr_list = ""
# Dump sensor registers # Dump sensor registers
@ -38,7 +38,7 @@ def ipmi_sensor_dump():
global ipmi_sdr_list global ipmi_sdr_list
ipmi_cmd = IPMI_SENSOR_DATA ipmi_cmd = IPMI_SENSOR_DATA
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute:' + ipmi_sdr_list) logging.error('Failed to execute:' + ipmi_sdr_list)
@ -47,9 +47,10 @@ def ipmi_sensor_dump():
# Fetch a Fan Status # Fetch a Fan Status
def get_fan_status(fan_id): 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: 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) sys.exit(0)
return(' ' + ipmi_cmd_ret.splitlines()[5].strip(' ').strip('[]')) return(' ' + ipmi_cmd_ret.splitlines()[5].strip(' ').strip('[]'))
@ -75,9 +76,9 @@ def get_pmc_register(reg_name):
#Fetch FRU Data for given fruid #Fetch FRU Data for given fruid
def get_psu_airflow(psu_id): def get_psu_airflow(psu_id):
fru_id = 'PSU' + str(psu_id) + '_fru' 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: if ret_status:
logging.error('Failed to execute ipmitool: '+ IPMI_FRU) logging.error('Failed to execute ipmitool: '+ ' '.join(IPMI_FRU))
sys.exit(0) sys.exit(0)
found_fru = False found_fru = False
for line in ipmi_cmd_ret.splitlines(): for line in ipmi_cmd_ret.splitlines():
@ -89,9 +90,10 @@ def get_psu_airflow(psu_id):
# Fetch FRU on given offset # Fetch FRU on given offset
def fetch_raw_fru(dev_id, 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: 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) sys.exit(0)
return int((ipmi_cmd_ret.splitlines()[int(offset/16)]).split(' ')[(int(offset%16)+1)]) 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: ',\ print (' CPU Temp: ',\
(get_pmc_register('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') file = '/sys/module/ipmi_si/parameters/kipmid_max_busy_us'
if ret_status: 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") logging.error("platform_sensors: Failed to set kipmid_max_busy_us to 0")
ipmi_sensor_dump() ipmi_sensor_dump()
@ -212,12 +217,12 @@ def get_psu_presence(index):
ret_status = 1 ret_status = 1
if index == 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: 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: 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) sys.exit(0)
psu_status = ipmi_cmd_ret psu_status = ipmi_cmd_ret
@ -234,12 +239,12 @@ def get_psu_status(index):
ipmi_cmd_ret = 'f' ipmi_cmd_ret = 'f'
if index == 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: 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: 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) sys.exit(0)
psu_status = ipmi_cmd_ret psu_status = ipmi_cmd_ret
@ -316,6 +321,9 @@ for psu in range(1, S5224F_MAX_PSUS + 1):
print ('\n Total Power: ',\ print ('\n Total Power: ',\
get_pmc_register('PSU_Total_watt')) get_pmc_register('PSU_Total_watt'))
ret_status, ipmi_cmd_ret = subprocess.getstatusoutput('echo 1000 > /sys/module/ipmi_si/parameters/kipmid_max_busy_us') file = '/sys/module/ipmi_si/parameters/kipmid_max_busy_us'
if ret_status: 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") logging.error("platform_sensors: Failed to set kipmid_max_busy_us to 1000")

View File

@ -13,7 +13,6 @@ try:
import time import time
import struct import struct
import mmap import mmap
import subprocess
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
except ImportError as e: 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) 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) 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) 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): if not os.path.isfile(driver_path):
print(driver_path, "does not exist") 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. #Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe2 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe2 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe1 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe1 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']: 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) time.sleep(0.2)
new_device = "echo optoe3 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe3 0x50\n')
time.sleep(2) time.sleep(2)
except IOError as e: except IOError as e:

View File

@ -13,21 +13,23 @@
import sys import sys
import logging import logging
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
S5232F_MAX_FAN_TRAYS = 4 S5232F_MAX_FAN_TRAYS = 4
S5232F_MAX_PSUS = 2 S5232F_MAX_PSUS = 2
IPMI_SENSOR_DATA = "ipmitool sdr list" IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
IPMI_SENSOR_DUMP = "/tmp/sdr" IPMI_SENSOR_DUMP = "/tmp/sdr"
PSU_PRESENCE = "PSU{0}_stat" PSU_PRESENCE = "PSU{0}_stat"
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
IPMI_FAN_PRESENCE = "ipmitool sensor get FAN{0}_prsnt" IPMI_FAN_PRESENCE = ["ipmitool", "sensor", "get", ""]
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x31 | 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 '{print substr($0,9,1)}'" IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x32"]
IPMI_RAW_STORAGE_READ = "ipmitool raw 0x0a 0x11 {0} 0 0 0xa0" awk_cmd = ['awk', '{print substr($0,9,1)}']
IPMI_FRU = "ipmitool fru" IPMI_RAW_STORAGE_READ = ["ipmitool", "raw", "0x0a", "0x11", "", "0", "0", "0xa0"]
IPMI_FRU = ["ipmitool", "fru"]
ipmi_sdr_list = "" ipmi_sdr_list = ""
# Dump sensor registers # Dump sensor registers
@ -38,7 +40,7 @@ def ipmi_sensor_dump():
status = 1 status = 1
global ipmi_sdr_list global ipmi_sdr_list
ipmi_cmd = IPMI_SENSOR_DATA ipmi_cmd = IPMI_SENSOR_DATA
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute: ' + ipmi_sdr_list) logging.error('Failed to execute: ' + ipmi_sdr_list)
@ -47,9 +49,10 @@ def ipmi_sensor_dump():
# Fetch a Fan Status # Fetch a Fan Status
def get_fan_status(fan_id): 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: 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) sys.exit(0)
return(' ' + ipmi_cmd_ret.splitlines()[5].strip(' ').strip('[]')) return(' ' + ipmi_cmd_ret.splitlines()[5].strip(' ').strip('[]'))
@ -75,9 +78,9 @@ def get_pmc_register(reg_name):
# Fetch FRU Data for given fruid # Fetch FRU Data for given fruid
def get_psu_airflow(psu_id): def get_psu_airflow(psu_id):
fru_id = 'PSU' + str(psu_id) + '_fru' 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: if ret_status:
logging.error('Failed to execute ipmitool: ' + IPMI_FRU) logging.error('Failed to execute ipmitool: ' + ' '.join(IPMI_FRU))
sys.exit(0) sys.exit(0)
found_fru = False found_fru = False
for line in ipmi_cmd_ret.splitlines(): for line in ipmi_cmd_ret.splitlines():
@ -89,9 +92,10 @@ def get_psu_airflow(psu_id):
# Fetch FRU on given offset # Fetch FRU on given offset
def fetch_raw_fru(dev_id, 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: 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) sys.exit(0)
return int((ipmi_cmd_ret.splitlines()[offset//16]).split(' ')[(offset%16+1)]) return int((ipmi_cmd_ret.splitlines()[offset//16]).split(' ')[(offset%16+1)])
@ -118,7 +122,9 @@ def print_temperature_sensors():
print(' CPU Temp: ', print(' CPU Temp: ',
get_pmc_register('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() ipmi_sensor_dump()
print_temperature_sensors() print_temperature_sensors()
@ -209,12 +215,12 @@ for tray in range(1, S5232F_MAX_FAN_TRAYS + 1):
ret_status = 1 ret_status = 1
if index == 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: 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: 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) sys.exit(0)
psu_status = ipmi_cmd_ret psu_status = ipmi_cmd_ret
@ -232,12 +238,12 @@ for tray in range(1, S5232F_MAX_FAN_TRAYS + 1):
ipmi_cmd_ret = 'f' ipmi_cmd_ret = 'f'
if index == 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: 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: 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) sys.exit(0)
psu_status = ipmi_cmd_ret psu_status = ipmi_cmd_ret
@ -330,4 +336,6 @@ for psu in range(1, S5232F_MAX_PSUS + 1):
print('\n Total Power: ', print('\n Total Power: ',
get_pmc_register('PSU_Total_watt')) 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')

View File

@ -13,7 +13,6 @@ try:
import time import time
import struct import struct
import mmap import mmap
import subprocess
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
except ImportError as e: 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) 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) 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) 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): if not os.path.isfile(driver_path):
print(driver_path, "does not exist") 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. #Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe2 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe2 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe1 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe1 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']: 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) time.sleep(0.2)
new_device = "echo optoe3 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe3 0x50\n')
time.sleep(2) time.sleep(2)
except IOError as e: except IOError as e:

View File

@ -13,11 +13,11 @@
import sys import sys
import logging import logging
import subprocess from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
S5248F_MAX_FAN_TRAYS = 4 S5248F_MAX_FAN_TRAYS = 4
S5248F_MAX_PSUS = 2 S5248F_MAX_PSUS = 2
IPMI_SENSOR_DATA = "ipmitool sdr list" IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
IPMI_SENSOR_DUMP = "/tmp/sdr" IPMI_SENSOR_DUMP = "/tmp/sdr"
FAN_PRESENCE = "FAN{0}_prsnt" FAN_PRESENCE = "FAN{0}_prsnt"
@ -25,8 +25,9 @@ PSU_PRESENCE = "PSU{0}_stat"
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x31 | 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 '{print substr($0,9,1)}'" IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x32"]
awk_cmd = ['awk', '{print substr($0,9,1)}']
ipmi_sdr_list = "" ipmi_sdr_list = ""
# Dump sensor registers # Dump sensor registers
@ -37,7 +38,7 @@ def ipmi_sensor_dump():
status = 1 status = 1
global ipmi_sdr_list global ipmi_sdr_list
ipmi_cmd = IPMI_SENSOR_DATA ipmi_cmd = IPMI_SENSOR_DATA
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute:' + ipmi_sdr_list) 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 ret_status = 1
if index == 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: 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: #if ret_status:
# print ipmi_cmd_ret # print ipmi_cmd_ret
@ -186,7 +187,7 @@ for tray in range(1, S5248F_MAX_FAN_TRAYS + 1):
psu_status = ipmi_cmd_ret psu_status = ipmi_cmd_ret
if psu_status == '1': if psu_status == '1':
status = 1 status = 1
return status return status

View File

@ -13,7 +13,6 @@ try:
import time import time
import struct import struct
import mmap import mmap
import subprocess
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
except ImportError as e: except ImportError as e:
@ -242,7 +241,7 @@ class Sfp(SfpOptoeBase):
""" """
reset = self.get_reset_status() reset = self.get_reset_status()
if (reset == True): if (reset is True):
status = False status = False
else: else:
status = True status = True
@ -278,7 +277,6 @@ class Sfp(SfpOptoeBase):
del_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/delete_device".format(self.index+1) 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) 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) 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): if not os.path.isfile(driver_path):
print(driver_path, "does not exist") 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. #Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe2 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe2 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe1 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe1 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']: 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) time.sleep(0.2)
new_device = "echo optoe3 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe3 0x50\n')
time.sleep(2) time.sleep(2)
except IOError as e: except IOError as e:

View File

@ -13,11 +13,11 @@
import sys import sys
import logging import logging
import commands from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
S5296F_MAX_FAN_TRAYS = 4 S5296F_MAX_FAN_TRAYS = 4
S5296F_MAX_PSUS = 2 S5296F_MAX_PSUS = 2
IPMI_SENSOR_DATA = "ipmitool sdr list" IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
IPMI_SENSOR_DUMP = "/tmp/sdr" IPMI_SENSOR_DUMP = "/tmp/sdr"
FAN_PRESENCE = "FAN{0}_prsnt" FAN_PRESENCE = "FAN{0}_prsnt"
@ -25,8 +25,9 @@ PSU_PRESENCE = "PSU{0}_stat"
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x31 | 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 '{print substr($0,9,1)}'" IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x32"]
awk_cmd = ['awk', '{print substr($0,9,1)}']
ipmi_sdr_list = "" ipmi_sdr_list = ""
# Dump sensor registers # Dump sensor registers
@ -36,7 +37,7 @@ def ipmi_sensor_dump():
global ipmi_sdr_list global ipmi_sdr_list
ipmi_cmd = IPMI_SENSOR_DATA ipmi_cmd = IPMI_SENSOR_DATA
status, ipmi_sdr_list = commands.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute:' + ipmi_sdr_list) logging.error('Failed to execute:' + ipmi_sdr_list)
@ -69,18 +70,18 @@ def print_temperature_sensors():
print("\nOnboard Temperature Sensors:") print("\nOnboard Temperature Sensors:")
print ' PT_Left_temp: ',\ print(' PT_Left_temp: ',\
(get_pmc_register('PT_Left_temp')) (get_pmc_register('PT_Left_temp')))
print ' PT_Mid_temp: ',\ print(' PT_Mid_temp: ',\
(get_pmc_register('PT_Mid_temp')) (get_pmc_register('PT_Mid_temp')))
print ' PT_Right_temp: ',\ print(' PT_Right_temp: ',\
(get_pmc_register('PT_Right_temp')) (get_pmc_register('PT_Right_temp')))
print ' Broadcom Temp: ',\ print(' Broadcom Temp: ',\
(get_pmc_register('NPU_Near_temp')) (get_pmc_register('NPU_Near_temp')))
print ' Inlet Airflow Temp: ',\ print(' Inlet Airflow Temp: ',\
(get_pmc_register('ILET_AF_temp')) (get_pmc_register('ILET_AF_temp')))
print ' CPU Temp: ',\ print(' CPU Temp: ',\
(get_pmc_register('CPU_temp')) (get_pmc_register('CPU_temp')))
ipmi_sensor_dump() ipmi_sensor_dump()
@ -93,43 +94,43 @@ def print_fan_tray(tray):
Fan_Status = [' Normal', ' Abnormal'] Fan_Status = [' Normal', ' Abnormal']
print ' Fan Tray ' + str(tray) + ':' print(' Fan Tray ' + str(tray) + ':')
if (tray == 1): if (tray == 1):
fan2_status = int(get_pmc_register('FAN1_Rear_stat'), 16) fan2_status = int(get_pmc_register('FAN1_Rear_stat'), 16)
print ' Fan Speed: ',\ print(' Fan Speed: ',\
get_pmc_register('FAN1_Rear_rpm') get_pmc_register('FAN1_Rear_rpm'))
print ' Fan State: ',\ print(' Fan State: ',\
Fan_Status[fan2_status] Fan_Status[fan2_status])
elif (tray == 2): elif (tray == 2):
fan2_status = int(get_pmc_register('FAN2_Rear_stat'), 16) fan2_status = int(get_pmc_register('FAN2_Rear_stat'), 16)
print ' Fan Speed: ',\ print(' Fan Speed: ',\
get_pmc_register('FAN2_Rear_rpm') get_pmc_register('FAN2_Rear_rpm'))
print ' Fan State: ',\ print(' Fan State: ',\
Fan_Status[fan2_status] Fan_Status[fan2_status])
elif (tray == 3): elif (tray == 3):
fan2_status = int(get_pmc_register('FAN3_Rear_stat'), 16) fan2_status = int(get_pmc_register('FAN3_Rear_stat'), 16)
print ' Fan Speed: ',\ print(' Fan Speed: ',\
get_pmc_register('FAN3_Rear_rpm') get_pmc_register('FAN3_Rear_rpm'))
print ' Fan State: ',\ print(' Fan State: ',\
Fan_Status[fan2_status] Fan_Status[fan2_status])
elif (tray == 4): elif (tray == 4):
fan2_status = int(get_pmc_register('FAN4_Rear_stat'), 16) fan2_status = int(get_pmc_register('FAN4_Rear_stat'), 16)
print ' Fan Speed: ',\ print(' Fan Speed: ',\
get_pmc_register('FAN4_Rear_rpm') get_pmc_register('FAN4_Rear_rpm'))
print ' Fan State: ',\ print(' Fan State: ',\
Fan_Status[fan2_status] Fan_Status[fan2_status])
print('\nFan Trays:') print('\nFan Trays:')
@ -139,7 +140,7 @@ for tray in range(1, S5296F_MAX_FAN_TRAYS + 1):
if (get_pmc_register(fan_presence)): if (get_pmc_register(fan_presence)):
print_fan_tray(tray) print_fan_tray(tray)
else: else:
print '\n Fan Tray ' + str(tray + 1) + ': Not present' print('\n Fan Tray ' + str(tray + 1) + ': Not present')
def get_psu_presence(index): def get_psu_presence(index):
""" """
@ -151,9 +152,9 @@ for tray in range(1, S5296F_MAX_FAN_TRAYS + 1):
status = 0 status = 0
if index == 1: 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: 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: #if ret_status:
# print ipmi_cmd_ret # print ipmi_cmd_ret
@ -163,7 +164,7 @@ for tray in range(1, S5296F_MAX_FAN_TRAYS + 1):
psu_status = ipmi_cmd_ret psu_status = ipmi_cmd_ret
if psu_status == '1': if psu_status == '1':
status = 1 status = 1
return status return status
@ -179,54 +180,54 @@ def print_psu(psu):
# psu1_fan_status = int(get_pmc_register('PSU1_status'),16) # psu1_fan_status = int(get_pmc_register('PSU1_status'),16)
print ' PSU1:' print(' PSU1:')
print ' FAN Normal Temperature: ',\ print(' FAN Normal Temperature: ',\
get_pmc_register('PSU1_temp') get_pmc_register('PSU1_temp'))
print ' FAN AirFlow Temperature: ',\ print(' FAN AirFlow Temperature: ',\
get_pmc_register('PSU1_AF_temp') get_pmc_register('PSU1_AF_temp'))
print ' FAN RPM: ',\ print(' FAN RPM: ',\
get_pmc_register('PSU1_rpm') get_pmc_register('PSU1_rpm'))
# print ' FAN Status: ', Psu_Fan_Status[psu1_fan_status] # print ' FAN Status: ', Psu_Fan_Status[psu1_fan_status]
# PSU input & output monitors # PSU input & output monitors
print ' Input Voltage: ',\ print(' Input Voltage: ',\
get_pmc_register('PSU1_In_volt') get_pmc_register('PSU1_In_volt'))
print ' Output Voltage: ',\ print(' Output Voltage: ',\
get_pmc_register('PSU1_Out_volt') get_pmc_register('PSU1_Out_volt'))
print ' Input Power: ',\ print(' Input Power: ',\
get_pmc_register('PSU1_In_watt') get_pmc_register('PSU1_In_watt'))
print ' Output Power: ',\ print(' Output Power: ',\
get_pmc_register('PSU1_Out_watt') get_pmc_register('PSU1_Out_watt'))
print ' Input Current: ',\ print(' Input Current: ',\
get_pmc_register('PSU1_In_amp') get_pmc_register('PSU1_In_amp'))
print ' Output Current: ',\ print(' Output Current: ',\
get_pmc_register('PSU1_Out_amp') get_pmc_register('PSU1_Out_amp'))
else: else:
# psu2_fan_status = int(get_pmc_register('PSU1_status'),16) # psu2_fan_status = int(get_pmc_register('PSU1_status'),16)
print ' PSU2:' print(' PSU2:')
print ' FAN Normal Temperature: ',\ print(' FAN Normal Temperature: ',\
get_pmc_register('PSU2_temp') get_pmc_register('PSU2_temp'))
print ' FAN AirFlow Temperature: ',\ print(' FAN AirFlow Temperature: ',\
get_pmc_register('PSU2_AF_temp') get_pmc_register('PSU2_AF_temp'))
print ' FAN RPM: ',\ print(' FAN RPM: ',\
get_pmc_register('PSU2_rpm') get_pmc_register('PSU2_rpm'))
# print ' FAN Status: ', Psu_Fan_Status[psu2_fan_status] # print ' FAN Status: ', Psu_Fan_Status[psu2_fan_status]
# PSU input & output monitors # PSU input & output monitors
print ' Input Voltage: ',\ print(' Input Voltage: ',\
get_pmc_register('PSU2_In_volt') get_pmc_register('PSU2_In_volt'))
print ' Output Voltage: ',\ print(' Output Voltage: ',\
get_pmc_register('PSU2_Out_volt') get_pmc_register('PSU2_Out_volt'))
print ' Input Power: ',\ print(' Input Power: ',\
get_pmc_register('PSU2_In_watt') get_pmc_register('PSU2_In_watt'))
print ' Output Power: ',\ print(' Output Power: ',\
get_pmc_register('PSU2_Out_watt') get_pmc_register('PSU2_Out_watt'))
print ' Input Current: ',\ print(' Input Current: ',\
get_pmc_register('PSU2_In_amp') get_pmc_register('PSU2_In_amp'))
print ' Output Current: ',\ print(' Output Current: ',\
get_pmc_register('PSU2_Out_amp') get_pmc_register('PSU2_Out_amp'))
print('\nPSUs:') print('\nPSUs:')
@ -235,8 +236,8 @@ for psu in range(1, S5296F_MAX_PSUS + 1):
if (get_psu_presence(psu)): if (get_psu_presence(psu)):
print_psu(psu) print_psu(psu)
else: else:
print '\n PSU ', psu, 'Not present' print('\n PSU ', psu, 'Not present')
print '\n Total Power: ',\ print('\n Total Power: ',\
get_pmc_register('PSU_Total_watt') get_pmc_register('PSU_Total_watt'))

View File

@ -14,6 +14,7 @@ try:
import subprocess import subprocess
from sonic_platform_base.component_base import ComponentBase from sonic_platform_base.component_base import ComponentBase
import sonic_platform.hwaccess as hwaccess import sonic_platform.hwaccess as hwaccess
from sonic_py_common.general import check_output_pipe
except ImportError as e: except ImportError as e:
raise ImportError(str(e) + "- required module not found") raise ImportError(str(e) + "- required module not found")
@ -31,9 +32,7 @@ def get_bmc_version():
""" Returns BMC Version """ """ Returns BMC Version """
bmc_ver = '' bmc_ver = ''
try: try:
bmc_ver = subprocess.check_output( bmc_ver = check_output_pipe(["ipmitool", "mc", "info"], ["awk", "/Firmware Revision/ { print $NF }"])
"ipmitool mc info | awk '/Firmware Revision/ { print $NF }'",
shell=True, text=True).strip()
except (FileNotFoundError, subprocess.CalledProcessError): except (FileNotFoundError, subprocess.CalledProcessError):
pass pass
return bmc_ver return bmc_ver

View File

@ -257,7 +257,7 @@ class Sfp(SfpOptoeBase):
""" """
reset = self.get_reset_status() reset = self.get_reset_status()
if (reset == True): if (reset is True):
status = False status = False
else: else:
status = True status = True
@ -293,7 +293,6 @@ class Sfp(SfpOptoeBase):
del_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/delete_device".format(self.index+1) 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) 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) 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): if not os.path.isfile(driver_path):
print(driver_path, "does not exist") 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. #Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe2 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe2 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe1 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe1 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']: 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) time.sleep(0.2)
new_device = "echo optoe3 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe3 0x50\n')
time.sleep(2) time.sleep(2)
except IOError as e: except IOError as e:

View File

@ -13,11 +13,11 @@
import sys import sys
import logging import logging
import subprocess from sonic_py_common.general import getstatusoutput_noshell
Z9264F_MAX_FAN_TRAYS = 4 Z9264F_MAX_FAN_TRAYS = 4
Z9264F_MAX_PSUS = 2 Z9264F_MAX_PSUS = 2
IPMI_SENSOR_DATA = "ipmitool sdr list" IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
IPMI_SENSOR_DUMP = "/tmp/sdr" IPMI_SENSOR_DUMP = "/tmp/sdr"
FAN_PRESENCE = "FAN{0}_prsnt" FAN_PRESENCE = "FAN{0}_prsnt"
@ -34,7 +34,7 @@ def ipmi_sensor_dump():
status = 1 status = 1
global ipmi_sdr_list global ipmi_sdr_list
ipmi_cmd = IPMI_SENSOR_DATA ipmi_cmd = IPMI_SENSOR_DATA
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute:' + ipmi_sdr_list) logging.error('Failed to execute:' + ipmi_sdr_list)

View File

@ -13,7 +13,6 @@ try:
import time import time
import struct import struct
import mmap import mmap
import subprocess
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
except ImportError as e: except ImportError as e:
@ -244,7 +243,7 @@ class Sfp(SfpOptoeBase):
""" """
reset = self.get_reset_status() reset = self.get_reset_status()
if (reset == True): if (reset is True):
status = False status = False
else: else:
status = True status = True
@ -280,7 +279,6 @@ class Sfp(SfpOptoeBase):
del_sfp_path = "/sys/class/i2c-adapter/i2c-{0}/delete_device".format(self.index+1) 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) 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) 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): if not os.path.isfile(driver_path):
print(driver_path, "does not exist") 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. #Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe2 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe2 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe1 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe1 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']: 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) time.sleep(0.2)
new_device = "echo optoe3 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe3 0x50\n')
time.sleep(2) time.sleep(2)
except IOError as e: except IOError as e:

View File

@ -13,11 +13,11 @@
import sys import sys
import logging import logging
import subprocess from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe
Z9332F_MAX_FAN_TRAYS = 7 Z9332F_MAX_FAN_TRAYS = 7
Z9332F_MAX_PSUS = 2 Z9332F_MAX_PSUS = 2
IPMI_SENSOR_DATA = "ipmitool sdr list" IPMI_SENSOR_DATA = ["ipmitool", "sdr", "list"]
IPMI_SENSOR_DUMP = "/tmp/sdr" IPMI_SENSOR_DUMP = "/tmp/sdr"
FAN_PRESENCE = "Fan{0}_Status" FAN_PRESENCE = "Fan{0}_Status"
@ -25,9 +25,9 @@ PSU_PRESENCE = "PSU{0}_Status"
# Use this for older firmware # Use this for older firmware
# PSU_PRESENCE="PSU{0}_prsnt" # PSU_PRESENCE="PSU{0}_prsnt"
IPMI_PSU1_DATA_DOCKER = "ipmitool raw 0x04 0x2d 0x2f | 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 '{print substr($0,9,1)}'" IPMI_PSU2_DATA_DOCKER = ["ipmitool", "raw", "0x04", "0x2d", "0x39"]
awk_cmd = ['awk', '{print substr($0,9,1)}']
ipmi_sdr_list = "" ipmi_sdr_list = ""
# Dump sensor registers # Dump sensor registers
@ -38,7 +38,7 @@ def ipmi_sensor_dump():
status = 1 status = 1
global ipmi_sdr_list global ipmi_sdr_list
ipmi_cmd = IPMI_SENSOR_DATA ipmi_cmd = IPMI_SENSOR_DATA
status, ipmi_sdr_list = subprocess.getstatusoutput(ipmi_cmd) status, ipmi_sdr_list = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute:' + ipmi_sdr_list) 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 ret_status = 1
if index == 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: 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: #if ret_status:
# print ipmi_cmd_ret # print ipmi_cmd_ret

View File

@ -18,6 +18,7 @@ try:
import tempfile import tempfile
from sonic_platform_base.component_base import ComponentBase from sonic_platform_base.component_base import ComponentBase
import sonic_platform.hwaccess as hwaccess import sonic_platform.hwaccess as hwaccess
from sonic_py_common.general import check_output_pipe
except ImportError as e: except ImportError as e:
raise ImportError(str(e) + "- required module not found") raise ImportError(str(e) + "- required module not found")
@ -161,10 +162,10 @@ class Component(ComponentBase):
return False, "ERROR: File not found" return False, "ERROR: File not found"
with tempfile.TemporaryDirectory() as tmpdir: 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: try:
subprocess.check_call(cmd, stdout=subprocess.DEVNULL, check_output_pipe(cmd1, cmd2)
stderr=subprocess.DEVNULL, shell=True)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
return False, "ERROR: Unable to extract firmware updater" return False, "ERROR: Unable to extract firmware updater"
@ -200,18 +201,18 @@ class Component(ComponentBase):
@staticmethod @staticmethod
def _stage_firmware_package(image_path): def _stage_firmware_package(image_path):
stage_msg = None stage_msg = None
cmd = "onie_stage_fwpkg -a {}".format(image_path) cmd = ["onie_stage_fwpkg", "-a", image_path]
try: 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: except subprocess.CalledProcessError as e:
if e.returncode != 2: if e.returncode != 2:
return False, e.output.strip() return False, e.output.strip()
else: else:
stage_msg = e.output.strip() stage_msg = e.output.strip()
cmd = "onie_mode_set -o update" cmd = ["onie_mode_set", "-o", "update"]
try: 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: except subprocess.CalledProcessError as e:
return False, e.output.strip() return False, e.output.strip()

View File

@ -12,7 +12,6 @@
try: try:
import os import os
import time import time
import subprocess
import mmap import mmap
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase 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]) self._port_to_i2c_mapping[self.index])
driver_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/name".format( driver_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/name".format(
self._port_to_i2c_mapping[self.index]) self._port_to_i2c_mapping[self.index])
delete_device = "echo 0x50 >" + del_sfp_path
if not os.path.isfile(driver_path): if not os.path.isfile(driver_path):
print(driver_path, "does not exist") 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. #Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe2 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe2 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe1 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe1 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']: 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) time.sleep(0.2)
new_device = "echo optoe3 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe3 0x50\n')
time.sleep(2) time.sleep(2)
except IOError as err: except IOError as err:

View File

@ -12,20 +12,20 @@
import sys import sys
import logging import logging
import commands from sonic_py_common.general import getstatusoutput_noshell
Z9432F_MAX_FAN_TRAYS = 7 Z9432F_MAX_FAN_TRAYS = 7
Z9432F_MAX_PSUS = 2 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 # Dump sensor registers
class SdrStatus(object): class SdrStatus(object):
""" Contains IPMI SDR List """ """ Contains IPMI SDR List """
def __init__(self): def __init__(self):
ipmi_cmd = IPMI_SENSOR_DATA ipmi_cmd = IPMI_SENSOR_DATA
status, resp = commands.getstatusoutput(ipmi_cmd) status, resp = getstatusoutput_noshell(ipmi_cmd)
if status: if status:
logging.error('Failed to execute: ' + ipmi_cmd) logging.error('Failed to execute: ' + ipmi_cmd)
sys.exit(0) sys.exit(0)
@ -43,14 +43,6 @@ class SdrStatus(object):
# Fetch a Fan Status # Fetch a Fan Status
SDR_STATUS = SdrStatus() 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 # Fetch a BMC register
@ -62,7 +54,7 @@ def get_pmc_register(reg_name):
if reg_name in sdr_status: if reg_name in sdr_status:
output = sdr_status[reg_name] output = sdr_status[reg_name]
else: else:
print '\nFailed to fetch: ' + reg_name + ' sensor ' print('\nFailed to fetch: ' + reg_name + ' sensor ')
sys.exit(0) sys.exit(0)
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
@ -71,9 +63,11 @@ def get_pmc_register(reg_name):
# Fetch FRU on given offset # Fetch FRU on given offset
def fetch_raw_fru(dev_id, offset): def fetch_raw_fru(dev_id, offset):
""" Fetch RAW value from FRU (dev_id) @ given 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: 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 -1
return int(cmd_ret.strip().split(' ')[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): def get_fan_airflow(fan_id):
""" Return Airflow of direction of FANTRAY(fan_id) """ """ Return Airflow of direction of FANTRAY(fan_id) """
airflow_direction = ['Exhaust', 'Intake'] 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: if dir_idx == -1:
return 'N/A' return 'N/A'
return airflow_direction[dir_idx] return airflow_direction[dir_idx]
@ -92,7 +86,7 @@ def get_fan_airflow(fan_id):
def get_psu_airflow(psu_id): def get_psu_airflow(psu_id):
""" Return Airflow Direction of psu_id """ """ Return Airflow Direction of psu_id """
airflow_direction = ['Exhaust', 'Intake'] airflow_direction = ['Exhaust', 'Intake']
dir_idx = fetch_raw_fru(psu_id, 0x2F) dir_idx = fetch_raw_fru(psu_id, "0x2F")
if dir_idx == -1: if dir_idx == -1:
return 'N/A' return 'N/A'
return airflow_direction[dir_idx] return airflow_direction[dir_idx]
@ -103,37 +97,39 @@ def get_psu_airflow(psu_id):
def print_temperature_sensors(): def print_temperature_sensors():
""" Prints Temperature Sensor """ """ Prints Temperature Sensor """
print "\nOnboard Temperature Sensors:" print("\nOnboard Temperature Sensors:")
print ' PT Left Temp: ',\ print(' PT Left Temp: ',\
(get_pmc_register('PT_Left_temp')) (get_pmc_register('PT_Left_temp')))
print ' NPU Rear Temp: ',\ print(' NPU Rear Temp: ',\
(get_pmc_register('NPU_Rear_temp')) (get_pmc_register('NPU_Rear_temp')))
print ' PT Right Temp: ',\ print(' PT Right Temp: ',\
(get_pmc_register('PT_Right_temp')) (get_pmc_register('PT_Right_temp')))
print ' NPU Front Temp: ',\ print(' NPU Front Temp: ',\
(get_pmc_register('NPU_Front_temp')) (get_pmc_register('NPU_Front_temp')))
print ' FAN Right Temp: ',\ print(' FAN Right Temp: ',\
(get_pmc_register('FAN_Right_temp')) (get_pmc_register('FAN_Right_temp')))
print ' NPU Temp: ',\ print(' NPU Temp: ',\
(get_pmc_register('NPU_temp')) (get_pmc_register('NPU_temp')))
print ' CPU Temp: ',\ print(' CPU Temp: ',\
(get_pmc_register('CPU_temp')) (get_pmc_register('CPU_temp')))
print ' PSU1 AF Temp: ',\ print(' PSU1 AF Temp: ',\
(get_pmc_register('PSU1_AF_temp')) (get_pmc_register('PSU1_AF_temp')))
print ' PSU1 Mid Temp: ',\ print(' PSU1 Mid Temp: ',\
(get_pmc_register('PSU1_Mid_temp')) (get_pmc_register('PSU1_Mid_temp')))
print ' PSU1 Rear Temp: ',\ print(' PSU1 Rear Temp: ',\
(get_pmc_register('PSU1_Rear_temp')) (get_pmc_register('PSU1_Rear_temp')))
print ' PSU2 AF Temp: ',\ print(' PSU2 AF Temp: ',\
(get_pmc_register('PSU2_AF_temp')) (get_pmc_register('PSU2_AF_temp')))
print ' PSU2 Mid Temp: ',\ print(' PSU2 Mid Temp: ',\
(get_pmc_register('PSU2_Mid_temp')) (get_pmc_register('PSU2_Mid_temp')))
print ' PSU2 Rear Temp: ',\ print(' PSU2 Rear Temp: ',\
(get_pmc_register('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() print_temperature_sensors()
@ -144,26 +140,26 @@ def print_fan_tray(fan_tray):
""" Prints given Fan Tray information """ """ Prints given Fan Tray information """
fan_status = ['Abnormal', 'Normal'] 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_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))) == '') fan_rear_status = (get_pmc_register('Fan{0}_Rear_state'.format(str(fan_tray))) == '')
print ' Fan1 Speed: ', \ print(' Fan1 Speed: ', \
get_pmc_register('FAN{0}_Front_rpm'.format(str(fan_tray))) get_pmc_register('FAN{0}_Front_rpm'.format(str(fan_tray))))
print ' Fan2 Speed: ',\ print(' Fan2 Speed: ',\
get_pmc_register('FAN{0}_Rear_rpm'.format(str(fan_tray))) get_pmc_register('FAN{0}_Rear_rpm'.format(str(fan_tray))))
print ' Fan1 State: ', fan_status[fan_front_status] print(' Fan1 State: ', fan_status[fan_front_status])
print ' Fan2 State: ', fan_status[fan_rear_status] print(' Fan2 State: ', fan_status[fan_rear_status])
print ' Airflow: ', get_fan_airflow(fan_tray) print(' Airflow: ', get_fan_airflow(fan_tray))
print '\nFan Trays:' print('\nFan Trays:')
for tray in range(1, Z9432F_MAX_FAN_TRAYS + 1): for tray in range(1, Z9432F_MAX_FAN_TRAYS + 1):
if get_pmc_register('FAN{0}_prsnt'.format(str(tray))) == 'Present': if get_pmc_register('FAN{0}_prsnt'.format(str(tray))) == 'Present':
print_fan_tray(tray) print_fan_tray(tray)
else: else:
print ' Fan Tray {}: NOT PRESENT'.format(str(tray)) print(' Fan Tray {}: NOT PRESENT'.format(str(tray)))
def get_psu_status(index): def get_psu_status(index):
""" """
@ -188,67 +184,69 @@ def print_psu(psu_id):
# PSU FAN details # PSU FAN details
if psu_id == 1: if psu_id == 1:
print ' PSU1:' print(' PSU1:')
print ' AF Temperature: ',\ print(' AF Temperature: ',\
get_pmc_register('PSU1_AF_temp') get_pmc_register('PSU1_AF_temp'))
print ' Mid Temperature: ',\ print(' Mid Temperature: ',\
get_pmc_register('PSU1_Mid_temp') get_pmc_register('PSU1_Mid_temp'))
print ' Rear Temperature: ',\ print(' Rear Temperature: ',\
get_pmc_register('PSU1_Rear_temp') get_pmc_register('PSU1_Rear_temp'))
print ' FAN RPM: ',\ print(' FAN RPM: ',\
get_pmc_register('PSU1_rpm') get_pmc_register('PSU1_rpm'))
# PSU input & output monitors # PSU input & output monitors
print ' Input Voltage: ',\ print(' Input Voltage: ',\
get_pmc_register('PSU1_In_volt') get_pmc_register('PSU1_In_volt'))
print ' Output Voltage: ',\ print(' Output Voltage: ',\
get_pmc_register('PSU1_Out_volt') get_pmc_register('PSU1_Out_volt'))
print ' Input Power: ',\ print(' Input Power: ',\
get_pmc_register('PSU1_In_watt') get_pmc_register('PSU1_In_watt'))
print ' Output Power: ',\ print(' Output Power: ',\
get_pmc_register('PSU1_Out_watt') get_pmc_register('PSU1_Out_watt'))
print ' Input Current: ',\ print(' Input Current: ',\
get_pmc_register('PSU1_In_amp') get_pmc_register('PSU1_In_amp'))
print ' Output Current: ',\ print(' Output Current: ',\
get_pmc_register('PSU1_Out_amp') get_pmc_register('PSU1_Out_amp'))
else: else:
print ' PSU2:' print(' PSU2:')
print ' AF Temperature: ',\ print(' AF Temperature: ',\
get_pmc_register('PSU2_AF_temp') get_pmc_register('PSU2_AF_temp'))
print ' Mid Temperature: ',\ print(' Mid Temperature: ',\
get_pmc_register('PSU2_Mid_temp') get_pmc_register('PSU2_Mid_temp'))
print ' Rear Temperature: ',\ print(' Rear Temperature: ',\
get_pmc_register('PSU2_Rear_temp') get_pmc_register('PSU2_Rear_temp'))
print ' FAN RPM: ',\ print(' FAN RPM: ',\
get_pmc_register('PSU2_rpm') get_pmc_register('PSU2_rpm'))
# PSU input & output monitors # PSU input & output monitors
print ' Input Voltage: ',\ print(' Input Voltage: ',\
get_pmc_register('PSU2_In_volt') get_pmc_register('PSU2_In_volt'))
print ' Output Voltage: ',\ print(' Output Voltage: ',\
get_pmc_register('PSU2_Out_volt') get_pmc_register('PSU2_Out_volt'))
print ' Input Power: ',\ print(' Input Power: ',\
get_pmc_register('PSU2_In_watt') get_pmc_register('PSU2_In_watt'))
print ' Output Power: ',\ print(' Output Power: ',\
get_pmc_register('PSU2_Out_watt') get_pmc_register('PSU2_Out_watt'))
print ' Input Current: ',\ print(' Input Current: ',\
get_pmc_register('PSU2_In_amp') get_pmc_register('PSU2_In_amp'))
print ' Output Current: ',\ print(' Output Current: ',\
get_pmc_register('PSU2_Out_amp') get_pmc_register('PSU2_Out_amp'))
print ' Airflow: ',\ print(' Airflow: ',\
get_psu_airflow(psu_id) get_psu_airflow(psu_id))
print '\nPSUs:' print('\nPSUs:')
for psu in range(1, Z9432F_MAX_PSUS + 1): for psu in range(1, Z9432F_MAX_PSUS + 1):
psu_status = get_psu_status(psu) psu_status = get_psu_status(psu)
if psu_status is not None: if psu_status is not None:
print ' PSU{0}: {1}'.format(psu, psu_status) print(' PSU{0}: {1}'.format(psu, psu_status))
else: else:
print_psu(psu) print_psu(psu)
print '\n Total Power: ',\ print('\n Total Power: ',\
get_pmc_register('PSU_Total_watt') get_pmc_register('PSU_Total_watt'))
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')

View File

@ -18,6 +18,7 @@ try:
import tempfile import tempfile
from sonic_platform_base.component_base import ComponentBase from sonic_platform_base.component_base import ComponentBase
import sonic_platform.hwaccess as hwaccess import sonic_platform.hwaccess as hwaccess
from sonic_py_common.general import check_output_pipe
except ImportError as e: except ImportError as e:
raise ImportError(str(e) + "- required module not found") raise ImportError(str(e) + "- required module not found")
@ -135,10 +136,11 @@ class Component(ComponentBase):
return False, "ERROR: File not found" return False, "ERROR: File not found"
with tempfile.TemporaryDirectory() as tmpdir: 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: try:
subprocess.check_call(cmd, stdout=subprocess.DEVNULL, check_output_pipe(cmd1, cmd2)
stderr=subprocess.DEVNULL, shell=True)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
return False, "ERROR: Unable to extract firmware updater" return False, "ERROR: Unable to extract firmware updater"
@ -166,18 +168,18 @@ class Component(ComponentBase):
@staticmethod @staticmethod
def _stage_firmware_package(image_path): def _stage_firmware_package(image_path):
stage_msg = None stage_msg = None
cmd = "onie_stage_fwpkg -a {}".format(image_path) cmd = ["onie_stage_fwpkg", "-a", image_path]
try: 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: except subprocess.CalledProcessError as e:
if e.returncode != 2: if e.returncode != 2:
return False, e.output.strip() return False, e.output.strip()
else: else:
stage_msg = e.output.strip() stage_msg = e.output.strip()
cmd = "onie_mode_set -o update" cmd = ["onie_mode_set", "-o", "update"]
try: 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: except subprocess.CalledProcessError as e:
return False, e.output.strip() return False, e.output.strip()

View File

@ -12,7 +12,6 @@
try: try:
import os import os
import time import time
import subprocess
import mmap import mmap
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase 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) 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) 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) 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): if not os.path.isfile(driver_path):
print(driver_path, "does not exist") 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. #Avoid re-initialization of the QSFP/SFP optic on QSFP/SFP port.
if self.sfp_type == 'SFP' and driver_name in ['optoe1', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe2 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe2 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP' and driver_name in ['optoe2', 'optoe3']: 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) time.sleep(0.2)
new_device = "echo optoe1 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe1 0x50\n')
time.sleep(2) time.sleep(2)
elif self.sfp_type == 'QSFP_DD' and driver_name in ['optoe1', 'optoe2']: 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) time.sleep(0.2)
new_device = "echo optoe3 0x50 >" + new_sfp_path with open(new_sfp_path, 'w') as f:
subprocess.Popen(new_device, shell=True, stdout=subprocess.PIPE) f.write('optoe3 0x50\n')
time.sleep(2) time.sleep(2)
except IOError as err: except IOError as err: