use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class StorageDomainDaoTest method testIsHostedEngineStorage.
@Test
public void testIsHostedEngineStorage() {
// create hosted engine vm
VmStatic vm = new VmStatic();
vm.setId(Guid.newGuid());
vm.setOrigin(OriginType.HOSTED_ENGINE);
dbFacade.getVmStaticDao().save(vm);
// create disk for HE
DiskImage disk = new DiskImage();
disk.setId(Guid.newGuid());
disk.setImageId(Guid.newGuid());
disk.setActive(true);
disk.setVolumeType(VolumeType.Preallocated);
disk.setVolumeFormat(VolumeFormat.RAW);
dbFacade.getImageDao().save(disk.getImage());
dbFacade.getBaseDiskDao().save(disk);
ImageStorageDomainMap map = new ImageStorageDomainMap(disk.getImageId(), existingDomain.getId(), null, null);
dbFacade.getImageStorageDomainMapDao().save(map);
// attach disk
VmDevice device = new VmDevice(new VmDeviceId(disk.getId(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.DISK.getName(), "", null, true, false, false, "", null, null, null);
dbFacade.getVmDeviceDao().save(device);
DiskVmElement diskVmElement = new DiskVmElement(device.getId());
diskVmElement.setDiskInterface(DiskInterface.IDE);
dbFacade.getDiskVmElementDao().save(diskVmElement);
// run test
StorageDomain domain = dao.get(existingDomain.getId());
assertTrue(domain.isHostedEngineStorage());
// change origin
vm.setOrigin(OriginType.MANAGED_HOSTED_ENGINE);
dbFacade.getVmStaticDao().update(vm);
// run test again
domain = dao.get(existingDomain.getId());
assertTrue(domain.isHostedEngineStorage());
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmInfoBuildUtilsTest method testGetVmDeviceUnitMapForScsiDisks.
@Test
public void testGetVmDeviceUnitMapForScsiDisks() {
VmDevice lunDiskVmDevice = new VmDevice(new VmDeviceId(LUN_DISK_ID, VM_ID), VmDeviceGeneralType.DISK, VmDeviceType.DISK.getName(), "", null, true, true, null, "", null, null, null);
VmDevice diskImageVmDevice = new VmDevice(new VmDeviceId(DISK_IMAGE_ID, VM_ID), VmDeviceGeneralType.DISK, VmDeviceType.DISK.getName(), "", null, true, true, null, "", null, null, null);
VM vm = new VM();
vm.setId(VM_ID);
vm.setDiskMap(mockUnsortedDisksMap(lunDiskVmDevice, diskImageVmDevice));
vm.setClusterArch(ArchitectureType.x86_64);
vm.setClusterCompatibilityVersion(Version.v4_1);
mcr.mockConfigValue(ConfigValues.VirtIOScsiIOThread, Version.v4_1, true);
Map<Integer, Map<VmDevice, Integer>> vmDeviceUnitMap = underTest.getVmDeviceUnitMapForScsiDisks(vm, DiskInterface.VirtIO_SCSI, false, false);
// Ensures that the boot disk unit is lower
assertEquals(vmDeviceUnitMap.get(0).get(lunDiskVmDevice), (Integer) 1);
assertEquals(vmDeviceUnitMap.get(0).get(diskImageVmDevice), (Integer) 0);
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmDevicesMonitoringTest method testIgnoreDeviceChangeBeforeFullList.
@Test
public void testIgnoreDeviceChangeBeforeFullList() {
initDevices(getVmDevice(CDROM_DEVICE_ID, VM_ID, VmDeviceGeneralType.DISK, "cdrom", true));
initDumpXmls();
vmDevicesMonitoring.initDevicesStatuses(2L);
VmDevicesMonitoring.Change change = vmDevicesMonitoring.createChange(1L);
change.removeDevice(new VmDeviceId(CDROM_DEVICE_ID, VM_ID));
change.flush();
verify(resourceManager, never()).runVdsCommand(eq(VDSCommandType.DumpXmls), any());
verify(vmDeviceDao, never()).updateAllInBatch(any());
verify(vmDeviceDao, never()).removeAll(any());
verify(vmDeviceDao, never()).saveAll(any());
verify(vmDynamicDao, never()).updateDevicesHashes(any());
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmDevicesMonitoringTest method testUpdateVm.
@Test
public void testUpdateVm() {
final Guid usbControllerId = Guid.newGuid();
initDevices(getVmDevice(usbControllerId, VM_ID, VmDeviceGeneralType.CONTROLLER, "usb", false), getVmDevice(VIDEO_DEVICE_ID, VM_ID, VmDeviceGeneralType.VIDEO, "cirrus", true), getVmDevice(CDROM_DEVICE_ID, VM_ID, VmDeviceGeneralType.DISK, "cdrom", true));
initDumpXmls(getDeviceInfo(null, "balloon", "memballoon", null), getDeviceInfo(null, "controller", "virtio-serial", SERIAL_DEVICE_ADDRESS), getDeviceInfo(VIDEO_DEVICE_ID, "video", "cirrus", VIDEO_DEVICE_ADDRESS), getDeviceInfo(CDROM_DEVICE_ID, "disk", "cdrom", CDROM_DEVICE_ADDRESS));
vmDevicesMonitoring.initDevicesStatuses(1L);
VmDevicesMonitoring.Change change = vmDevicesMonitoring.createChange(VDS_ID, 2L);
change.updateVm(VM_ID, NEW_HASH);
change.flush();
ArgumentCaptor<Collection> updateCaptor = ArgumentCaptor.forClass(Collection.class);
verify(vmDeviceDao, times(1)).updateAllInBatch(updateCaptor.capture());
assertEquals(2, updateCaptor.getValue().size());
ArgumentCaptor<List> removeCaptor = ArgumentCaptor.forClass(List.class);
verify(vmDeviceDao, times(1)).removeAll(removeCaptor.capture());
List removedDeviceIds = removeCaptor.getValue();
assertEquals(1, removedDeviceIds.size());
VmDeviceId deviceId = (VmDeviceId) removedDeviceIds.get(0);
assertEquals(deviceId.getDeviceId(), usbControllerId);
assertEquals(VM_ID, deviceId.getVmId());
ArgumentCaptor<List> saveCaptor = ArgumentCaptor.forClass(List.class);
verify(vmDeviceDao, times(1)).saveAll(saveCaptor.capture());
List savedDevices = saveCaptor.getValue();
assertEquals(1, savedDevices.size());
VmDevice device = (VmDevice) savedDevices.get(0);
assertEquals(SERIAL_DEVICE_ADDRESS, device.getAddress());
ArgumentCaptor<List> updateHashesCaptor = ArgumentCaptor.forClass(List.class);
verify(vmDynamicDao, times(1)).updateDevicesHashes(updateHashesCaptor.capture());
List updatedHashes = updateHashesCaptor.getValue();
assertEquals(1, updatedHashes.size());
Pair<Guid, String> hashInfo = (Pair<Guid, String>) updatedHashes.get(0);
assertEquals(VM_ID, hashInfo.getFirst());
assertEquals(NEW_HASH, hashInfo.getSecond());
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmDeviceCommonUtils method addGraphicsDevice.
public static void addGraphicsDevice(VmBase vmBase, VmDeviceType vmDeviceType) {
GraphicsDevice graphicsDevice = new GraphicsDevice(vmDeviceType);
graphicsDevice.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
vmBase.getManagedDeviceMap().put(graphicsDevice.getDeviceId(), graphicsDevice);
}
Aggregations