@Test
  public void isNonNetworkDeviceNetworkFree() {
    HostDevice device = new HostDevice();
    device.setHostId(HOST_ID);
    device.setDeviceName(PCI_DEVICE_NAME_2);

    assertTrue(networkDeviceHelper.isDeviceNetworkFree(device));
  }
  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));
  }
  private List<HostDevice> mockVfsOnNetDevice(int numOfVfs, Guid vmId) {
    List<HostDevice> vfs = new ArrayList<>();

    for (int i = 0; i < numOfVfs; ++i) {
      HostDevice vfPciDevice = new HostDevice();
      vfPciDevice.setParentPhysicalFunction(pciDevice.getDeviceName());
      vfPciDevice.setDeviceName(String.valueOf(i));
      vfPciDevice.setHostId(HOST_ID);
      vfPciDevice.setVmId(vmId);
      vfs.add(vfPciDevice);
    }

    return vfs;
  }
 private HostDevice createHostDevice(Guid vmId) {
   HostDevice hostDevice = new HostDevice();
   hostDevice.setHostId(HOST_ID);
   hostDevice.setVmId(vmId);
   return hostDevice;
 }