Search in sources :

Example 11 with DiskVmElement

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

the class VmValidator method checkPciAndIdeLimit.

/**
 * This method checks that with the given parameters, the max PCI and IDE limits defined are not passed.
 */
public static ValidationResult checkPciAndIdeLimit(int osId, Version clusterVersion, int monitorsNumber, List<? extends VmNic> interfaces, List<DiskVmElement> diskVmElements, boolean virtioScsiEnabled, boolean hasWatchdog, boolean isBalloonEnabled, boolean isSoundDeviceEnabled) {
    // this adds: monitors + 2 * (interfaces with type rtl_pv) + (all other
    // interfaces) + (all disks that are not IDE)
    int pciInUse = monitorsNumber;
    for (VmNic a : interfaces) {
        if (a.getType() != null && VmInterfaceType.forValue(a.getType()) == VmInterfaceType.rtl8139_pv) {
            pciInUse += 2;
        } else if (a.getType() != null && VmInterfaceType.forValue(a.getType()) == VmInterfaceType.spaprVlan) {
        // Do not count sPAPR VLAN devices since they are not PCI
        } else {
            pciInUse += 1;
        }
    }
    pciInUse += diskVmElements.stream().filter(dve -> dve.getDiskInterface() == DiskInterface.VirtIO).count();
    // VirtIO SCSI controller requires one PCI slot
    pciInUse += virtioScsiEnabled ? 1 : 0;
    // VmWatchdog controller requires one PCI slot
    pciInUse += hasWatchdog ? 1 : 0;
    // Balloon controller requires one PCI slot
    pciInUse += isBalloonEnabled ? 1 : 0;
    // Sound device controller requires one PCI slot
    pciInUse += isSoundDeviceEnabled ? 1 : 0;
    OsRepository osRepository = Injector.get(OsRepository.class);
    int maxPciSlots = osRepository.getMaxPciDevices(osId, clusterVersion);
    ArrayList<EngineMessage> messages = new ArrayList<>();
    if (pciInUse > maxPciSlots) {
        messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_PCI_SLOTS);
    } else if (VmCommand.MAX_IDE_SLOTS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.IDE).count()) {
        messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_IDE_SLOTS);
    } else if (VmCommand.MAX_VIRTIO_SCSI_DISKS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.VirtIO_SCSI).count()) {
        messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_VIRTIO_SCSI_DISKS);
    } else if (VmCommand.MAX_SPAPR_SCSI_DISKS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.SPAPR_VSCSI).count()) {
        messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_SPAPR_VSCSI_DISKS);
    }
    if (!messages.isEmpty()) {
        return new ValidationResult(messages);
    }
    return ValidationResult.VALID;
}
Also used : Arrays(java.util.Arrays) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) Guid(org.ovirt.engine.core.compat.Guid) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) DbFacade(org.ovirt.engine.core.dal.dbbroker.DbFacade) ArrayList(java.util.ArrayList) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) ActionType(org.ovirt.engine.core.common.action.ActionType) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) Map(java.util.Map) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) ONLY_ACTIVE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE) Version(org.ovirt.engine.core.compat.Version) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) VmCommand(org.ovirt.engine.core.bll.VmCommand) Config(org.ovirt.engine.core.common.config.Config) ActionUtils(org.ovirt.engine.core.common.ActionUtils) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Predicate(java.util.function.Predicate) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) HostDeviceManager(org.ovirt.engine.core.bll.hostdev.HostDeviceManager) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskVmElementDao(org.ovirt.engine.core.dao.DiskVmElementDao) Collectors(java.util.stream.Collectors) SnapshotType(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType) ONLY_NOT_SHAREABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) DiskDao(org.ovirt.engine.core.dao.DiskDao) Injector(org.ovirt.engine.core.di.Injector) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) Collections(java.util.Collections) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) ArrayList(java.util.ArrayList) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 12 with DiskVmElement

use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement 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 13 with DiskVmElement

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

the class UpdateVmDiskCommandTest method clearAddressOnInterfaceChange.

