Search in sources :

Example 46 with DiskVmElement

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);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) ArrayList(java.util.ArrayList) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 47 with DiskVmElement

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);
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 48 with DiskVmElement

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);
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 49 with DiskVmElement

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());
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 50 with 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);
}
Also used : ArrayList(java.util.ArrayList) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)

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