use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class HostSetupNetworksValidator method validRemovedNetworkAttachments.
private ValidationResult validRemovedNetworkAttachments() {
List<Guid> invalidIds = Entities.idsNotReferencingExistingRecords(params.getRemovedNetworkAttachments(), existingAttachments);
if (!invalidIds.isEmpty()) {
EngineMessage engineMessage = EngineMessage.NETWORK_ATTACHMENTS_TO_BE_REMOVED_DOES_NOT_EXISTS;
return new ValidationResult(engineMessage, ReplacementUtils.getListVariableAssignmentString(engineMessage, invalidIds));
}
ValidationResult vr = ValidationResult.VALID;
Iterator<NetworkAttachment> iterator = removedNetworkAttachments.iterator();
while (iterator.hasNext() && vr.isValid()) {
NetworkAttachment attachment = iterator.next();
NetworkAttachmentValidator validator = createNetworkAttachmentValidator(attachment);
vr = skipValidation(vr) ? vr : validator.networkAttachmentIsSet();
vr = skipValidation(vr) ? vr : validator.notExternalNetwork();
vr = skipValidation(vr) ? vr : validator.notRemovingManagementNetwork();
vr = skipValidation(vr) ? vr : notRemovingLabeledNetworks(attachment);
vr = skipValidation(vr) ? vr : validateNotRemovingUsedNetworkByVms(attachment.getNetworkName());
}
return vr;
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class HostSetupNetworksValidator method notRemovingLabeledNetworks.
/**
* @param attachment attachment obtained from db, record validity is assumed.
*
* @return removed attachment relates to network and nic. Method returns true such network is not labeled,
* such nic is currently being removed bond,
* or such nic is not labeled by same label as network is.
*/
ValidationResult notRemovingLabeledNetworks(NetworkAttachment attachment) {
Network removedNetwork = existingNetworkRelatedToAttachment(attachment);
if (!NetworkUtils.isLabeled(removedNetwork)) {
return ValidationResult.VALID;
}
EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_CANNOT_REMOVE_LABELED_NETWORK_FROM_NIC;
return ValidationResult.failWith(engineMessage, ReplacementUtils.getVariableAssignmentStringWithMultipleValues(engineMessage, removedNetwork.getName())).when(isNicToConfigureContainTheLabel(attachment.getNicName(), removedNetwork.getLabel()));
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class HostSetupNetworksValidator method notMovingLabeledNetworkToDifferentNic.
ValidationResult notMovingLabeledNetworkToDifferentNic(NetworkAttachment newOrModifedAttachmet) {
Network movedNetwork = existingNetworkRelatedToAttachment(newOrModifedAttachmet);
if (!NetworkUtils.isLabeled(movedNetwork)) {
return ValidationResult.VALID;
}
NetworkAttachment existingAttachment = existingAttachmentsById.get(newOrModifedAttachmet.getId());
boolean movedToDifferentNic = !existingAttachment.getNicId().equals(newOrModifedAttachmet.getNicId());
EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_CANNOT_MOVE_LABELED_NETWORK_TO_ANOTHER_NIC;
return ValidationResult.failWith(engineMessage, ReplacementUtils.createSetVariableString(VAR_NETWORK_NAME, movedNetwork.getName()), ReplacementUtils.getVariableAssignmentString(engineMessage, movedNetwork.getLabel())).when(movedToDifferentNic && isNicToConfigureContainTheLabel(existingAttachment.getNicName(), movedNetwork.getLabel()));
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class NetworkAttachmentValidatorTest method testNetworkAttachmentIsSetWhenAttachmentIsNull.
@Test
public void testNetworkAttachmentIsSetWhenAttachmentIsNull() {
EngineMessage engineMessage = EngineMessage.NULL_PASSED_AS_NETWORK_ATTACHMENT;
assertThat(createNetworkAttachmentValidator(null).networkAttachmentIsSet(), failsWith(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, null)));
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class NetworkAttachmentValidatorTest method testNetworkExistWhenOnlyNetworkIdIsSet.
@Test
public void testNetworkExistWhenOnlyNetworkIdIsSet() {
Guid networkId = Guid.newGuid();
NetworkAttachment networkAttachment = new NetworkAttachment();
networkAttachment.setNetworkId(networkId);
NetworkAttachmentValidator validator = createNetworkAttachmentValidator(networkAttachment);
EngineMessage engineMessage = EngineMessage.NETWORK_HAVING_ID_NOT_EXISTS;
assertThat(validator.networkExists(), failsWith(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, networkId.toString())));
}
Aggregations