Search in sources :

Example 1 with HostInterfaceValidator

use of org.ovirt.engine.core.bll.validator.HostInterfaceValidator in project ovirt-engine by oVirt.

the class UnlabelNicCommand method validate.

@Override
protected boolean validate() {
    Guid nicId = getParameters().getNicId();
    HostInterfaceValidator hostInterfaceValidator = new HostInterfaceValidator(getNic());
    return validate(hostInterfaceValidator.interfaceExists(nicId)) && validate(hostInterfaceValidator.nicIsNotLabeledWithSpecifiedLabel(getLabel()));
}
Also used : HostInterfaceValidator(org.ovirt.engine.core.bll.validator.HostInterfaceValidator) Guid(org.ovirt.engine.core.compat.Guid)

Example 2 with HostInterfaceValidator

use of org.ovirt.engine.core.bll.validator.HostInterfaceValidator in project ovirt-engine by oVirt.

the class HostSetupNetworksValidator method validateModifiedBondSlaves.

ValidationResult validateModifiedBondSlaves(CreateOrUpdateBond modifiedOrNewBond) {
    for (String slaveName : modifiedOrNewBond.getSlaves()) {
        VdsNetworkInterface potentialSlave = existingInterfacesMap.get(slaveName);
        HostInterfaceValidator slaveHostInterfaceValidator = createHostInterfaceValidator(potentialSlave);
        ValidationResult interfaceExists = slaveHostInterfaceValidator.interfaceExists(slaveName);
        if (!interfaceExists.isValid()) {
            return interfaceExists;
        }
        ValidationResult interfaceIsValidSlave = slaveHostInterfaceValidator.interfaceIsValidSlave();
        if (!interfaceIsValidSlave.isValid()) {
            return interfaceIsValidSlave;
        }
        /*
             * definition of currently processed bond references this slave, but this slave already 'slaves' for
             * another bond. This is ok only when this bond will be removed as a part of this request
             * or the slave will be removed from its former bond, as a part of this request.
             */
        String currentSlavesBondName = potentialSlave.getBondName();
        if (potentialSlave.isPartOfBond() && /*
                         * we're creating new bond, and it's definition contains reference to slave already assigned
                         * to a different bond.
                         */
        (!potentialSlave.isPartOfBond(modifiedOrNewBond.getName()) && // … but this bond is also removed in this request, so it's ok.
        !isBondRemoved(currentSlavesBondName) && // … or slave was removed from its former bond
        !bondIsUpdatedAndDoesNotContainCertainSlave(slaveName, currentSlavesBondName))) {
            EngineMessage engineMessage = EngineMessage.NETWORK_INTERFACE_ALREADY_IN_BOND;
            return new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, slaveName));
        }
        ValidationResult slaveHasAttachedNetworksValidationResult = validateSlaveHasNoNetworks(potentialSlave.getName());
        if (!slaveHasAttachedNetworksValidationResult.isValid()) {
            return slaveHasAttachedNetworksValidationResult;
        }
        if (slaveUsedMultipleTimesInDifferentBonds(slaveName)) {
            return new ValidationResult(EngineMessage.NETWORK_INTERFACE_REFERENCED_AS_A_SLAVE_MULTIPLE_TIMES, ReplacementUtils.createSetVariableString("NETWORK_INTERFACE_REFERENCED_AS_A_SLAVE_MULTIPLE_TIMES_ENTITY", slaveName));
        }
        ValidationResult slaveHasNoLabelsValidationResult = validateSlaveHasNoLabels(slaveName);
        if (!slaveHasNoLabelsValidationResult.isValid()) {
            return slaveHasNoLabelsValidationResult;
        }
    }
    return ValidationResult.VALID;
}
Also used : HostInterfaceValidator(org.ovirt.engine.core.bll.validator.HostInterfaceValidator) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Example 3 with HostInterfaceValidator

use of org.ovirt.engine.core.bll.validator.HostInterfaceValidator in project ovirt-engine by oVirt.

the class HostSetupNetworksValidatorTest method doTestValidateModifiedBondSlaves.

private void doTestValidateModifiedBondSlaves(HostSetupNetworksValidator validator, ValidationResult interfaceExistValidationResult, ValidationResult interfaceIsValidSlaveValidationResult, Matcher<ValidationResult> matcher) {
    HostInterfaceValidator hostInterfaceValidatorMock = mock(HostInterfaceValidator.class);
    when(hostInterfaceValidatorMock.interfaceExists(anyString())).thenReturn(interfaceExistValidationResult);
    when(hostInterfaceValidatorMock.interfaceIsValidSlave()).thenReturn(interfaceIsValidSlaveValidationResult);
    doReturn(hostInterfaceValidatorMock).when(validator).createHostInterfaceValidator(any());
    assertThat(validator.validNewOrModifiedBonds(), matcher);
}
Also used : HostInterfaceValidator(org.ovirt.engine.core.bll.validator.HostInterfaceValidator)

Example 4 with HostInterfaceValidator

use of org.ovirt.engine.core.bll.validator.HostInterfaceValidator in project ovirt-engine by oVirt.

the class HostSetupNetworksValidatorTest method doTestValidModifiedBonds.

private void doTestValidModifiedBonds(CreateOrUpdateBond createOrUpdateBond, ValidationResult interfaceIsBondValidationResult, ValidationResult expectedValidationResult, ValidationResult slavesValidationValidationResult) {
    HostSetupNetworksValidator validator = spy(new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addBonds(createOrUpdateBond)).addExistingInterfaces((List<VdsNetworkInterface>) null).addExistingAttachments((List<NetworkAttachment>) null).addNetworks((Collection<Network>) null).build());
    HostInterfaceValidator hostInterfaceValidatorMock = mock(HostInterfaceValidator.class);
    when(hostInterfaceValidatorMock.interfaceIsBondOrNull()).thenReturn(interfaceIsBondValidationResult);
    doReturn(hostInterfaceValidatorMock).when(validator).createHostInterfaceValidator(any());
    doReturn(slavesValidationValidationResult).when(validator).validateModifiedBondSlaves(any());
    if (expectedValidationResult.isValid()) {
        assertThat(validator.validNewOrModifiedBonds(), isValid());
    } else {
        assertThat(validator.validNewOrModifiedBonds(), failsWith(expectedValidationResult.getMessages(), expectedValidationResult.getVariableReplacements()));
    }
}
Also used : HostInterfaceValidator(org.ovirt.engine.core.bll.validator.HostInterfaceValidator) FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

HostInterfaceValidator (org.ovirt.engine.core.bll.validator.HostInterfaceValidator)4 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)1 Network (org.ovirt.engine.core.common.businessentities.network.Network)1 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)1 Guid (org.ovirt.engine.core.compat.Guid)1