Search in sources :

Example 16 with HostDevice

use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.

the class NetworkDeviceHelperImplTest method setVmIdOnVfs.

@Test
public void setVmIdOnVfs() {
    List<HostDevice> vfs = mockVfsOnNetDevice(1);
    vfs.forEach(vf -> vf.setVmId(null));
    mockHostDevices(vfs);
    HostDevice vf = vfs.get(0);
    Guid vmId = Guid.newGuid();
    networkDeviceHelper.setVmIdOnVfs(HOST_ID, vmId, Collections.singleton(vf.getDeviceName()));
    verify(hostDeviceDao).setVmIdOnHostDevice(hostDeviceIdCaptor.capture(), vmIdCaptor.capture());
    HostDeviceId capturedDeviceId = hostDeviceIdCaptor.getValue();
    Guid capturedVmId = vmIdCaptor.getValue();
    assertEquals(vf.getId(), capturedDeviceId);
    assertEquals(vmId, capturedVmId);
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) Guid(org.ovirt.engine.core.compat.Guid) HostDeviceId(org.ovirt.engine.core.common.businessentities.HostDeviceId) Test(org.junit.Test)

Example 17 with HostDevice

use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.

the class NetworkDeviceHelperImplTest method testGetVfMap.

@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);
    final Map<Guid, Guid> actual = networkDeviceHelper.getVfMap(HOST_ID);
    assertEquals(1, actual.size());
    assertThat(actual, hasEntry(NIC_ID, pfNicId));
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 18 with HostDevice

use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.

the class NetworkDeviceHelperImplTest method freeVfCommon.

private List<HostDevice> freeVfCommon(int numOfFreeVfs, int numOfVfsAttachedToVm, int numOfVfsHasNoNic, int numOfVfsHasNetworkAttached, int numOfVfsHasVlanDeviceAttached, int numOfVfsArePartOfBond) {
    networkDeviceHelper = spy(new NetworkDeviceHelperImpl(interfaceDao, hostDeviceDao, hostNicVfsConfigDao));
    List<HostDevice> devices = new ArrayList<>();
    List<HostDevice> freeVfs = new ArrayList<>();
    int numOfVfs = numOfFreeVfs + numOfVfsAttachedToVm + numOfVfsHasNoNic + numOfVfsHasNetworkAttached + numOfVfsHasVlanDeviceAttached + numOfVfsArePartOfBond;
    List<HostDevice> vfs = mockVfsOnNetDevice(numOfVfs);
    List<VdsNetworkInterface> nics = new ArrayList<>();
    devices.addAll(vfs);
    for (HostDevice vfPciDevice : vfs) {
        HostDevice vfNetDevice = mockNetworkDeviceForPciDevice(vfPciDevice);
        devices.add(vfNetDevice);
        if (numOfVfsHasNoNic != 0) {
            --numOfVfsHasNoNic;
        } else {
            VdsNetworkInterface vfNic = mockNicForNetDevice(vfNetDevice);
            nics.add(vfNic);
            if (numOfVfsAttachedToVm != 0) {
                --numOfVfsAttachedToVm;
                vfPciDevice.setVmId(Guid.newGuid());
            } else if (numOfVfsHasNetworkAttached != 0) {
                --numOfVfsHasNetworkAttached;
                vfNic.setNetworkName("netName");
            } else if (numOfVfsHasVlanDeviceAttached != 0) {
                --numOfVfsHasVlanDeviceAttached;
                doReturn(true).when(networkDeviceHelper).isVlanDeviceAttached(vfNic);
            } else if (numOfVfsArePartOfBond != 0) {
                --numOfVfsArePartOfBond;
                vfNic.setBondName("bondName");
            } else {
                doReturn(false).when(networkDeviceHelper).isVlanDeviceAttached(vfNic);
                freeVfs.add(vfPciDevice);
            }
        }
    }
    mockHostDevices(devices);
    mockNics(nics, true);
    return freeVfs;
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 19 with HostDevice

use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.

the class NetworkDeviceHelperImplTest method mockVfsOnNetDevice.

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;
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) ArrayList(java.util.ArrayList)

Example 20 with HostDevice

use of org.ovirt.engine.core.common.businessentities.HostDevice in project ovirt-engine by oVirt.

the class AddVmHostDevicesCommand method executeCommand.

@Override
protected void executeCommand() {
    Set<HostDevice> affectedHostDevices = getAffectedHostDevices();
    Map<String, VmHostDevice> existingDevices = getExistingVmHostDevicesByName();
    List<VmDevice> devicesToAdd = new ArrayList<>();
    List<VmDevice> devicesToUpdate = new ArrayList<>();
    for (HostDevice hostDevice : affectedHostDevices) {
        if (!existingDevices.containsKey(hostDevice.getDeviceName())) {
            VmHostDevice device = new VmHostDevice(getVmId(), hostDevice);
            // if the device was not explicitly intended by the user (only added due to the IOMMU group
            // we mark it as as placeholder
            boolean required = getPrimaryDeviceNames().contains(device.getDevice());
            device.setIommuPlaceholder(!required);
            devicesToAdd.add(device);
        } else {
            VmHostDevice device = new VmHostDevice(existingDevices.get(hostDevice.getDeviceName()));
            // as it is now explicitly requested by the user
            if (getPrimaryDeviceNames().contains(device.getDevice()) && device.isIommuPlaceholder()) {
                device.setIommuPlaceholder(false);
                devicesToUpdate.add(device);
            }
        }
    }
    vmDeviceDao.saveAllInBatch(devicesToAdd);
    vmDeviceDao.updateAllInBatch(devicesToUpdate);
    setSucceeded(true);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) ArrayList(java.util.ArrayList) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice)

Aggregations

HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)46 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)16 Guid (org.ovirt.engine.core.compat.Guid)14 Map (java.util.Map)11 List (java.util.List)10 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)10 HashMap (java.util.HashMap)9 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)9 Collectors (java.util.stream.Collectors)8 HostNicVfsConfig (org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig)7 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)7 HostDeviceDao (org.ovirt.engine.core.dao.HostDeviceDao)7 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 Objects (java.util.Objects)6 Inject (javax.inject.Inject)6 StringUtils (org.apache.commons.lang.StringUtils)6 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)6 VmDeviceDao (org.ovirt.engine.core.dao.VmDeviceDao)6