Search in sources :

Example 31 with NetworkAttachment

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

the class HostNetworkAttachmentsPersisterTest method testPersistNetworkAttachmentsWhenNetworkMovedToDifferentNic.

@Test
public void testPersistNetworkAttachmentsWhenNetworkMovedToDifferentNic() throws Exception {
    NetworkAttachment networkAttachmentForClusterNetworkA = createNetworkAttachment(clusterNetworkA);
    // make network attachment out of sync, by setting different nicId and nicName
    Guid notUpToDateNicId = Guid.newGuid();
    networkAttachmentForClusterNetworkA.setNicId(notUpToDateNicId);
    networkAttachmentForClusterNetworkA.setNicName("nonsense");
    IpConfiguration ipConfiguration = NetworkUtils.createIpConfigurationFromVdsNetworkInterface(interfaceWithAttachedClusterNetworkA);
    networkAttachmentForClusterNetworkA.setIpConfiguration(ipConfiguration);
    networkAttachmentForClusterNetworkA.setProperties(customPropertiesForNics.getCustomPropertiesFor(interfaceWithAttachedClusterNetworkA));
    callPersistNetworkAttachmentsAndVerifyThatNetworkAttachmentIsSynced(networkAttachmentForClusterNetworkA, createPersister(Collections.emptyList()));
}
Also used : IpConfiguration(org.ovirt.engine.core.common.businessentities.network.IpConfiguration) Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 32 with NetworkAttachment

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

the class ExecuteNetworkCommandInNetworkOperationTest method testDetachingPreexistingNetworkAttachment.

/*
     * At the beginning there was a NetworkAttachment, and network gets detached from the nic.
     */
@Test
public void testDetachingPreexistingNetworkAttachment() throws Exception {
    NetworkAttachment attachment = createAttachmentOnNetworkModelAndUpdateParams(networkInterfaceModelOfNicA, logicalNetworkModelOfNetworkA);
    Guid attachmentId = attachment.getId();
    NetworkOperation.DETACH_NETWORK.getTarget().executeNetworkCommand(logicalNetworkModelOfNetworkA, null, dataFromHostSetupNetworksModel);
    assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(1));
    Guid removedNetworkAttachmentId = dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().iterator().next();
    // $NON-NLS-1$
    assertThat("id mismatch", removedNetworkAttachmentId, is(attachmentId));
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 33 with NetworkAttachment

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

the class ExecuteNetworkCommandInNetworkOperationTest method testAddingNewNicWithNetworkAttachmentToExistingBondWithoutAnyAttachment.

/*
     * At the beginning there was bond without any network attachment. Then another nic showed up joining the family
     * bringing his own network attachment along.
     */
@Test
public void testAddingNewNicWithNetworkAttachmentToExistingBondWithoutAnyAttachment() throws Exception {
    addBondToParamsAndModel(existingBond, bondNetworkInterfaceModelA, Collections.emptyList());
    NetworkAttachment networkAttachment = createAttachmentOnNetworkModelAndUpdateParams(networkInterfaceModelOfNicC, logicalNetworkModelOfNetworkC);
    when(networkInterfaceModelOfNicC.getItems()).thenReturn(Collections.singletonList(logicalNetworkModelOfNetworkC));
    initNetworkIdToExistingAttachmentIdMap(networkAttachment);
    NetworkOperation.ADD_TO_BOND.getTarget().executeNetworkCommand(networkInterfaceModelOfNicC, bondNetworkInterfaceModelA, dataFromHostSetupNetworksModel);
    // related network attachment will be updated, not removed and created new one.
    assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1));
    assertNetworkAttachment(dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next(), networkAttachment.getId(), networkC.getId(), existingBondId);
    assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1));
    CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next();
    assertBond(newOrModifiedBond, existingBondId, Arrays.asList(nicA, nicB, nicC));
    assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(0));
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 34 with NetworkAttachment

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

the class ExecuteNetworkCommandInNetworkOperationTest method joinBondsTest.

/*
     * At the beginning there were two bonds (one with NetworkAttachment), which, after being introduced to each other,
     * formed a firm bond adopting NetworkAttachment as their own.
     */
