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()));
}
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;
}
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);
}
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()));
}
}
Aggregations