private HostDevice mockNetworkDeviceForPciDevice(HostDevice pciDeviceParam) { HostDevice mockedNetDevice = new HostDevice(); mockedNetDevice.setParentDeviceName(pciDeviceParam.getDeviceName()); mockedNetDevice.setHostId(pciDeviceParam.getHostId()); mockedNetDevice.setDeviceName(pciDeviceParam.getDeviceName() + "netDevice"); mockedNetDevice.setNetworkInterfaceName(mockedNetDevice.getDeviceName() + "iface"); return mockedNetDevice; }
@Test public void testGetVfMap() { final HostDevice pfNetDevice = new HostDevice(); final HostDevice pfPciDevice = new HostDevice(); final Guid pfNicId = Guid.newGuid(); final String pfNicName = "pf" + NIC_NAME; final String pfPciDeviceName = "pf" + PCI_DEVICE_NAME; pfNetDevice.setHostId(HOST_ID); pfNetDevice.setDeviceName("pf" + NET_DEVICE_NAME); pfNetDevice.setNetworkInterfaceName(pfNicName); pfNetDevice.setParentDeviceName(pfPciDeviceName); pfPciDevice.setHostId(HOST_ID); pfPciDevice.setDeviceName(pfPciDeviceName); pfPciDevice.setDeviceName(pfPciDeviceName); when(pciDevice.getParentPhysicalFunction()).thenReturn(pfPciDeviceName); mockHostDevices(Arrays.asList(pfNetDevice, pfPciDevice, new HostDevice())); when(nic.getVlanId()).thenReturn(null); final VdsNetworkInterface pfNic = new VdsNetworkInterface(); pfNic.setId(pfNicId); pfNic.setName(pfNetDevice.getNetworkInterfaceName()); final VdsNetworkInterface bondNic = new VdsNetworkInterface(); bondNic.setBonded(true); final VdsNetworkInterface vlanNic = new VdsNetworkInterface(); vlanNic.setVlanId(666); mockNics(Arrays.asList(pfNic, bondNic, vlanNic), true); mockHostSupportsSriov(true); final Map<Guid, Guid> actual = networkDeviceHelper.getVfMap(HOST_ID); assertEquals(1, actual.size()); assertThat(actual, hasEntry(NIC_ID, pfNicId)); }