Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def get_cage_num(self, port_num):
cage_num = port_num
if (port_num >= self.QSFP_PORT_START):
cage_num = (port_num - self.QSFP_PORT_START)/4
cage_num = cage_num + self.QSFP_PORT_START
cage_num = int(cage_num + self.QSFP_PORT_START)

return cage_num

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _get_fan_node_val(self, fan_num, node_num):
return None

try:
val_file.close()
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
Expand Down Expand Up @@ -135,7 +135,7 @@ def _set_fan_node_val(self, fan_num, node_num, val):
val_file.write(content)

try:
val_file.close()
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,96 +34,60 @@
class ThermalUtil(object):
"""Platform-specific ThermalUtil class"""
THERMAL_NUM_MAX = 4
THERMAL_NUM_1_IDX = 1 # 1_ON_CPU_BROAD. LM75
THERMAL_NUM_1_IDX = 1 # 1_ON_CPU_BROAD. LM75
THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD. LM75
THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD. LM75
THERMAL_NUM_4_IDX = 4 # 4_ON_MAIN_BROAD. LM75

""" Dictionary where
key1 = thermal id index (integer) starting from 1
value = path to fan device file (string) """
#_thermal_to_device_path_mapping = {}

_thermal_to_device_node_mapping = {
THERMAL_NUM_1_IDX: ['18', '4b'],
THERMAL_NUM_2_IDX: ['19', '4c'],
THERMAL_NUM_3_IDX: ['20', '49'],
THERMAL_NUM_4_IDX: ['21', '4a'],
}

