Search in sources :

Example 6 with VmValidator

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

the class AddVmFromSnapshotCommandTest method testCannotDisableVirtioScsiCanDisableIDE.

@Test
public void testCannotDisableVirtioScsiCanDisableIDE() {
    cmd.getParameters().setVirtioScsiEnabled(false);
    VM vm = new VM();
    doReturn(vm).when(cmd).getVmFromConfiguration();
    DiskImage disk = new DiskImage();
    disk.setPlugged(true);
    DiskVmElement dve = new DiskVmElement(disk.getId(), vm.getId());
    dve.setDiskInterface(DiskInterface.VirtIO_SCSI);
    disk.setDiskVmElements(Collections.singletonList(dve));
    doReturn(Collections.singletonList(disk)).when(cmd).getAdjustedDiskImagesFromConfiguration();
    VmValidator vmValidator = spy(new VmValidator(vm));
    doReturn(vmValidator).when(cmd).createVmValidator(vm);
    assertFalse(cmd.checkCanDisableVirtIoScsi());
    ValidateTestUtils.assertValidationMessages("Validation should prevent disabling of virtIO-scsi.", cmd, EngineMessage.CANNOT_DISABLE_VIRTIO_SCSI_PLUGGED_DISKS);
    dve.setDiskInterface(DiskInterface.IDE);
    assertTrue(cmd.checkCanDisableVirtIoScsi());
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) Test(org.junit.Test)

Example 7 with VmValidator

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

the class AddVmAndCloneImageCommand method validate.

@Override
protected boolean validate() {
    List<DiskImage> disksToCheck = getDiskImagesToValidate();
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(disksToCheck);
    if (!validate(diskImagesValidator.diskImagesNotLocked())) {
        return false;
    }
    Set<Guid> storageIds = ImagesHandler.getAllStorageIdsForImageIds(disksToCheck);
    MultipleStorageDomainsValidator storageValidator = new MultipleStorageDomainsValidator(getStoragePoolId(), storageIds);
    if (!validate(storageValidator.allDomainsExistAndActive())) {
        return false;
    }
    if (!validate(new VmValidator(getSourceVmFromDb()).vmNotLocked())) {
        return false;
    }
    // Run all checks for AddVm, now that it is determined snapshot exists
    if (!super.validate()) {
        return false;
    }
    for (DiskImage diskImage : getDiskImagesToBeCloned()) {
        if (diskImage.getDiskStorageType() == DiskStorageType.IMAGE && !checkImageConfiguration(diskImage)) {
            return false;
        }
    }
    return true;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 8 with VmValidator

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

the class ExportVmCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    setDescription(getVmName());
    setStoragePoolId(getVm().getStoragePoolId());
    // check that target domain exists
    StorageDomainValidator targetstorageDomainValidator = new StorageDomainValidator(getStorageDomain());
    if (!validate(targetstorageDomainValidator.isDomainExistAndActive())) {
        return false;
    }
    // load the disks of vm from database
    vmHandler.updateDisksFromDb(getVm());
    List<DiskImage> disksForExport = getDisksBasedOnImage();
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(disksForExport);
    if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
        return false;
    }
    // update vm snapshots for storage free space check
    imagesHandler.fillImagesBySnapshots(getVm());
    // check that the target and source domain are in the same storage_pool
    if (storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getVm().getStoragePoolId())) == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
    }
    // check if template exists only if asked for
    if (getParameters().getTemplateMustExists()) {
        if (!checkTemplateInStorageDomain(getVm().getStoragePoolId(), getParameters().getStorageDomainId(), getVm().getVmtGuid(), getContext().getEngineContext())) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_NOT_FOUND_ON_EXPORT_DOMAIN, String.format("$TemplateName %1$s", getVm().getVmtName()));
        }
    }
    Map<Guid, ? extends Disk> images = getVm().getDiskMap();
    if (getParameters().getCopyCollapse()) {
        for (DiskImage img : disksForExport) {
            if (images.containsKey(img.getId())) {
                // check that no RAW format exists (we are in collapse mode)
                if (((DiskImage) images.get(img.getId())).getVolumeFormat() == VolumeFormat.RAW && img.getVolumeFormat() != VolumeFormat.RAW) {
                    return failValidation(EngineMessage.VM_CANNOT_EXPORT_RAW_FORMAT);
                }
            }
        }
    }
    // check destination storage is Export domain
    if (getStorageDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_SPECIFY_DOMAIN_IS_NOT_EXPORT_DOMAIN, String.format("$storageDomainName %1$s", getStorageDomainName()));
    }
    // get the snapshots that are going to be exported and have memory
    snapshotsWithMemory = getSnapshotsToBeExportedWithMemory();
    // check destination storage have free space
    if (!handleDestStorageDomain(disksForExport)) {
        return false;
    }
    if (!(checkVmInStorageDomain() && validate(new StoragePoolValidator(getStoragePool()).existsAndUp()) && validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) && validate(snapshotsValidator.vmNotInPreview(getVmId())) && validate(new VmValidator(getVm()).vmDown()) && validate(new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), ImagesHandler.getAllStorageIdsForImageIds(disksForExport)).allDomainsExistAndActive()))) {
        return false;
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Guid(org.ovirt.engine.core.compat.Guid) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 9 with VmValidator

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

the class AddDiskCommand method checkIfImageDiskCanBeAdded.

protected boolean checkIfImageDiskCanBeAdded(VM vm, DiskVmElementValidator diskVmElementValidator) {
    if (Guid.Empty.equals(getStorageDomainId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_SPECIFIED);
    }
    boolean returnValue;
    StorageDomainValidator storageDomainValidator = createStorageDomainValidator();
    // vm agnostic checks
    returnValue = (getParameters().isSkipDomainCheck() || validate(storageDomainValidator.isDomainExistAndActive())) && validateShareableDiskOnGlusterDomain() && checkImageConfiguration() && validate(storageDomainValidator.hasSpaceForNewDisk(getDiskImageInfo())) && validate(storageDomainValidator.isDomainWithinThresholds()) && checkExceedingMaxBlockDiskSize() && canAddShareableDisk() && validate(diskVmElementValidator.isVirtIoScsiValid(vm)) && validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()));
    if (returnValue && vm != null) {
        // Note this is done according to the VM's spId.
        StoragePool sp = getStoragePool();
        returnValue = validate(new StoragePoolValidator(sp).existsAndUp()) && isStoragePoolMatching(vm) && validate(new VmValidator(getVm()).vmNotLocked()) && isVmNotInPreviewSnapshot();
    }
    return returnValue;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 10 with VmValidator

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

