Search in sources :

Example 46 with VmNic

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

the class SyncMacsOfDbNicsWithSnapshotTest method testSyncWhenNothingChanged.

@Test
public void testSyncWhenNothingChanged() {
    String macAddress = "1";
    VmNic nic = createNic(macAddress);
    createSyncMacsOfDbNicsWithSnapshot(false).sync(Arrays.asList(nic), Arrays.asList(nic));
    verify(nic, times(2)).getMacAddress();
    verify(macPool).freeMacs(Collections.emptyList());
    verify(macPool).addMacs(Collections.emptyList());
    Mockito.verifyNoMoreInteractions(nic);
}
Also used : VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) Test(org.junit.Test)

Example 47 with VmNic

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

the class SyncMacsOfDbNicsWithSnapshotTest method testSyncWhenNeedToSyncMacsWithStatefulSnapshotAndRelocate.

@Test
public void testSyncWhenNeedToSyncMacsWithStatefulSnapshotAndRelocate() {
    // note that reallocation is only possible, when macs from snapshots are not reserved.
    String currentMac1 = "1";
    String currentMac2 = "3";
    String snapshottedMac1 = "1";
    String snapshottedMac2 = "2";
    String reallocatingMac = "4";
    VmNic currentNic1 = createNic(currentMac1);
    VmNic currentNic2 = createNic(currentMac2);
    VmNic snapshottedNic1 = createNic(snapshottedMac1);
    VmNic snapshottedNic2 = createNic(snapshottedMac2);
    List<String> macsToBeAdded = Collections.singletonList(snapshottedMac2);
    when(macPool.addMacs(macsToBeAdded)).thenReturn(macsToBeAdded);
    when(macPool.allocateNewMac()).thenReturn(reallocatingMac);
    createSyncMacsOfDbNicsWithSnapshot(false).sync(Arrays.asList(currentNic1, currentNic2), Arrays.asList(snapshottedNic1, snapshottedNic2));
    verify(snapshottedNic2).setMacAddress(reallocatingMac);
    verifyMethodCallOn(VmNic::getMacAddress, 1, currentNic1, currentNic2);
    // because in reallocation all(in this case) snapshotted nics will be queried again.
    verifyMethodCallOn(VmNic::getMacAddress, 2, snapshottedNic1, snapshottedNic2);
    verify(macPool).allocateNewMac();
    verify(macPool).freeMacs(Collections.singletonList(currentMac2));
    verify(macPool).addMacs(macsToBeAdded);
    verifyNoMoreInteractionsOn(snapshottedNic1, snapshottedNic2, currentNic1, currentNic2);
}
Also used : VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) Test(org.junit.Test)

Aggregations

VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)47 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 VM (org.ovirt.engine.core.common.businessentities.VM)6 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)6 Network (org.ovirt.engine.core.common.businessentities.network.Network)5 Guid (org.ovirt.engine.core.compat.Guid)5 HashMap (java.util.HashMap)4 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 List (java.util.List)3 Map (java.util.Map)3 VmNicValidator (org.ovirt.engine.core.bll.validator.VmNicValidator)3 Version (org.ovirt.engine.core.compat.Version)3 Collectors (java.util.stream.Collectors)2 VmInterfaceManager (org.ovirt.engine.core.bll.network.VmInterfaceManager)2 MacPool (org.ovirt.engine.core.bll.network.macpool.MacPool)2 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)2 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2