use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class AttachDiskToVmCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
if (!isOperationPerformedOnDiskSnapshot()) {
vmStaticDao.incrementDbGeneration(getVm().getId());
}
final VmDevice vmDevice = createVmDevice();
vmDeviceDao.save(vmDevice);
DiskVmElement diskVmElement = getDiskVmElement();
diskVmElement.getId().setDeviceId(disk.getId());
diskVmElementDao.save(diskVmElement);
// When performing hot plug for VirtIO-SCSI or SPAPR_VSCSI the address map calculation needs this info to be populated
disk.setDiskVmElements(Collections.singletonList(diskVmElement));
// update cached image
List<Disk> imageList = new ArrayList<>();
imageList.add(disk);
vmHandler.updateDisksForVm(getVm(), imageList);
if (!isOperationPerformedOnDiskSnapshot()) {
if (disk.isAllowSnapshot()) {
updateDiskVmSnapshotId();
}
}
if (getParameters().isPlugUnPlug() && getVm().getStatus() != VMStatus.Down) {
performPlugCommand(VDSCommandType.HotPlugDisk, disk, vmDevice);
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class UpdateVmDiskCommandTest method validateDiscardFailedNotSupportedByDcVersion.
@Test
public void validateDiscardFailedNotSupportedByDcVersion() {
when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage());
initializeCommand();
command.getParameters().getDiskVmElement().setPassDiscard(true);
DiskVmElement oldDiskVmElement = new DiskVmElement();
oldDiskVmElement.setPassDiscard(false);
doReturn(oldDiskVmElement).when(command).getOldDiskVmElement();
command.getStoragePool().setCompatibilityVersion(Version.v4_0);
ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.ACTION_TYPE_FAILED_PASS_DISCARD_NOT_SUPPORTED_BY_DC_VERSION);
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class UpdateVmDiskCommandTest method testUpdateDiskInterfaceUnsupported.
@Test
public void testUpdateDiskInterfaceUnsupported() {
command.getParameters().getDiskVmElement().setDiskInterface(DiskInterface.IDE);
initializeCommand();
mockVdsCommandSetVolumeDescription();
DiskVmElement dve = new DiskVmElement(diskImageGuid, vmId);
dve.setDiskInterface(DiskInterface.VirtIO);
doReturn(dve).when(command).getOldDiskVmElement();
doReturn(createDiskImage()).when(command).getOldDisk();
stubVmDevice(diskImageGuid, vmId);
when(diskVmElementValidator.isDiskInterfaceSupported(any())).thenReturn(new ValidationResult(EngineMessage.ACTION_TYPE_DISK_INTERFACE_UNSUPPORTED));
when(command.getDiskValidator(command.getParameters().getDiskInfo())).thenReturn(diskValidator);
ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.ACTION_TYPE_DISK_INTERFACE_UNSUPPORTED);
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class UpdateVmDiskCommandTest method mockToUpdateDiskVm.
private void mockToUpdateDiskVm(VM vm) {
when(vmDao.get(command.getParameters().getVmId())).thenReturn(vm);
when(diskVmElementDao.get(new VmDeviceId(command.getParameters().getDiskInfo().getId(), vm.getId()))).thenReturn(new DiskVmElement());
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class AddDiskCommandTest method mockOtherVmDisks.
private void mockOtherVmDisks(VM vm, int numOfDisks, DiskInterface iface) {
List<DiskVmElement> otherDisks = new ArrayList<>(numOfDisks);
for (int i = 0; i < numOfDisks; i++) {
DiskVmElement dve = new DiskVmElement(Guid.newGuid(), vm.getId());
dve.setDiskInterface(iface);
otherDisks.add(dve);
}
doReturn(otherDisks).when(diskVmElementDao).getAllForVm(vmId);
}
Aggregations