@Test
public void clearAddressOnInterfaceChange() {
    // update new disk interface so it will be different than the old one
    command.getParameters().getDiskVmElement().setDiskInterface(DiskInterface.VirtIO);
    DiskImage diskFromDb = createDiskImage();
    doReturn(diskFromDb).when(diskDao).get(diskImageGuid);
    initializeCommand();
    DiskVmElement dve = new DiskVmElement(diskImageGuid, vmId);
    dve.setDiskInterface(DiskInterface.IDE);
    doReturn(dve).when(command).getOldDiskVmElement();
    mockVdsCommandSetVolumeDescription();
    assertNotSame(dve.getDiskInterface(), command.getParameters().getDiskVmElement().getDiskInterface());
    command.executeVmCommand();
    // verify that device address was cleared exactly once
    verify(vmDeviceDao).clearDeviceAddress(diskImageGuid);
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 14 with DiskVmElement

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

the class UpdateVmDiskCommandTest method testExtendingDiskWithQuota.

@Test
public void testExtendingDiskWithQuota() {
    Guid quotaId = Guid.newGuid();
    DiskImage oldDiskImage = createDiskImage();
    oldDiskImage.setQuotaId(quotaId);
    oldDiskImage.setSize(SizeConverter.convert(3L, SizeConverter.SizeUnit.GiB, SizeConverter.SizeUnit.BYTES).longValue());
    DiskImage newDiskImage = createDiskImage();
    newDiskImage.setQuotaId(quotaId);
    newDiskImage.setSize(SizeConverter.convert(5L, SizeConverter.SizeUnit.GiB, SizeConverter.SizeUnit.BYTES).longValue());
    command.getParameters().setDiskVmElement(new DiskVmElement(newDiskImage.getId(), vmId));
    command.getParameters().setDiskInfo(newDiskImage);
    long diskExtendingDiffInGB = newDiskImage.getSizeInGigabytes() - oldDiskImage.getSizeInGigabytes();
    when(diskDao.get(diskImageGuid)).thenReturn(oldDiskImage);
    initializeCommand();
    QuotaStorageConsumptionParameter consumptionParameter = (QuotaStorageConsumptionParameter) command.getQuotaStorageConsumptionParameters().get(0);
    assertEquals(consumptionParameter.getRequestedStorageGB().longValue(), diskExtendingDiffInGB);
}
Also used : QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 15 with DiskVmElement

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

the class UpdateVmDiskCommandTest method testAmendNotRunningWithExtend.

@Test
public void testAmendNotRunningWithExtend() {
    Guid quotaId = Guid.newGuid();
    DiskImage oldDiskImage = createDiskImage();
    oldDiskImage.setQuotaId(quotaId);
    oldDiskImage.setSize(SizeConverter.convert(3L, SizeConverter.SizeUnit.GiB, SizeConverter.SizeUnit.BYTES).longValue());
    oldDiskImage.setVolumeFormat(VolumeFormat.COW);
    oldDiskImage.setQcowCompat(QcowCompat.QCOW2_V2);
    DiskImage newDiskImage = createDiskImage();
    newDiskImage.setQuotaId(quotaId);
    newDiskImage.setSize(SizeConverter.convert(5L, SizeConverter.SizeUnit.GiB, SizeConverter.SizeUnit.BYTES).longValue());
    newDiskImage.setVolumeFormat(VolumeFormat.COW);
    newDiskImage.setQcowCompat(QcowCompat.QCOW2_V3);
    command.getParameters().setDiskVmElement(new DiskVmElement(newDiskImage.getId(), vmId));
    command.getParameters().setDiskInfo(newDiskImage);
    when(diskDao.get(diskImageGuid)).thenReturn(oldDiskImage);
    mockGetAllSnapshotsForDisk(Collections.singletonList(oldDiskImage));
    initializeCommand();
    ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.ACTION_TYPE_FAILED_AMEND_AND_EXTEND_IN_ONE_OPERATION);
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Aggregations

DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)91 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)30 Test (org.junit.Test)26 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)23 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)22 Guid (org.ovirt.engine.core.compat.Guid)17 ArrayList (java.util.ArrayList)16 VM (org.ovirt.engine.core.common.businessentities.VM)12 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)11 HashMap (java.util.HashMap)8 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)8 Map (java.util.Map)7 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)7 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)7 ActionType (org.ovirt.engine.core.common.action.ActionType)6 AttachDetachVmDiskParameters (org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 VmDiskOperationParameterBase (org.ovirt.engine.core.common.action.VmDiskOperationParameterBase)5 Collection (java.util.Collection)4