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 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)