Search in sources :

Example 11 with HostDevice

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

the class VfSchedulerImplTest method createFreeVf.

private HostDevice createFreeVf(HostNicVfsConfig hostNicVfsConfig) {
    HostDevice vf = createVf();
    ArgumentMatcher<List<String>> matchNotContainVf = argVf -> argVf == null || !argVf.contains(vf.getName());
    when(networkDeviceHelper.getFreeVf(eq(getNic(hostNicVfsConfig)), argThat(matchNotContainVf))).thenReturn(vf);
    return vf;
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Guid(org.ovirt.engine.core.compat.Guid) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) RandomUtils(org.ovirt.engine.core.utils.RandomUtils) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) HashSet(java.util.HashSet) ArgumentMatcher(org.mockito.ArgumentMatcher) VdsDao(org.ovirt.engine.core.dao.VdsDao) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) Network(org.ovirt.engine.core.common.businessentities.network.Network) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) Before(org.junit.Before) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) NetworkDao(org.ovirt.engine.core.dao.network.NetworkDao) Mockito.when(org.mockito.Mockito.when) HostDeviceDao(org.ovirt.engine.core.dao.HostDeviceDao) Collectors(java.util.stream.Collectors) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) InterfaceDao(org.ovirt.engine.core.dao.network.InterfaceDao) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) VDS(org.ovirt.engine.core.common.businessentities.VDS) HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with HostDevice

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

the class VfSchedulerImplTest method hostNicHaveTwoFreeVfOneShouldBeDirectlyPassthrough.

@Test
public void hostNicHaveTwoFreeVfOneShouldBeDirectlyPassthrough() {
    VmNetworkInterface vnic = mockVnic(true);
    List<HostDevice> vfs = initHostWithOneVfsConfig(Collections.singletonList(vnic), 2, true, false, false, true, false, true);
    HostDevice freeVf = vfs.get(0);
    mockVfDirectlyAttached(false, freeVf);
    expectedVnicToVfMap.put(vnic.getId(), freeVf.getDeviceName());
    assertHostValid(Collections.singletonList(vnic));
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Test(org.junit.Test)

Example 13 with HostDevice

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

the class VfSchedulerImplTest method updateVfsConfig.

private HostDevice updateVfsConfig(HostNicVfsConfig hostNicVfsConfig, VmNetworkInterface vnic, int numOfVfs, boolean allNetworksAllowed, boolean vnicNetworkInSriovConfig, boolean vnicLabelInSriovConfig, boolean hasFreeVf, boolean freeVfShareIommuGroup, boolean vfDirectlyAttached) {
    hostNicVfsConfig.setNicId(Guid.newGuid());
    hostNicVfsConfig.setNumOfVfs(numOfVfs);
    hostNicVfsConfig.setAllNetworksAllowed(allNetworksAllowed);
    updateVfsConfigNetworks(hostNicVfsConfig, vnic, vnicNetworkInSriovConfig);
    updateVfsConfigLabels(hostNicVfsConfig, vnic, vnicLabelInSriovConfig);
    VdsNetworkInterface nic = new VdsNetworkInterface();
    nic.setId(hostNicVfsConfig.getNicId());
    when(getNic(hostNicVfsConfig)).thenReturn(nic);
    HostDevice vf = null;
    if (hasFreeVf) {
        vf = createFreeVf(hostNicVfsConfig);
        mockVfShareIommuGroup(vf, freeVfShareIommuGroup);
        if (!freeVfShareIommuGroup && (allNetworksAllowed || vnicNetworkInSriovConfig || vnicLabelInSriovConfig)) {
            if (!vfDirectlyAttached) {
                expectedVnicToVfMap.put(vnic.getId(), vf.getDeviceName());
            }
            mockVfDirectlyAttached(vfDirectlyAttached, vf);
        }
    }
    return vf;
}
Also used : HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 14 with HostDevice

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

the class NetworkDeviceHelperImplTest method mockNetworkDeviceForPciDevice.

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

Example 15 with HostDevice

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

the class NetworkDeviceHelperImplTest method isNetworkDeviceNonNetworkFree.

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

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