Search in sources :

Example 6 with CreateOrUpdateBond

use of org.ovirt.engine.core.common.action.CreateOrUpdateBond 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 7 with CreateOrUpdateBond

use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.

the class ExecuteNetworkCommandInNetworkOperationTest method testBondingTwoNicsWithReattachingNetworkAttachmentOnNewlyCreatedBond.

/*
     * At the beginning there were two nics (one with NetworkAttachment), which, after being introduced to each other,
     * formed a firm bond adopting NetworkAttachment as their own.
     */
@Test
public void testBondingTwoNicsWithReattachingNetworkAttachmentOnNewlyCreatedBond() throws Exception {
    NetworkAttachment attachment = createAttachmentOnNetworkModelAndUpdateParams(networkInterfaceModelOfNicA, logicalNetworkModelOfNetworkA);
    initNetworkIdToExistingAttachmentIdMap(attachment);
    initOrginalBondNameToIdMap();
    when(networkInterfaceModelOfNicA.getItems()).thenReturn(Collections.singletonList(logicalNetworkModelOfNetworkA));
    NetworkOperation.BOND_WITH.getTarget().executeNetworkCommand(networkInterfaceModelOfNicA, networkInterfaceModelOfNicB, dataFromHostSetupNetworksModel, newlyCreatedBond);
    when(logicalNetworkModelOfNetworkA.isAttached()).thenReturn(false);
    when(bondNetworkInterfaceModelA.getOriginalIface()).thenReturn(newlyCreatedBond.toBond());
    // this is not part of BOND_WITH command, it's simply called after it. BOND_WITH is actually: "detach networks
    // and create bond".
    // in production code, probably due to some problems with listeners, this is actually called three times,
    // luckily each time overwriting previous call.
    NetworkOperation.attachNetworks(bondNetworkInterfaceModelA, Collections.singletonList(logicalNetworkModelOfNetworkA), dataFromHostSetupNetworksModel);
    // related network attachment will be updated, not removed and created new one.
    assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1));
    assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0));
    assertNetworkAttachment(dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next(), attachment.getId(), networkA.getId(), newlyCreatedBond.getId());
    assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1));
    CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next();
    assertBond(newOrModifiedBond, null, Arrays.asList(nicA, nicB));
    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 8 with CreateOrUpdateBond

use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.

the class BackendHostResource method mapBonds.

public CreateOrUpdateBond mapBonds(BusinessEntityMap<Bond> bonds, HostNic model) {
    Mapper<HostNic, Bond> hostNicMapper = getMapper(HostNic.class, Bond.class);
    Bond bond;
    if (model.isSetId()) {
        Guid nicId = asGuid(model.getId());
        bond = hostNicMapper.map(model, bonds.get(nicId));
    } else {
        Bond template = model.isSetName() ? bonds.get(model.getName()) : null;
        bond = hostNicMapper.map(model, template);
    }
    return CreateOrUpdateBond.fromBond(bond);
}
Also used : HostNic(org.ovirt.engine.api.model.HostNic) Guid(org.ovirt.engine.core.compat.Guid) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Example 9 with CreateOrUpdateBond

use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.

the class NicLabelValidator method labelBeingAttachedToValidBond.

ValidationResult labelBeingAttachedToValidBond(NicLabel nicLabel) {
    String interfaceName = nicLabel.getNicName();
    VdsNetworkInterface nic = existingInterfacesMap.get(interfaceName);
    if (nic instanceof Bond) {
        CreateOrUpdateBond createOrUpdateBond = createOrUpdateBondBusinessEntityMap.containsKey(interfaceName) ? createOrUpdateBondBusinessEntityMap.get(interfaceName) : CreateOrUpdateBond.fromBond((Bond) nic);
        if (createOrUpdateBond.getSlaves().size() < 2) {
            return new ValidationResult(EngineMessage.IMPROPER_BOND_IS_LABELED, ReplacementUtils.createSetVariableString(HostInterfaceValidator.VAR_BOND_NAME, createOrUpdateBond.getName()));
        }
    }
    return ValidationResult.VALID;
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 10 with CreateOrUpdateBond

use of org.ovirt.engine.core.common.action.CreateOrUpdateBond in project ovirt-engine by oVirt.

the class NicLabelValidator method shouldBeConfigureAsBondSlave.

private boolean shouldBeConfigureAsBondSlave(String interfaceName) {
    // Check if the interface was updated to be a bond's slave
    for (CreateOrUpdateBond createOrUpdateBond : params.getCreateOrUpdateBonds()) {
        if (createOrUpdateBond.getSlaves().contains(interfaceName)) {
            return true;
        }
    }
    // The interface wasn't updated to be a slave, check if currently it is a slave.
    VdsNetworkInterface existingNic = existingInterfacesMap.get(interfaceName);
    if (existingNic == null) {
        return false;
    }
    if (existingNic.isPartOfBond()) {
        String bondName = existingNic.getBondName();
        VdsNetworkInterface bond = existingInterfacesMap.get(bondName);
        boolean bondWasRemoved = params.getRemovedBonds().contains(bond.getId());
        boolean slaveWasRemovedFromBond = createOrUpdateBondBusinessEntityMap.containsKey(bondName) && !createOrUpdateBondBusinessEntityMap.get(bondName).getSlaves().contains(interfaceName);
        return !bondWasRemoved && !slaveWasRemovedFromBond;
    }
    return false;
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Aggregations

CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)38 Test (org.junit.Test)18 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)14 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)10 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)8 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)8 Guid (org.ovirt.engine.core.compat.Guid)6 HostSetupNetworksParameters (org.ovirt.engine.core.common.action.HostSetupNetworksParameters)5 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)4 BondNetworkInterfaceModel (org.ovirt.engine.ui.uicommonweb.models.hosts.network.BondNetworkInterfaceModel)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Network (org.ovirt.engine.core.common.businessentities.network.Network)3 LogicalNetworkModel (org.ovirt.engine.ui.uicommonweb.models.hosts.network.LogicalNetworkModel)3 NetworkInterfaceModel (org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkInterfaceModel)3 List (java.util.List)2 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)2 NicLabel (org.ovirt.engine.core.common.businessentities.network.NicLabel)2 BaseCommandTarget (org.ovirt.engine.ui.uicommonweb.BaseCommandTarget)2 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)2