use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class UpdateVmDiskCommandTest method initializeCommand.
protected void initializeCommand(VM vm) {
mockGetForDisk(vm);
mockGetVmsListForDisk(vm);
doNothing().when(command).reloadDisks();
doAnswer(invocation -> invocation.getArguments()[0] != null ? invocation.getArguments()[0] : Guid.newGuid()).when(quotaManager).getDefaultQuotaIfNull(any(), any());
doReturn(diskValidator).when(command).getDiskValidator(any());
doReturn(diskVmElementValidator).when(command).getDiskVmElementValidator(any(), any());
doReturn(true).when(command).setAndValidateDiskProfiles();
doReturn(true).when(command).validateQuota();
mockVmsStoragePoolInfo(vm);
mockToUpdateDiskVm(vm);
StorageDomain sd = new StorageDomain();
sd.setAvailableDiskSize(Integer.MAX_VALUE);
sd.setStatus(StorageDomainStatus.Active);
when(storageDomainDao.get(any())).thenReturn(sd);
when(storageDomainDao.getForStoragePool(any(), any())).thenReturn(sd);
StorageDomainValidator sdValidator = new StorageDomainValidator(sd);
doReturn(sdValidator).when(command).getStorageDomainValidator(any());
ActionReturnValue ret = new ActionReturnValue();
ret.setSucceeded(true);
when(backend.runInternalAction(eq(ActionType.AmendImageGroupVolumes), any(), any())).thenReturn(ret);
command.init();
doReturn(ActionType.UpdateVmDisk).when(command).getActionType();
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class AddStorageDomainCommand method validate.
@Override
protected boolean validate() {
if (!super.validate() || !initializeVds() || !checkStorageDomainNameLengthValid()) {
return false;
}
if (getStorageDomain().getStorageDomainType() == StorageDomainType.ISO && !getStorageDomain().getStorageType().isFileDomain()) {
addValidationMessageVariable("domainType", StorageConstants.ISO);
addValidationMessageVariable("storageTypes", StorageConstants.FILE);
return failValidation(EngineMessage.ACTION_TYPE_FAILED_DOMAIN_TYPE_CAN_BE_CREATED_ONLY_ON_SPECIFIC_STORAGE_DOMAINS);
}
if (getStorageDomain().getStorageDomainType() == StorageDomainType.ImportExport && getStorageDomain().getStorageType().isBlockDomain()) {
addValidationMessageVariable("domainType", StorageConstants.EXPORT);
addValidationMessageVariable("storageTypes", StorageConstants.FILE);
return failValidation(EngineMessage.ACTION_TYPE_FAILED_DOMAIN_TYPE_CAN_BE_CREATED_ONLY_ON_SPECIFIC_STORAGE_DOMAINS);
}
if (getStorageDomain().getStorageDomainType() == StorageDomainType.Master) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
}
StorageDomainValidator sdValidator = getStorageDomainValidator();
if (!validate(sdValidator.isNotIsoOrExportForBackup())) {
return false;
}
ensureStorageFormatInitialized();
if (!validate(sdValidator.isStorageFormatCompatibleWithDomain())) {
return false;
}
initStorageDomainDiscardAfterDeleteIfNeeded();
if (!validateDiscardAfterDeleteLegal(sdValidator)) {
return false;
}
if (!canAddDomain()) {
return false;
}
if (isStorageWithSameNameExists()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NAME_ALREADY_EXIST);
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class VmLeaseCommandBase method validate.
@Override
protected boolean validate() {
StorageDomain domain = storageDomainDao.getForStoragePool(getParameters().getStorageDomainId(), getParameters().getStoragePoolId());
StorageDomainValidator validator = new StorageDomainValidator(domain);
return validate(validator.isDomainExistAndActive()) && validate(validator.isDataDomain());
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class UpdateStorageDomainCommand method validateStoragePropertiesUpdate.
private boolean validateStoragePropertiesUpdate() {
StorageDomainValidator storageDomainValidator = getStorageDomainValidator();
if (!checkStorageDomainStatusNotEqual(StorageDomainStatus.Locked) || !validateStorageNameUpdate() || !validateDiscardAfterDeleteLegal(storageDomainValidator) || !validateDiskOnBackupDomain(storageDomainValidator)) {
return false;
}
// Collect changed fields to update in a list.
List<String> props = ObjectIdentityChecker.getChangedFields(oldDomain, getStorageDomain().getStorageStaticData());
// Allow changes to the following fields only:
props.remove("storageName");
props.remove("description");
props.remove("comment");
props.remove("wipeAfterDelete");
props.remove("discardAfterDelete");
props.remove("warningLowSpaceIndicator");
props.remove("criticalSpaceActionBlocker");
props.remove("backup");
if (!props.isEmpty()) {
log.warn("There was an attempt to update the following fields although they are not allowed to be updated: {}", StringUtils.join(props, ","));
return failValidation(EngineMessage.ERROR_CANNOT_CHANGE_STORAGE_DOMAIN_FIELDS);
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class ImportVmCommand method validateBeforeCloneVm.
protected boolean validateBeforeCloneVm(Map<Guid, StorageDomain> domainsMap) {
if (getVm() != null) {
setDescription(getVmName());
}
StoragePoolValidator spValidator = new StoragePoolValidator(getStoragePool());
if (!validate(spValidator.existsAndUp())) {
return false;
}
Set<Guid> destGuids = new HashSet<>(imageToDestinationDomainMap.values());
for (Guid destGuid : destGuids) {
StorageDomain storageDomain = getStorageDomain(destGuid);
StorageDomainValidator validator = new StorageDomainValidator(storageDomain);
if (!validate(validator.isDomainExistAndActive()) || !validate(validator.domainIsValidDestination())) {
return false;
}
domainsMap.put(destGuid, storageDomain);
}
if (!isImagesAlreadyOnTarget() && getParameters().isImportAsNewEntity() && isCopyCollapseDisabledWithSnapshotsOrWithTemplate()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_IMPORT_CLONE_NOT_COLLAPSED, String.format("$VmName %1$s", getVmName()));
}
// Register can never happen with copyCollapse = true since there's no copy operation involved.
if (isImagesAlreadyOnTarget() && getParameters().getCopyCollapse()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_IMPORT_UNREGISTERED_NOT_COLLAPSED);
}
if (!isImagesAlreadyOnTarget()) {
setSourceDomainId(getParameters().getSourceDomainId());
StorageDomainValidator validator = new StorageDomainValidator(getSourceDomain());
if (validator.isDomainExistAndActive().isValid() && getSourceDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
}
if (!validateAndSetVmFromExportDomain()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND_ON_EXPORT_DOMAIN);
}
}
if (!validateImages(domainsMap)) {
return false;
}
List<VmNetworkInterface> vmNetworkInterfaces = getVm().getInterfaces();
vmNicMacsUtils.replaceInvalidEmptyStringMacAddressesWithNull(vmNetworkInterfaces);
return true;
}
Aggregations