Search in sources :

Example 61 with VmDeviceId

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());
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) Test(org.junit.Test)

Example 62 with VmDeviceId

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);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VM(org.ovirt.engine.core.common.businessentities.VM) Map(java.util.Map) HashMap(java.util.HashMap) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) Test(org.junit.Test)

Example 63 with VmDeviceId

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

Example 64 with VmDeviceId

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());
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test)

Example 65 with VmDeviceId

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

Aggregations

VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)75 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)40 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)21 Guid (org.ovirt.engine.core.compat.Guid)19 HashMap (java.util.HashMap)13 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)12 Test (org.junit.Test)10 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)9 ArrayList (java.util.ArrayList)7 Map (java.util.Map)5 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 VmPayload (org.ovirt.engine.core.common.businessentities.VmPayload)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)4 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)3 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)3