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;
}
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());
}
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);
}
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);
}
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);
}
Aggregations