the class AddDiskCommand method validate.

@Override
protected boolean validate() {
    if (!isFloatingDisk() && (!validate(new VmValidator(getVm()).isVmExists()) || !validateDiskVmData())) {
        return false;
    }
    Disk diskInfo = getParameters().getDiskInfo();
    if (diskInfo.getDiskStorageType() == DiskStorageType.IMAGE || diskInfo.getDiskStorageType() == DiskStorageType.CINDER) {
        getDiskImageInfo().setDiskSnapshot(false);
    }
    VM vm = getVm();
    DiskValidator diskValidator = getDiskValidator(getParameters().getDiskInfo());
    DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(getParameters().getDiskInfo(), getDiskVmElement());
    if (vm != null) {
        if (!validateDiskVmData() || !canRunActionOnNonManagedVm()) {
            return false;
        }
        updateDisksFromDb();
        if (getDiskVmElement().isBoot() && !validate(diskValidator.isVmNotContainsBootDisk(vm))) {
            return false;
        }
        if (!validatePassDiscardSupported(diskVmElementValidator)) {
            return false;
        }
        // if user sent drive check that its not in use
        if (!isDiskPassPciAndIdeLimit()) {
            return false;
        }
        if (!validate(diskVmElementValidator.isReadOnlyPropertyCompatibleWithInterface())) {
            return false;
        }
    } else if (Boolean.TRUE.equals(getParameters().getPlugDiskToVm())) {
        return failValidation(EngineMessage.CANNOT_ADD_FLOATING_DISK_WITH_PLUG_VM_SET);
    }
    if (!validateQuota()) {
        return false;
    }
    if (DiskStorageType.IMAGE == getParameters().getDiskInfo().getDiskStorageType()) {
        if (!checkIfImageDiskCanBeAdded(vm, diskVmElementValidator)) {
            return false;
        }
        return setAndValidateDiskProfiles();
    }
    if (DiskStorageType.LUN == getParameters().getDiskInfo().getDiskStorageType()) {
        return checkIfLunDiskCanBeAdded(diskValidator);
    }
    if (DiskStorageType.CINDER == getParameters().getDiskInfo().getDiskStorageType()) {
        CinderDisk cinderDisk = (CinderDisk) getParameters().getDiskInfo();
        cinderDisk.setStorageIds(new ArrayList<>(Collections.singletonList(getStorageDomainId())));
        StorageDomainValidator storageDomainValidator = createStorageDomainValidator();
        CinderDisksValidator cinderDisksValidator = new CinderDisksValidator(cinderDisk);
        return validate(storageDomainValidator.isDomainExistAndActive()) && validate(cinderDisksValidator.validateCinderDiskLimits()) && validate(cinderDisksValidator.validateCinderVolumeTypesExist());
    }
    return true;
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) VM(org.ovirt.engine.core.common.businessentities.VM) CinderDisksValidator(org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Aggregations

VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)20 DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)10 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)9 Guid (org.ovirt.engine.core.compat.Guid)7 MultipleStorageDomainsValidator (org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator)6 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)5 DiskVmElementValidator (org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator)4 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Before (org.junit.Before)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2 CinderDisksValidator (org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator)2 DiskSnapshotsValidator (org.ovirt.engine.core.bll.validator.storage.DiskSnapshotsValidator)2 DiskValidator (org.ovirt.engine.core.bll.validator.storage.DiskValidator)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2