diff --git a/platform/broadcom/sonic-platform-modules-accton/as9726-32d/classes/fanutil.py b/platform/broadcom/sonic-platform-modules-accton/as9726-32d/classes/fanutil.py index 2384245fed..bffd9fd0c3 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as9726-32d/classes/fanutil.py +++ b/platform/broadcom/sonic-platform-modules-accton/as9726-32d/classes/fanutil.py @@ -36,9 +36,10 @@ class FanUtil(object): FAN_NUM_5_IDX = 5 FAN_NUM_6_IDX = 6 - FAN_NODE_NUM_OF_MAP = 2 + FAN_NODE_NUM_OF_MAP = 3 FAN_NODE_FAULT_IDX_OF_MAP = 1 FAN_NODE_DIR_IDX_OF_MAP = 2 + FAN_NODE_PRESENT_IDX_OF_MAP = 3 BASE_VAL_PATH = '/sys/bus/i2c/devices/14-0066/{0}' FAN_DUTY_PATH = '/sys/bus/i2c/devices/14-0066/fan_duty_cycle_percentage' @@ -60,21 +61,27 @@ class FanUtil(object): _fan_device_node_mapping = { (FAN_NUM_1_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan1_fault', (FAN_NUM_1_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan1_direction', + (FAN_NUM_1_IDX, FAN_NODE_PRESENT_IDX_OF_MAP): 'fan1_present', (FAN_NUM_2_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan2_fault', (FAN_NUM_2_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan2_direction', + (FAN_NUM_2_IDX, FAN_NODE_PRESENT_IDX_OF_MAP): 'fan2_present', (FAN_NUM_3_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan3_fault', (FAN_NUM_3_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan3_direction', + (FAN_NUM_3_IDX, FAN_NODE_PRESENT_IDX_OF_MAP): 'fan3_present', (FAN_NUM_4_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan4_fault', (FAN_NUM_4_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan4_direction', + (FAN_NUM_4_IDX, FAN_NODE_PRESENT_IDX_OF_MAP): 'fan4_present', (FAN_NUM_5_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan5_fault', (FAN_NUM_5_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan5_direction', + (FAN_NUM_5_IDX, FAN_NODE_PRESENT_IDX_OF_MAP): 'fan5_present', (FAN_NUM_6_IDX, FAN_NODE_FAULT_IDX_OF_MAP): 'fan6_fault', (FAN_NUM_6_IDX, FAN_NODE_DIR_IDX_OF_MAP): 'fan6_direction', + (FAN_NUM_6_IDX, FAN_NODE_PRESENT_IDX_OF_MAP): 'fan6_present', } def _get_fan_device_node(self, fan_num, node_num): @@ -177,6 +184,9 @@ class FanUtil(object): def get_fan_dir(self, fan_num): return self._get_fan_node_val(fan_num, self.FAN_NODE_DIR_IDX_OF_MAP) + def get_fan_present(self, fan_num): + return self._get_fan_node_val(fan_num, self.FAN_NODE_PRESENT_IDX_OF_MAP) + def get_fan_duty_cycle(self): #duty_path = self.FAN_DUTY_PATH try: @@ -209,7 +219,10 @@ class FanUtil(object): logging.debug('GET. Parameter error. fan_num, %d', fan_num) return None - if self.get_fan_fault(fan_num) is not None and self.get_fan_fault(fan_num) > 0: + if self.get_fan_fault(fan_num) is None: + return None + + if self.get_fan_fault(fan_num) > 0: logging.debug('GET. FAN fault. fan_num, %d', fan_num) return False diff --git a/platform/broadcom/sonic-platform-modules-accton/as9726-32d/utils/accton_as9726_32d_monitor.py b/platform/broadcom/sonic-platform-modules-accton/as9726-32d/utils/accton_as9726_32d_monitor.py index 49843fc761..310dda0c72 100755 --- a/platform/broadcom/sonic-platform-modules-accton/as9726-32d/utils/accton_as9726_32d_monitor.py +++ b/platform/broadcom/sonic-platform-modules-accton/as9726-32d/utils/accton_as9726_32d_monitor.py @@ -17,6 +17,11 @@ # HISTORY: # mm/dd/yyyy (A.D.)# # 04/23/2021: Michael_Shih create for as9726_32d thermal plan +# 11/23/2023: Roger +# 1. Sync the log buffer to the disk before +# powering off the DUT. +# 2. Change the decision of FAN direction +# 3. Enhance test data # ------------------------------------------------------------------ try: @@ -221,6 +226,14 @@ class switch(object): #Transceiver >=77 def power_off_dut(): + # Sync log buffer to disk + cmd_str = ["sync"] + status, output = getstatusoutput_noshell(cmd_str) + cmd_str = ["/sbin/fstrim", "-av"] + status, output = getstatusoutput_noshell(cmd_str) + time.sleep(3) + + # Power off dut cmd_str = ["i2cset", "-y", "-f", "19", "0x60", "0x60", "0x10"] (status, output) = getstatusoutput_noshell(cmd_str) return (status == 0) @@ -285,7 +298,7 @@ fan_fail=0 count_check=0 test_temp = 0 -test_temp_list = [0, 0, 0, 0, 0, 0, 0] +test_temp_list = [0] * (7 + 16) # 7 Thermal, 16 ZR/ZR+ Thermal temp_test_data=0 test_temp_revert=0 @@ -319,7 +332,7 @@ class device_monitor(object): if log_level == logging.DEBUG: console = logging.StreamHandler() console.setLevel(log_level) - formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') + formatter = logging.Formatter('%(asctime)s %(name)-12s: %(levelname)-8s %(message)s', datefmt='%H:%M:%S') console.setFormatter(formatter) logging.getLogger('').addHandler(console) @@ -328,10 +341,12 @@ class device_monitor(object): logging.getLogger('').addHandler(sys_handler) #logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level) - state_db = swsscommon.DBConnector(STATE_DB, 0, False) - self.transceiver_dom_sensor_table = swsscommon.Table(state_db, TRANSCEIVER_DOM_SENSOR_TABLE) + self.transceiver_dom_sensor_table = None def get_transceiver_temperature(self, iface_name): + if self.transceiver_dom_sensor_table is None: + return 0.0 + (status, ret) = self.transceiver_dom_sensor_table.hget(iface_name, TEMPERATURE_FIELD_NAME) if status: try: @@ -427,6 +442,16 @@ class device_monitor(object): max_to_mid=0 mid_to_min=0 + # After booting, the database might not be ready for + # connection. So, it should try to connect to the database + # if self.transceiver_dom_sensor_table is None. + if self.transceiver_dom_sensor_table is None: + try: + state_db = swsscommon.DBConnector(STATE_DB, 0, False) + self.transceiver_dom_sensor_table = swsscommon.Table(state_db, TRANSCEIVER_DOM_SENSOR_TABLE) + except Exception as e: + logging.debug("{}".format(e)) + fan = self.fan if fan_policy_state==LEVEL_FAN_INIT: fan_policy_state=LEVEL_FAN_MAX #This is default state @@ -440,14 +465,24 @@ class device_monitor(object): count_check=0 thermal = self.thermal - fan_dir=fan.get_fan_dir(1) + f2b_dir = 0 + b2f_dir = 0 + for i in range (fan.FAN_NUM_1_IDX, fan.FAN_NUM_ON_MAIN_BROAD+1): + if fan.get_fan_present(i)==0: + continue + b2f_dir += fan.get_fan_dir(i) == 1 + f2b_dir += fan.get_fan_dir(i) == 0 + logging.debug("b2f_dir={} f2b_dir={}".format(b2f_dir, f2b_dir)) + fan_dir = int(b2f_dir >= f2b_dir) if fan_dir==1: # AFI fan_thermal_spec = afi_thermal_spec fan_policy=fan_policy_b2f + logging.debug("fan_policy = fan_policy_b2f") elif fan_dir==0: # AFO fan_thermal_spec = afo_thermal_spec fan_policy=fan_policy_f2b + logging.debug("fan_policy = fan_policy_f2b") else: logging.debug( "NULL case") @@ -471,8 +506,12 @@ class device_monitor(object): logging.debug("Maximum avaliable port : %d", TRANSCEIVER_NUM_MAX) logging.debug(thermal_val) else: - for i in range(THERMAL_NUM_MAX): + for i in range(thermal.THERMAL_NUM_MAX): thermal_val.append((TYPE_SENSOR, None, test_temp_list[i] + temp_test_data)) + for port_num in monitor_port: + sfp = platform_chassis.get_sfp(port_num) + thermal_val.append((TYPE_TRANSCEIVER, sfp, test_temp_list[i + 1] + temp_test_data)) + i = i + 1 logging.debug(thermal_val) fan_fail=0 @@ -656,11 +695,11 @@ def main(argv): log_file = arg if sys.argv[1]== '-t': - if len(sys.argv)!=9: - print("temp test, need input 7 temp") + if len(sys.argv)!=(2 + 7 + 16): # 7 Thermal, 16 ZR/ZR+ Thermal + print("temp test, need input %d temp" % (7 + 16)) return 0 i=0 - for x in range(2, 9): + for x in range(2, (2 + 7 + 16)): # 7 Thermal, 16 ZR/ZR+ Thermal test_temp_list[i]= int(sys.argv[x])*1000 i=i+1 test_temp = 1