Search in sources :

Example 66 with DiskImage

use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.

the class MultipleStorageDomainsValidatorTest method testAllDomainsHaveSpaceForClonedDisksFail.

@Test
public void testAllDomainsHaveSpaceForClonedDisksFail() {
    List<Guid> sdIds = Arrays.asList(sdId1, sdId2);
    List<DiskImage> disksList = generateDisksList(NUM_DISKS, sdIds);
    StorageDomainValidator storageDomainValidator = mock(StorageDomainValidator.class);
    doReturn(new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_SPACE_LOW_ON_STORAGE_DOMAIN)).when(storageDomainValidator).hasSpaceForClonedDisks(any());
    doReturn(storageDomainValidator).when(validator).getStorageDomainValidator(any());
    ValidationResult result = validator.allDomainsHaveSpaceForClonedDisks(disksList);
    assertThat(result, failsWith(EngineMessage.ACTION_TYPE_FAILED_DISK_SPACE_LOW_ON_STORAGE_DOMAIN));
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 67 with DiskImage

use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.

the class MultipleStorageDomainsValidatorTest method testAllDomainsHaveSpaceForAllDisksFail.

@Test
public void testAllDomainsHaveSpaceForAllDisksFail() {
    List<Guid> sdIdsForNew = Arrays.asList(sdId1, sdId2);
    List<Guid> sdIdsForCloned = Arrays.asList(sdId2, sdId3);
    List<DiskImage> disksListForNew = generateDisksList(NUM_DISKS, sdIdsForNew);
    List<DiskImage> disksListForCloned = generateDisksList(NUM_DISKS, sdIdsForCloned);
    StorageDomainValidator storageDomainValidator = mock(StorageDomainValidator.class);
    doReturn(new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_SPACE_LOW_ON_STORAGE_DOMAIN)).when(storageDomainValidator).hasSpaceForAllDisks(any(), any());
    doReturn(storageDomainValidator).when(validator).getStorageDomainValidator(any());
    ValidationResult result = validator.allDomainsHaveSpaceForAllDisks(disksListForNew, disksListForCloned);
    assertThat(result, failsWith(EngineMessage.ACTION_TYPE_FAILED_DISK_SPACE_LOW_ON_STORAGE_DOMAIN));
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 68 with DiskImage

use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.

the class StorageDomainValidatorFreeSpaceTest method createParams.

@Parameterized.Parameters
public static Collection<Object[]> createParams() {
    List<Object[]> params = new ArrayList<>();
    for (StorageType storageType : StorageType.values()) {
        if (storageType.isConcreteStorageType() && !storageType.isCinderDomain()) {
            List<VolumeType> volumeTypes = storageType.isFileDomain() ? Arrays.asList(VolumeType.Preallocated, VolumeType.Sparse) : Collections.singletonList(VolumeType.Preallocated);
            for (VolumeType volumeType : volumeTypes) {
                for (VolumeFormat volumeFormat : new VolumeFormat[] { VolumeFormat.COW, VolumeFormat.RAW }) {
                    DiskImage disk = new DiskImage();
                    disk.setVolumeFormat(volumeFormat);
                    disk.setVolumeType(volumeType);
                    disk.getSnapshots().add(disk);
                    disk.setSizeInGigabytes(200);
                    // GB
                    disk.setActualSize(100);
                    StorageDomain sd = new StorageDomain();
                    sd.setStorageType(storageType);
                    // GB
                    sd.setAvailableDiskSize(107);
                    params.add(new Object[] { disk, sd, volumeFormat == VolumeFormat.RAW && volumeType == VolumeType.Sparse, volumeFormat == VolumeFormat.COW || volumeType == VolumeType.Sparse, volumeFormat == VolumeFormat.RAW && volumeType == VolumeType.Sparse });
                }
            }
        }
    }
    return params;
}
Also used : VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) VolumeType(org.ovirt.engine.core.common.businessentities.storage.VolumeType) ArrayList(java.util.ArrayList) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 69 with DiskImage

use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.

the class StorageDomainValidatorTest method invalidRunningVmsAndVmLeasesForBackupDomain.

@Test
public void invalidRunningVmsAndVmLeasesForBackupDomain() {
    QueryReturnValue ret = new QueryReturnValue();
    List<VmBase> vmLeases = new ArrayList<>();
    VM vmWithLease = new VM();
    vmWithLease.setName("firstVM");
    vmLeases.add(vmWithLease.getStaticData());
    ret.setReturnValue(vmLeases);
    ret.setSucceeded(true);
    // VM1
    VM vm1 = new VM();
    vm1.setName("firstVM");
    Map<Guid, Disk> attachedDisksForVm1 = new HashMap<>();
    DiskImage diskVm1 = new DiskImage();
    diskVm1.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm1.setPlugged(true);
    attachedDisksForVm1.put(Guid.newGuid(), diskVm1);
    vm1.setDiskMap(attachedDisksForVm1);
    // VM2
    VM vm2 = new VM();
    vm2.setName("secondVM");
    Map<Guid, Disk> attachedDisksForVm2 = new HashMap<>();
    DiskImage diskVm2 = new DiskImage();
    diskVm2.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm2.setPlugged(true);
    attachedDisksForVm2.put(Guid.newGuid(), diskVm2);
    vm2.setDiskMap(attachedDisksForVm2);
    List<VM> runningVMs = new ArrayList<>();
    runningVMs.add(vm1);
    runningVMs.add(vm2);
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(runningVMs);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), failsWith(EngineMessage.ACTION_TYPE_FAILED_RUNNING_VM_OR_VM_LEASES_PRESENT_ON_STORAGE_DOMAIN));
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 70 with DiskImage

use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.

the class StorageDomainValidatorTest method validRunningVmsWithUnpluggedDisksForBackupDomain.

@Test
public void validRunningVmsWithUnpluggedDisksForBackupDomain() {
    // VM1
    VM vm1 = new VM();
    vm1.setName("firstVM");
    Map<Guid, Disk> attachedDisksForVm1 = new HashMap<>();
    DiskImage diskVm1 = new DiskImage();
    diskVm1.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm1.setPlugged(false);
    attachedDisksForVm1.put(Guid.newGuid(), diskVm1);
    vm1.setDiskMap(attachedDisksForVm1);
    List<VM> runningVMs = new ArrayList<>();
    runningVMs.add(vm1);
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(runningVMs);
    QueryReturnValue ret = new QueryReturnValue();
    ret.setReturnValue(new ArrayList<VmBase>());
    ret.setSucceeded(true);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), isValid());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Aggregations

DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)635 Guid (org.ovirt.engine.core.compat.Guid)212 ArrayList (java.util.ArrayList)167 Test (org.junit.Test)132 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)80 VM (org.ovirt.engine.core.common.businessentities.VM)77 HashMap (java.util.HashMap)64 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)62 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)62 List (java.util.List)56 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)48 Map (java.util.Map)39 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)38 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)35 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)34 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)31 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)31 EngineException (org.ovirt.engine.core.common.errors.EngineException)29 ActionType (org.ovirt.engine.core.common.action.ActionType)22 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)22