thermal_sysfspath ={
THERMAL_NUM_1_IDX: ["/sys/bus/i2c/devices/18-004b/hwmon/hwmon3/temp1_input"],
THERMAL_NUM_2_IDX: ["/sys/bus/i2c/devices/19-004c/hwmon/hwmon4/temp1_input"],
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/devices/20-0049/hwmon/hwmon5/temp1_input"],
THERMAL_NUM_4_IDX: ["/sys/bus/i2c/devices/21-004a/hwmon/hwmon6/temp1_input"],
THERMAL_NUM_1_IDX: ["/sys/bus/i2c/devices/18-004b/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_2_IDX: ["/sys/bus/i2c/devices/19-004c/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/devices/20-0049/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_4_IDX: ["/sys/bus/i2c/devices/21-004a/hwmon/hwmon*/temp1_input"],
}

#def __init__(self):
def _get_thermal_val(self, thermal_num):
def get_thermal_val(self, thermal_num):
if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_MAX:
logging.debug('GET. Parameter error. thermal_num, %d', thermal_num)
return None

device_path = self.get_thermal_to_device_path(thermal_num)
if(os.path.isfile(device_path)):
for filename in glob.glob(device_path):
try:
val_file = open(filename, 'r')
except IOError as e:
logging.error('GET. unable to open file: %s', str(e))
return None
device_path = self.get_thermal_path(thermal_num)
for filename in glob.glob(device_path):
try:
val_file = open(filename, 'r')
except IOError as e:
logging.error('GET. unable to open file: %s', str(e))
return None
content = val_file.readline().rstrip()
if content == '':
logging.debug('GET. content is NULL. device_path:%s', device_path)
return None
try:
val_file.close()
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
return int(content)

else:
print("No such device_path=%s"%device_path)
return 0

return 0

def get_num_thermals(self):
return self.THERMAL_NUM_MAX

def get_idx_thermal_start(self):
return self.THERMAL_NUM_1_IDX

def get_size_node_map(self):
return len(self._thermal_to_device_node_mapping)

def get_size_path_map(self):
return len(self.thermal_sysfspath)

def get_thermal_to_device_path(self, thermal_num):

def get_thermal_path(self, thermal_num):
return self.thermal_sysfspath[thermal_num][0]

def get_thermal_1_val(self):
return self._get_thermal_val(self.THERMAL_NUM_1_IDX)

def get_thermal_2_val(self):
return self._get_thermal_val(self.THERMAL_NUM_2_IDX)

def get_thermal_3_val(self):
return self._get_thermal_val(self.THERMAL_NUM_3_IDX)

def get_thermal_temp(self):
return (self._get_thermal_val(self.THERMAL_NUM_1_IDX) + self._get_thermal_val(self.THERMAL_NUM_2_IDX) +self._get_thermal_val(self.THERMAL_NUM_3_IDX))

def main():
thermal = ThermalUtil()
print("termal1=%d" %thermal._get_thermal_val(1))
print("termal2=%d" %thermal._get_thermal_val(2))
print("termal3=%d" %thermal._get_thermal_val(3))
print("termal4=%d" %thermal._get_thermal_val(4))
#
# print 'get_size_node_map : %d' % thermal.get_size_node_map()
# print 'get_size_path_map : %d' % thermal.get_size_path_map()
# for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1):
# print thermal.get_thermal_to_device_path(x)
#
logging.basicConfig(level=logging.DEBUG)
logging.debug('thermal1=%d', thermal.get_thermal_val(1))
logging.debug('thermal2=%d', thermal.get_thermal_val(2))
logging.debug('thermal3=%d', thermal.get_thermal_val(3))
logging.debug('thermal4=%d', thermal.get_thermal_val(4))

if __name__ == '__main__':
main()
main()
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def manage_fans(self):
thermal = ThermalUtil()
fan = FanUtil()

temp2 = thermal.get_thermal_2_val()
temp2 = thermal.get_thermal_val(2)
if temp2 is None:
return False

temp3 = thermal.get_thermal_3_val()
temp3 = thermal.get_thermal_val(3)
if temp3 is None:
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@


if DEBUG == True:
print((sys.argv[0]))
print(("ARGV :", sys.argv[1:]))
print(sys.argv[0])
print("ARGV :", sys.argv[1:])


def main():
Expand All @@ -67,7 +67,7 @@ def main():
if DEBUG == True:
print(options)
print(args)
print((len(sys.argv)))
print(len(sys.argv))

for opt, arg in options:
if opt in ('-h', '--help'):
Expand Down Expand Up @@ -96,13 +96,13 @@ def main():
return 0

def show_help():
print((__doc__ % {'scriptName' : sys.argv[0].split("/")[-1]}))
print(__doc__ % {'scriptName' : sys.argv[0].split("/")[-1]})
sys.exit(0)


def my_log(txt):
if DEBUG == True:
print(("[Debug]"+txt))
print("[Debug]"+txt)
return

def log_os_system(cmd, show):
Expand All @@ -113,7 +113,7 @@ def log_os_system(cmd, show):
if status:
logging.info('Failed :'+cmd)
if show:
print(('Failed :'+cmd))
print('Failed :'+cmd)
return status, output

def driver_check():
Expand All @@ -128,6 +128,8 @@ def driver_check():

kos = [
'modprobe i2c_dev',
'modprobe i2c_i801',
'modprobe i2c_ismt',
'modprobe i2c_mux_pca954x force_deselect_on_exit=1',
'modprobe accton_as5835_54x_cpld' ,
'modprobe ym2651y' ,
Expand Down Expand Up @@ -285,6 +287,10 @@ def device_install():

for i in range(49, 55): #Set qsfp port to normal state
log_os_system("echo 0 > /sys/bus/i2c/devices/3-0062/module_reset_" + str(i), 1)
for i in range(1, 39): #Set disable tx_disable to sfp port
log_os_system("echo 0 > /sys/bus/i2c/devices/3-0061/module_tx_disable_" + str(i), 1)
for i in range(39, 49): #Set disable tx_disable to sfp port
log_os_system("echo 0 > /sys/bus/i2c/devices/3-0062/module_tx_disable_" + str(i), 1)

for i in range(0,len(sfp_map)):
if i < qsfp_start:
Expand Down Expand Up @@ -348,29 +354,29 @@ def do_sonic_platform_install():
if os.path.exists(SONIC_PLATFORM_BSP_WHL_PKG_PY3):
status, output = log_os_system("pip3 install "+ SONIC_PLATFORM_BSP_WHL_PKG_PY3, 1)
if status:
print(("Error: Failed to install {}".format(PLATFORM_API2_WHL_FILE_PY3) ))
print("Error: Failed to install {}".format(PLATFORM_API2_WHL_FILE_PY3) )
return status
else:
print(("Successfully installed {} package".format(PLATFORM_API2_WHL_FILE_PY3) ))
print("Successfully installed {} package".format(PLATFORM_API2_WHL_FILE_PY3) )
else:
print(('{} is not found'.format(PLATFORM_API2_WHL_FILE_PY3)))
print('{} is not found'.format(PLATFORM_API2_WHL_FILE_PY3))
else:
print(('{} has installed'.format(PLATFORM_API2_WHL_FILE_PY3)))
print('{} has installed'.format(PLATFORM_API2_WHL_FILE_PY3))

return

def do_sonic_platform_clean():
status, output = log_os_system("pip3 show sonic-platform > /dev/null 2>&1", 0)
if status:
print(('{} does not install, not need to uninstall'.format(PLATFORM_API2_WHL_FILE_PY3)))
print('{} does not install, not need to uninstall'.format(PLATFORM_API2_WHL_FILE_PY3))

else:
status, output = log_os_system("pip3 uninstall sonic-platform -y", 0)
if status:
print(('Error: Failed to uninstall {}'.format(PLATFORM_API2_WHL_FILE_PY3)))
print('Error: Failed to uninstall {}'.format(PLATFORM_API2_WHL_FILE_PY3))
return status
else:
print(('{} is uninstalled'.format(PLATFORM_API2_WHL_FILE_PY3)))
print('{} is uninstalled'.format(PLATFORM_API2_WHL_FILE_PY3))

return

Expand All @@ -383,15 +389,15 @@ def do_install():
if FORCE == 0:
return status
else:
print((PROJECT_NAME.upper()+" drivers detected...."))
print(PROJECT_NAME.upper()+" drivers detected....")
if not device_exist():
print("No device, installing....")
status = device_install()
if status:
if FORCE == 0:
return status
else:
print((PROJECT_NAME.upper()+" devices detected...."))
print(PROJECT_NAME.upper()+" devices detected....")

do_sonic_platform_install()

Expand All @@ -400,7 +406,7 @@ def do_install():
def do_uninstall():
print("Checking system....")
if not device_exist():
print((PROJECT_NAME.upper() +" has no device installed...."))
print(PROJECT_NAME.upper() +" has no device installed....")
else:
print("Removing device....")
status = device_uninstall()
Expand All @@ -409,7 +415,7 @@ def do_uninstall():
return status

if driver_check()== False :
print((PROJECT_NAME.upper() +" has no driver installed...."))
print(PROJECT_NAME.upper() +" has no driver installed....")
else:
print("Removing installed driver....")
status = driver_uninstall()
Expand Down