Search in sources :

Example 31 with CreateOrUpdateBond

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

the class HostSetupNetworksValidatorTest method testValidModifiedBondsFailsWhenSlavesValidationFails.

@Test
public void testValidModifiedBondsFailsWhenSlavesValidationFails() throws Exception {
    EngineMessage engineMessage = EngineMessage.NETWORK_INTERFACE_ATTACHED_TO_NETWORK_CANNOT_BE_SLAVE;
    ValidationResult slavesValidationResult = new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, "slaveA"), ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_NETWORK_NAME, "networkName"));
    CreateOrUpdateBond createOrUpdateBond = createNewCreateOrUpdateBondWithNameAndId();
    createOrUpdateBond.setSlaves(Stream.of("slaveA", "slaveB").collect(toSet()));
    doTestValidModifiedBonds(createOrUpdateBond, ValidationResult.VALID, /*this mocks validateModifiedBondSlaves to just verify, that caller method will behave ok, when
            validateModifiedBondSlaves return invalid result*/
    slavesValidationResult, slavesValidationResult);
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Test(org.junit.Test)

Example 32 with CreateOrUpdateBond

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

the class ExecuteNetworkCommandInNetworkOperationTest method createBond.

private CreateOrUpdateBond createBond(Guid id, String bondName, List<VdsNetworkInterface> slaves) {
    CreateOrUpdateBond result = new CreateOrUpdateBond();
    result.setId(id);
    result.setName(bondName);
    for (VdsNetworkInterface slave : slaves) {
        result.getSlaves().add(slave.getName());
    }
    return result;
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 33 with CreateOrUpdateBond

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

the class ExecuteNetworkCommandInNetworkOperationTest method testRemoveSlaveFromBond.

/*
     * At the beginning there was a bond with three slaves, the one of them left others.
     */
@Test
public void testRemoveSlaveFromBond() throws Exception {
    existingBond.getSlaves().add(nicC.getName());
    addBondToParamsAndModel(existingBond, bondNetworkInterfaceModelA, Collections.emptyList());
    when(bondNetworkInterfaceModelA.getSlaves()).thenReturn(Arrays.asList(networkInterfaceModelOfNicA, networkInterfaceModelOfNicB, networkInterfaceModelOfNicC));
    NetworkAttachment networkAttachment = createAttachmentOnNetworkModelAndUpdateParams(bondNetworkInterfaceModelA, logicalNetworkModelOfNetworkA);
    when(networkInterfaceModelOfNicA.getBond()).thenReturn(bondNetworkInterfaceModelA);
    NetworkOperation.REMOVE_FROM_BOND.getTarget().executeNetworkCommand(networkInterfaceModelOfNicA, null, dataFromHostSetupNetworksModel);
    // related network attachment will be updated, not removed and created new one.
    assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1));
    Guid networkAttachmentId = dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next().getId();
    // $NON-NLS-1$
    assertThat("id mismatch", networkAttachmentId, is(networkAttachment.getId()));
    assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1));
    CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next();
    assertBond(newOrModifiedBond, existingBondId, Arrays.asList(nicB, nicC));
    assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(0));
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 34 with CreateOrUpdateBond

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

the class ExecuteNetworkCommandInNetworkOperationTest method testBreakingExistingBond.

/*
     * At the beginning there was a bond, which was then broken.
     */
@Test
public void testBreakingExistingBond() throws Exception {
    CreateOrUpdateBond createOrUpdateBond = CreateOrUpdateBond.fromBond(existingBond);
    dataFromHostSetupNetworksModel.getBonds().add(createOrUpdateBond);
    when(bondNetworkInterfaceModelA.getItems()).thenReturn(Collections.emptyList());
    when(bondNetworkInterfaceModelA.getCreateOrUpdateBond()).thenReturn(createOrUpdateBond);
    NetworkOperation.BREAK_BOND.getTarget().executeNetworkCommand(bondNetworkInterfaceModelA, null, dataFromHostSetupNetworksModel);
    assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(1));
    Guid removedBondId = dataFromHostSetupNetworksModel.getRemovedBonds().iterator().next();
    // $NON-NLS-1$
    assertThat("id mismatch", removedBondId, is(existingBond.getId()));
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 35 with CreateOrUpdateBond

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

the class HostSetupNetworksCommand method isManagementNetworkChanged.

private boolean isManagementNetworkChanged(List<HostNetwork> networksToConfigure) {
    Network managementNetwork = managementNetworkUtil.getManagementNetwork(getClusterNetworks(), getClusterId());
    String managementNetworkName = managementNetwork.getName();
    for (HostNetwork network : networksToConfigure) {
        if (managementNetworkName.equals(network.getNetworkName())) {
            return true;
        }
    }
    for (CreateOrUpdateBond createOrUpdateBond : getParameters().getCreateOrUpdateBonds()) {
        // We are only interested in existing bonds, whose bonding options/slave have changed, so it
        // enough to check existing bonds. New bonds which have the management network
        // are covered by network attachments
        VdsNetworkInterface bondNic = getExistingNicsBusinessEntityMap().get(createOrUpdateBond.getId());
        if (bondNic != null && managementNetworkName.equals(bondNic.getNetworkName())) {
            return true;
        }
    }
    return false;
}
Also used : HostNetwork(org.ovirt.engine.core.common.vdscommands.HostNetwork) FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) HostNetwork(org.ovirt.engine.core.common.vdscommands.HostNetwork)

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