private void joinBondsTest(boolean resusingName) {
    addBondToParamsAndModel(existingBond, bondNetworkInterfaceModelA, Collections.emptyList());
    NetworkAttachment networkAttachment = createAttachmentOnNetworkModelAndUpdateParams(bondNetworkInterfaceModelA, logicalNetworkModelOfNetworkA);
    // $NON-NLS-1$
    Bond bondB = createBond(Guid.newGuid(), "bondB", Arrays.asList(nicC, nicD)).toBond();
    addBondToParamsAndModel(bondB, bondNetworkInterfaceModelB, Collections.singletonList(logicalNetworkModelOfNetworkA));
    initOrginalBondNameToIdMap(bondNetworkInterfaceModelA.getCreateOrUpdateBond(), bondNetworkInterfaceModelB.getCreateOrUpdateBond());
    when(bondNetworkInterfaceModelA.getItems()).thenReturn(Collections.singletonList(logicalNetworkModelOfNetworkA));
    when(bondNetworkInterfaceModelA.getSlaves()).thenReturn(Arrays.asList(networkInterfaceModelOfNicA, networkInterfaceModelOfNicB));
    when(bondNetworkInterfaceModelB.getItems()).thenReturn(Collections.emptyList());
    when(bondNetworkInterfaceModelB.getSlaves()).thenReturn(Arrays.asList(networkInterfaceModelOfNicC, networkInterfaceModelOfNicD));
    if (resusingName) {
        newlyCreatedBond.setName(existingBondName);
    }
    NetworkOperation.JOIN_BONDS.getTarget().executeNetworkCommand(bondNetworkInterfaceModelA, bondNetworkInterfaceModelB, dataFromHostSetupNetworksModel, newlyCreatedBond);
    // NetworkOperation.JOIN_BONDS only detaches the attachments, the attachments are being re-attached only in
    // HostSetupNetworksModel (after clicking ok in the new bond dialog)
    assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(1));
    Guid removeNetworkAttachmentId = dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().iterator().next();
    // $NON-NLS-1$
    assertThat("id mismatch", removeNetworkAttachmentId, is(networkAttachment.getId()));
    assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1));
    CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next();
    assertBond(newOrModifiedBond, resusingName ? existingBondId : null, Arrays.asList(nicA, nicB, nicC, nicD));
    assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(resusingName ? 1 : 2));
    // $NON-NLS-1$
    assertThat("id mismatch", dataFromHostSetupNetworksModel.getRemovedBonds().contains(existingBondId), is(!resusingName));
    // $NON-NLS-1$
    assertThat("id mismatch", dataFromHostSetupNetworksModel.getRemovedBonds().contains(bondB.getId()), is(true));
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Guid(org.ovirt.engine.core.compat.Guid) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 35 with NetworkAttachment

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

the class ExecuteNetworkCommandInNetworkOperationTest method testReattachingPreexistingNetworkAfterItsBeingDetached.

/*
     * At the beginning there was a NetworkAttachment. Suddenly network was detached from the nic, but in the end,
     * network was back attached to the nic unchanged.
     */
@Test
public void testReattachingPreexistingNetworkAfterItsBeingDetached() throws Exception {
    NetworkAttachment attachment = createAttachmentOnNetworkModelAndUpdateParams(networkInterfaceModelOfNicA, logicalNetworkModelOfNetworkA);
    initNetworkIdToExistingAttachmentIdMap(attachment);
    NetworkOperation.DETACH_NETWORK.getTarget().executeNetworkCommand(logicalNetworkModelOfNetworkA, null, dataFromHostSetupNetworksModel);
    NetworkOperation.ATTACH_NETWORK.getTarget().executeNetworkCommand(logicalNetworkModelOfNetworkA, networkInterfaceModelOfNicA, dataFromHostSetupNetworksModel);
    assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1));
    NetworkAttachment updatedNetworkAttachment = dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next();
    assertNetworkAttachment(updatedNetworkAttachment, attachment.getId(), networkA.getId(), nicA.getId());
    assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0));
}
Also used : NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Aggregations

NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)167 Test (org.junit.Test)79 Network (org.ovirt.engine.core.common.businessentities.network.Network)62 Guid (org.ovirt.engine.core.compat.Guid)37 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)36 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)35 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)20 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)18 HashMap (java.util.HashMap)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)14 ArrayList (java.util.ArrayList)10 IpConfiguration (org.ovirt.engine.core.common.businessentities.network.IpConfiguration)10 ProviderNetwork (org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)9 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)8 PersistentHostSetupNetworksParameters (org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)7 HostNetworkQos (org.ovirt.engine.core.common.businessentities.network.HostNetworkQos)7 AnonymousHostNetworkQos (org.ovirt.engine.core.common.businessentities.network.AnonymousHostNetworkQos)6 HostSetupNetworksParameters (org.ovirt.engine.core.common.action.HostSetupNetworksParameters)5 BusinessEntityMap (org.ovirt.engine.core.common.businessentities.BusinessEntityMap)5