Search in sources :

Example 96 with VdsNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface 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 97 with VdsNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface 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 98 with VdsNetworkInterface

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

the class NicLabelValidatorTest method labelBeingAttachedToNonVlanNonSlaveInterfaceAttachToNewSlave.

@Test
public void labelBeingAttachedToNonVlanNonSlaveInterfaceAttachToNewSlave() {
    HostSetupNetworksParameters params = createHostSetupNetworksParams();
    VdsNetworkInterface slave = createNic();
    CreateOrUpdateBond createOrUpdateBond = new CreateOrUpdateBond();
    createOrUpdateBond.setName("bond");
    createOrUpdateBond.setSlaves(Collections.singleton(slave.getName()));
    params.setCreateOrUpdateBonds(Collections.singletonList(createOrUpdateBond));
    assertLabelBeingAttachedToNonVlanNonSlaveInterfaceFailed(params, slave);
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) HostSetupNetworksParameters(org.ovirt.engine.core.common.action.HostSetupNetworksParameters) Test(org.junit.Test)

Example 99 with VdsNetworkInterface

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

the class NicLabelValidatorTest method createNic.

private VdsNetworkInterface createNic() {
    VdsNetworkInterface nic = new VdsNetworkInterface();
    nic.setId(Guid.newGuid());
    nic.setName(nic.getId().toString());
    return nic;
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 100 with VdsNetworkInterface

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

the class GetManagementInterfaceAddressByVmIdQueryTest method testExecuteQuery.

@Test
public void testExecuteQuery() {
    Guid vmID = Guid.newGuid();
    VM vm = new VM();
    Guid vdsID = Guid.newGuid();
    vm.setRunOnVds(vdsID);
    VDS vds = new VDS();
    vds.setId(vdsID);
    VdsNetworkInterface managementInterface = new VdsNetworkInterface();
    managementInterface.setIpv4Address("my_address");
    IdQueryParameters paramsMock = getQueryParameters();
    when(paramsMock.getId()).thenReturn(vmID);
    when(vmDaoMock.get(vmID)).thenReturn(vm);
    when(interfaceDaoMock.getManagedInterfaceForVds(vdsID, getUser().getId(), getQueryParameters().isFiltered())).thenReturn(managementInterface);
    getQuery().executeQueryCommand();
    String result = getQuery().getQueryReturnValue().getReturnValue();
    assertEquals("Wrong address returned", "my_address", result);
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VDS(org.ovirt.engine.core.common.businessentities.VDS) VM(org.ovirt.engine.core.common.businessentities.VM) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid) AbstractUserQueryTest(org.ovirt.engine.core.bll.AbstractUserQueryTest) Test(org.junit.Test)

Aggregations

VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)233 Test (org.junit.Test)68 Network (org.ovirt.engine.core.common.businessentities.network.Network)47 ArrayList (java.util.ArrayList)46 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)35 Guid (org.ovirt.engine.core.compat.Guid)30 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)24 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)23 List (java.util.List)19 HashMap (java.util.HashMap)18 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)18 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)17 NicLabel (org.ovirt.engine.core.common.businessentities.network.NicLabel)16 VDS (org.ovirt.engine.core.common.businessentities.VDS)15 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)14 Nic (org.ovirt.engine.core.common.businessentities.network.Nic)13 Map (java.util.Map)12 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)9 HostNetworkQos (org.ovirt.engine.core.common.businessentities.network.HostNetworkQos)8 Vlan (org.ovirt.engine.core.common.businessentities.network.Vlan)8