def main():
    print("-----------------")
    print("Chassis Unit Test")
    print("-----------------")

    chassis = sonic_platform.platform.Platform().get_chassis()
    print("  Chassis name: {}".format(chassis.get_name()))

    print("  Chassis presence: {}".format(chassis.get_presence()))

    print("  Chassis model: {}".format(chassis.get_model()))

    print("  Chassis serial: {}".format(chassis.get_serial()))

    print("  Chassis status: {}".format(chassis.get_status()))

    print("  Chassis serial_number: {}".format(chassis.get_serial_number()))

    print("  Chassis base_mac: {}".format(chassis.get_base_mac()))

    print("  Chassis reboot cause: {}\n".format(chassis.get_reboot_cause()))

    print("  Chassis watchdog: {}".format(chassis.get_watchdog()))

    print("  Chassis num_components: {}".format(chassis.get_num_components()))

    print("  Chassis all_components: {}\n".format(
        chassis.get_all_components()))

    print("  Chassis num_modules: {}".format(chassis.get_num_modules()))

    print("  Chassis all_modules: {}\n".format(chassis.get_all_modules()))

    print("  Chassis num_fans: {}".format(chassis.get_num_fans()))

    print("  Chassis all_fans: {}\n".format(chassis.get_all_fans()))

    print("  Chassis num_thermals: {}".format(chassis.get_num_thermals()))

    print("  Chassis all_thermals: {}\n".format(chassis.get_all_thermals()))

    print("  Chassis num_sfps: {}".format(chassis.get_num_sfps()))

    print("  Chassis all_sfps: {}\n".format(chassis.get_all_sfps()))

    print("  Chassis eeprom: {}".format(chassis.get_eeprom()))

    print("  Chassis system_eeprom_info: {}\n".format(
        chassis.get_system_eeprom_info()))

    print("  Chassis get_status_led start : {}\n".format(
        chassis.get_status_led()))
    chassis.set_status_led('amber')
    print("  Chassis get_status_led amber: {}\n".format(
        chassis.get_status_led()))
    chassis.set_status_led('green')
    print("  Chassis get_status_led green: {}\n".format(
        chassis.get_status_led()))

    return
    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