def test_chassis_thermal(self): from sonic_platform.thermal import THERMAL_NAMING_RULE os.path.exists = mock.MagicMock(return_value=True) chassis = Chassis() thermal_list = chassis.get_all_thermals() assert thermal_list thermal_dict = {thermal.get_name(): thermal for thermal in thermal_list} gearbox_thermal_rule = None cpu_thermal_rule = None for rule in THERMAL_NAMING_RULE['chassis thermals']: thermal_type = rule.get('type', 'single') if thermal_type == 'single': thermal_name = rule['name'] if rule['temperature'] == 'comex_amb': assert thermal_name not in thermal_dict continue default_present = rule.get('default_present', True) if not default_present: assert thermal_name not in thermal_dict continue assert thermal_name in thermal_dict thermal = thermal_dict[thermal_name] assert rule['temperature'] in thermal.temperature assert rule['high_threshold'] in thermal.high_threshold if 'high_threshold' in rule else thermal.high_threshold is None assert rule['high_critical_threshold'] in thermal.high_critical_threshold if 'high_critical_threshold' in rule else thermal.high_critical_threshold is None else: if 'Gearbox' in rule['name']: gearbox_thermal_rule = rule elif 'CPU Core' in rule['name']: cpu_thermal_rule = rule gearbox_thermal_count = 0 cpu_thermal_count = 0 for thermal in thermal_list: if 'Gearbox' in thermal.get_name(): start_index = gearbox_thermal_rule.get('start_index', 1) start_index += gearbox_thermal_count assert thermal.get_name() == gearbox_thermal_rule['name'].format(start_index) assert gearbox_thermal_rule['temperature'].format(start_index) in thermal.temperature assert gearbox_thermal_rule['high_threshold'].format(start_index) in thermal.high_threshold assert gearbox_thermal_rule['high_critical_threshold'].format(start_index) in thermal.high_critical_threshold gearbox_thermal_count += 1 elif 'CPU Core' in thermal.get_name(): start_index = cpu_thermal_rule.get('start_index', 1) start_index += cpu_thermal_count assert thermal.get_name() == cpu_thermal_rule['name'].format(start_index) assert cpu_thermal_rule['temperature'].format(start_index) in thermal.temperature assert cpu_thermal_rule['high_threshold'].format(start_index) in thermal.high_threshold assert cpu_thermal_rule['high_critical_threshold'].format(start_index) in thermal.high_critical_threshold cpu_thermal_count += 1 assert gearbox_thermal_count == 2 assert cpu_thermal_count == 2
def test_chassis_thermal_includes(self): from sonic_platform.thermal import THERMAL_NAMING_RULE DeviceDataManager.get_platform_name = mock.MagicMock(return_value='x86_64-nvidia_sn2201-r0') DeviceDataManager.get_thermal_capability = mock.MagicMock(return_value={'comex_amb': False, 'cpu_amb': True, 'swb_amb': True}) chassis = Chassis() thermal_list = chassis.get_all_thermals() assert thermal_list thermal_dict = {thermal.get_name(): thermal for thermal in thermal_list} for rule in THERMAL_NAMING_RULE['chassis thermals']: default_present = rule.get('default_present', True) if not default_present: thermal_name = rule['name'] assert thermal_name in thermal_dict
def main(): print("-------------------------") print("Chassis Thermal Unit Test") print("-------------------------") chassis = Chassis() for thermal in chassis.get_all_thermals(): print(" Name:", thermal.get_name()) print(" Presence: {}, Status: {}".format(thermal.get_presence(), thermal.get_status())) print(" Model: {}, Serial: {}".format(thermal.get_model(), thermal.get_serial())) print(" Temperature: {}C, High Threshold: {}C\n".format(thermal.get_temperature(), thermal.get_high_threshold())) return
def main(): print("-------------------------") print("Chassis Thermal Unit Test") print("-------------------------") chassis = Chassis() for thermal in chassis.get_all_thermals(): if not thermal.get_presence(): print(" Name: {} not present".format(thermal.get_name())) else: print(" Name:", thermal.get_name()) print(" Presence: {}, Status: {}".format( thermal.get_presence(), thermal.get_status())) print(" Model: {}, Serial#: {}".format( thermal.get_model(), thermal.get_serial())) print(" Temperature(C): {}".format( thermal.get_temperature())) try: low_thresh = thermal.get_low_threshold() except NotImplementedError: low_thresh = "NA" try: high_thresh = thermal.get_high_threshold() except NotImplementedError: high_thresh = "NA" print(" Low Threshold(C): {}, High Threshold(C): {}".format( low_thresh, high_thresh)) try: crit_low_thresh = thermal.get_low_critical_threshold() except NotImplementedError: crit_low_thresh = "NA" try: crit_high_thresh = thermal.get_high_critical_threshold() except NotImplementedError: crit_high_thresh = "NA" print( " Crit Low Threshold(C): {}, Crit High Threshold(C): {}\n" .format(crit_low_thresh, crit_high_thresh)) return