Search in sources :

Example 31 with HostDevice

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

the class NetworkDeviceHelperImplTest method isVlanDeviceNonNetworkFree.

@Test
public void isVlanDeviceNonNetworkFree() {
    freeVfCommon(0, 0, 0, 0, 1, 0);
    HostDevice hostDevice = getSingleMockedNonFreeDevice();
    assertFalse(networkDeviceHelper.isDeviceNetworkFree(hostDevice));
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) Test(org.junit.Test)

Example 32 with HostDevice

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

the class NetworkDeviceHelperImplTest method createHostDevice.

private HostDevice createHostDevice(Guid vmId) {
    HostDevice hostDevice = new HostDevice();
    hostDevice.setHostId(HOST_ID);
    hostDevice.setVmId(vmId);
    return hostDevice;
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice)

Example 33 with HostDevice

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

the class NetworkDeviceHelperImplTest method removeVmIdFromVfsCommonTest.

private void removeVmIdFromVfsCommonTest(int numOfVfWithVmId, int numOfOtherDeviceWithVmId) {
    List<HostDevice> allDevices = new ArrayList<>();
    List<HostDevice> otherDeviceWithVmId = new ArrayList<>();
    Guid vmId = Guid.newGuid();
    List<HostDevice> vfs = mockVfsOnNetDevice(numOfVfWithVmId, vmId);
    allDevices.addAll(vfs);
    for (int i = 0; i <= numOfOtherDeviceWithVmId; ++i) {
        HostDevice hostDevice = createHostDevice(vmId);
        otherDeviceWithVmId.add(hostDevice);
    }
    allDevices.addAll(otherDeviceWithVmId);
    mockHostDevices(allDevices);
    for (HostDevice vf : vfs) {
        assertEquals(vmId, vf.getVmId());
    }
    networkDeviceHelper.removeVmIdFromVfs(vmId);
    for (HostDevice vf : vfs) {
        vf.setVmId(null);
    }
    if (numOfVfWithVmId == 0) {
        verify(hostDeviceDao, never()).setVmIdOnHostDevice(any(), any());
    } else {
        verify(hostDeviceDao, times(numOfVfWithVmId)).setVmIdOnHostDevice(hostDeviceIdCaptor.capture(), vmIdCaptor.capture());
        List<HostDeviceId> capturedDeviceIds = hostDeviceIdCaptor.getAllValues();
        List<Guid> capturedVmIds = vmIdCaptor.getAllValues();
        for (HostDevice vf : vfs) {
            assertTrue(capturedDeviceIds.contains(vf.getId()));
        }
        for (HostDevice hostDevice : otherDeviceWithVmId) {
            assertFalse(capturedDeviceIds.contains(hostDevice.getId()));
        }
        for (Guid capturedVmId : capturedVmIds) {
            assertNull(capturedVmId);
        }
    }
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) HostDeviceId(org.ovirt.engine.core.common.businessentities.HostDeviceId)

Example 34 with HostDevice

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

the class VfSchedulerImplTest method mockVfShareIommuGroup.

private void mockVfShareIommuGroup(HostDevice vf, boolean share) {
    vf.setIommuGroup(RandomUtils.instance().nextInt());
    List<HostDevice> devices = new ArrayList<>();
    devices.add(vf);
    if (share) {
        HostDevice extraIommuDevice = new HostDevice();
        extraIommuDevice.setHostId(vf.getHostId());
        extraIommuDevice.setIommuGroup(vf.getIommuGroup());
        devices.add(extraIommuDevice);
    }
    when(hostDeviceDao.getHostDevicesByHostIdAndIommuGroup(vf.getHostId(), vf.getIommuGroup())).thenReturn(devices);
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) ArrayList(java.util.ArrayList)

Example 35 with HostDevice

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

the class VfSchedulerImplTest method createVf.

private HostDevice createVf() {
    HostDevice hostDevice = new HostDevice();
    hostDevice.setHostId(hostId);
    hostDevice.setDeviceName(getRandomString());
    return hostDevice;
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice)

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