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_module(self): from sonic_platform.chassis import ModularChassis # Test get_num_modules, it should not create any SFP objects DeviceDataManager.get_linecard_count = mock.MagicMock(return_value=3) chassis = ModularChassis() assert chassis.is_modular_chassis() assert chassis.get_num_modules() == 3 assert len(chassis._module_list) == 0 # Index out of bound, return None m = chassis.get_module(3) assert m is None assert len(chassis._module_list) == 0 # Get one Module, other Module in list should be initialized to None m = chassis.get_module(0) assert m is not None assert len(chassis._module_list) == 3 assert chassis._module_list[1] is None assert chassis._module_list[2] is None assert chassis.module_initialized_count == 1 # Get the Module again, no new Module created m1 = chassis.get_module(0) assert id(m) == id(m1) # Get another Module, module_initialized_count increase m2 = chassis.get_module(1) assert m2 is not None assert chassis._module_list[2] is None assert chassis.module_initialized_count == 2 # Get all SFPs, but there are SFP already created, only None SFP created module_list = chassis.get_all_modules() assert len(module_list) == 3 assert chassis.module_initialized_count == 3 assert list(filter(lambda x: x is not None, module_list)) assert id(m1) == id(module_list[0]) assert id(m2) == id(module_list[1]) # Get all SFPs, no SFP yet, all SFP created chassis._module_list = [] chassis.module_initialized_count = 0 module_list = chassis.get_all_modules() assert len(module_list) == 3 assert chassis.module_initialized_count == 3