def test_sfp_partial_and_then_full_initialize(): """ Verify SFP initialization flow (partial and then full): 1. get_sfp to tirgger a partial initialization 2. get_sfp for another SPF module and verify the partial initialization isn't executed again 3. get_all_sfps to trigger a full initialization """ chassis = Chassis() # Fetch a sfp # This should trigger SFP modules be partial initialized sfp1 = chassis.get_sfp(1) # Verify the SFP list has been created assert len(chassis._sfp_list) == chassis.PORT_END + 1 assert chassis.sfp_module_partial_initialized == True assert chassis.sfp_module_full_initialized == False # Fetch another SFP module sfp2 = chassis.get_sfp(2) # Verify the previous SFP module isn't changed assert sfp1 == chassis.get_sfp(1) # Fetch all SFP modules allsfp = chassis.get_all_sfps() # Verify sfp1 and sfp2 aren't changed assert sfp1 == chassis.get_sfp(1) assert sfp2 == chassis.get_sfp(2) # Verify the SFP has been fully initialized assert chassis.sfp_module_partial_initialized == True assert chassis.sfp_module_full_initialized == True
def main(): print("---------------------") print("Chassis SFP Unit Test") print("---------------------") chassis = Chassis() PORT_START = 1 PORT_END = 52 for physical_port in range(PORT_START, PORT_END + 1): print(" ") print(" SFP transceiver tests PORT = ", physical_port) name = chassis.get_sfp(physical_port).get_name() print(" SFP transceiver tests NAME = ", name) presence = chassis.get_sfp(physical_port).get_presence() print("TEST 1 - sfp presence [ True ] ", physical_port, presence) status = chassis.get_sfp(physical_port).get_reset_status() print("TEST 2 - sfp reset status [ False ] ", physical_port, status) txdisable = chassis.get_sfp(physical_port).get_tx_disable() print("TEST 3 - sfp tx_disable [ False ] ", physical_port, txdisable) rxlos = chassis.get_sfp(physical_port).get_rx_los() print("TEST 4 - sfp status rxlos [ False ] ", physical_port, rxlos) txfault = chassis.get_sfp(physical_port).get_tx_fault() print("TEST 5 - sfp status txfault [ False ] ", physical_port, txfault) lpmode = chassis.get_sfp(physical_port).get_lpmode() print("TEST 6 - sfp enable lpmode [ False ] ", physical_port, lpmode) trans_info = chassis.get_sfp(physical_port).get_transceiver_info() print("TEST 7 - sfp transceiver info for port:", physical_port, trans_info) trans_status = chassis.get_sfp( physical_port).get_transceiver_bulk_status() print("TEST 8 - sfp bulk status for port:", physical_port, trans_status) threshold = chassis.get_sfp( physical_port).get_transceiver_threshold_info() print("TEST 9 - sfp bulk status for port:", physical_port, threshold) return
def test_sfp_get_error_status(): chassis = Chassis() # Fetch an SFP module to test sfp = chassis.get_sfp(1) description_dict = sfp._get_error_description_dict() sfp.oper_code = SX_PORT_MODULE_STATUS_PLUGGED_WITH_ERROR for error in description_dict.keys(): sfp.error_code = error description = sfp.get_error_description() assert description == description_dict[sfp.error_code] sfp.error_code = -1 description = sfp.get_error_description() assert description == "Unknown error (-1)" expected_description_list = [ (SX_PORT_MODULE_STATUS_INITIALIZING, "Initializing"), (SX_PORT_MODULE_STATUS_PLUGGED, "OK"), (SX_PORT_MODULE_STATUS_UNPLUGGED, "Unplugged"), (SX_PORT_MODULE_STATUS_PLUGGED_DISABLED, "Disabled") ] for oper_code, expected_description in expected_description_list: sfp.oper_code = oper_code description = sfp.get_error_description() assert description == expected_description
def test_sfp_get_error_status(self, mock_get_error_code): chassis = Chassis() # Fetch an SFP module to test sfp = chassis.get_sfp(1) description_dict = sfp._get_error_description_dict() for error in description_dict.keys(): mock_get_error_code.return_value = ( SX_PORT_MODULE_STATUS_PLUGGED_WITH_ERROR, error) description = sfp.get_error_description() assert description == description_dict[error] mock_get_error_code.return_value = ( SX_PORT_MODULE_STATUS_PLUGGED_WITH_ERROR, -1) description = sfp.get_error_description() assert description == "Unknown error (-1)" expected_description_list = [ (SX_PORT_MODULE_STATUS_INITIALIZING, "Initializing"), (SX_PORT_MODULE_STATUS_PLUGGED, "OK"), (SX_PORT_MODULE_STATUS_UNPLUGGED, "Unplugged"), (SX_PORT_MODULE_STATUS_PLUGGED_DISABLED, "Disabled") ] for oper_code, expected_description in expected_description_list: mock_get_error_code.return_value = (oper_code, -1) description = sfp.get_error_description() assert description == expected_description
def test_sfp(self): # Test get_num_sfps, it should not create any SFP objects DeviceDataManager.get_sfp_count = mock.MagicMock(return_value=3) chassis = Chassis() assert chassis.get_num_sfps() == 3 assert len(chassis._sfp_list) == 0 # Index out of bound, return None sfp = chassis.get_sfp(4) assert sfp is None assert len(chassis._sfp_list) == 0 # Get one SFP, other SFP list should be initialized to None sfp = chassis.get_sfp(1) assert sfp is not None assert len(chassis._sfp_list) == 3 assert chassis._sfp_list[1] is None assert chassis._sfp_list[2] is None assert chassis.sfp_initialized_count == 1 # Get the SFP again, no new SFP created sfp1 = chassis.get_sfp(1) assert id(sfp) == id(sfp1) # Get another SFP, sfp_initialized_count increase sfp2 = chassis.get_sfp(2) assert sfp2 is not None assert chassis._sfp_list[2] is None assert chassis.sfp_initialized_count == 2 # Get all SFPs, but there are SFP already created, only None SFP created sfp_list = chassis.get_all_sfps() assert len(sfp_list) == 3 assert chassis.sfp_initialized_count == 3 assert list(filter(lambda x: x is not None, sfp_list)) assert id(sfp1) == id(sfp_list[0]) assert id(sfp2) == id(sfp_list[1]) # Get all SFPs, no SFP yet, all SFP created chassis._sfp_list = [] chassis.sfp_initialized_count = 0 sfp_list = chassis.get_all_sfps() assert len(sfp_list) == 3 assert chassis.sfp_initialized_count == 3
def test_sfp_full_initialize_without_partial(): """ Verify SFP initialization flow (full): 1. get_all_sfps to trigger a full initialization 2. get_sfp for a certain SFP module and verify the partial initialization isn't executed again """ chassis = Chassis() # Fetch all SFP modules allsfp = chassis.get_all_sfps() # Verify the SFP has been fully initialized assert chassis.sfp_module_partial_initialized == True assert chassis.sfp_module_full_initialized == True for sfp in allsfp: assert sfp is not None # Verify when get_sfp is called, the SFP modules won't be initialized again sfp1 = allsfp[0] assert sfp1 == chassis.get_sfp(1)