|
58 | 58 |
|
59 | 59 | import com.cloud.utils.net.NetUtils; |
60 | 60 |
|
| 61 | +import com.cloud.vm.VmDetailConstants; |
61 | 62 | import org.apache.cloudstack.api.ApiConstants.IoDriverPolicy; |
62 | 63 | import org.apache.cloudstack.storage.command.AttachAnswer; |
63 | 64 | import org.apache.cloudstack.storage.command.AttachCommand; |
| 65 | +import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; |
| 66 | +import org.apache.cloudstack.storage.to.VolumeObjectTO; |
64 | 67 | import org.apache.cloudstack.utils.bytescale.ByteScaleUtils; |
65 | 68 | import org.apache.cloudstack.utils.linux.CPUStat; |
66 | 69 | import org.apache.cloudstack.utils.linux.MemStat; |
@@ -6295,4 +6298,114 @@ public void setMaxHostCpuSharesIfCGroupV2TestShouldNotCalculateMaxCpuCapacityIfH |
6295 | 6298 | Assert.assertEquals(expectedShares, libvirtComputingResourceSpy.getHostCpuMaxCapacity()); |
6296 | 6299 | } |
6297 | 6300 | } |
| 6301 | + |
| 6302 | + @Test |
| 6303 | + public void createLinstorVdb() throws LibvirtException, InternalErrorException, URISyntaxException { |
| 6304 | + final Connect connect = Mockito.mock(Connect.class); |
| 6305 | + |
| 6306 | + final int id = random.nextInt(65534); |
| 6307 | + final String name = "test-instance-1"; |
| 6308 | + |
| 6309 | + final int cpus = 2; |
| 6310 | + final int speed = 1024; |
| 6311 | + final int minRam = 256 * 1024; |
| 6312 | + final int maxRam = 512 * 1024; |
| 6313 | + final String os = "Ubuntu"; |
| 6314 | + final String vncPassword = "mySuperSecretPassword"; |
| 6315 | + |
| 6316 | + final VirtualMachineTO to = new VirtualMachineTO(id, name, VirtualMachine.Type.User, cpus, speed, minRam, |
| 6317 | + maxRam, BootloaderType.HVM, os, false, false, vncPassword); |
| 6318 | + to.setVncAddr(""); |
| 6319 | + to.setArch("x86_64"); |
| 6320 | + to.setUuid("b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9"); |
| 6321 | + to.setVcpuMaxLimit(cpus + 1); |
| 6322 | + final HashMap<String, String> vmToDetails = new HashMap<>(); |
| 6323 | + to.setDetails(vmToDetails); |
| 6324 | + |
| 6325 | + String diskLinPath = "9ebe53c1-3d35-46e5-b7aa-6fc223ba0fcf"; |
| 6326 | + final DiskTO diskTO = new DiskTO(); |
| 6327 | + diskTO.setDiskSeq(1L); |
| 6328 | + diskTO.setType(Volume.Type.ROOT); |
| 6329 | + diskTO.setDetails(new HashMap<>()); |
| 6330 | + diskTO.setPath(diskLinPath); |
| 6331 | + |
| 6332 | + final PrimaryDataStoreTO primaryDataStoreTO = Mockito.mock(PrimaryDataStoreTO.class); |
| 6333 | + String pDSTOUUID = "9ebe53c1-3d35-46e5-b7aa-6fc223ac4fcf"; |
| 6334 | + when(primaryDataStoreTO.getPoolType()).thenReturn(StoragePoolType.Linstor); |
| 6335 | + when(primaryDataStoreTO.getUuid()).thenReturn(pDSTOUUID); |
| 6336 | + |
| 6337 | + VolumeObjectTO dataTO = new VolumeObjectTO(); |
| 6338 | + |
| 6339 | + dataTO.setUuid("12be53c1-3d35-46e5-b7aa-6fc223ba0f34"); |
| 6340 | + dataTO.setPath(diskTO.getPath()); |
| 6341 | + dataTO.setDataStore(primaryDataStoreTO); |
| 6342 | + diskTO.setData(dataTO); |
| 6343 | + to.setDisks(new DiskTO[]{diskTO}); |
| 6344 | + |
| 6345 | + String path = "/dev/drbd1020"; |
| 6346 | + final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class); |
| 6347 | + final KVMStoragePool storagePool = Mockito.mock(KVMStoragePool.class); |
| 6348 | + final KVMPhysicalDisk vol = Mockito.mock(KVMPhysicalDisk.class); |
| 6349 | + |
| 6350 | + when(libvirtComputingResourceSpy.getStoragePoolMgr()).thenReturn(storagePoolMgr); |
| 6351 | + when(storagePool.getType()).thenReturn(StoragePoolType.Linstor); |
| 6352 | + when(storagePoolMgr.getPhysicalDisk(StoragePoolType.Linstor, pDSTOUUID, diskLinPath)).thenReturn(vol); |
| 6353 | + when(vol.getPath()).thenReturn(path); |
| 6354 | + when(vol.getPool()).thenReturn(storagePool); |
| 6355 | + when(vol.getFormat()).thenReturn(PhysicalDiskFormat.RAW); |
| 6356 | + |
| 6357 | + // 1. test Bus: IDE and broken qemu version -> NO discard |
| 6358 | + when(libvirtComputingResourceSpy.getHypervisorQemuVersion()).thenReturn(6000000L); |
| 6359 | + vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.IDE.name()); |
| 6360 | + { |
| 6361 | + LibvirtVMDef vm = new LibvirtVMDef(); |
| 6362 | + vm.addComp(new DevicesDef()); |
| 6363 | + libvirtComputingResourceSpy.createVbd(connect, to, name, vm); |
| 6364 | + |
| 6365 | + DiskDef rootDisk = vm.getDevices().getDisks().get(0); |
| 6366 | + assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType()); |
| 6367 | + assertEquals(DiskDef.DiskBus.IDE, rootDisk.getBusType()); |
| 6368 | + assertEquals(DiskDef.DiscardType.IGNORE, rootDisk.getDiscard()); |
| 6369 | + } |
| 6370 | + |
| 6371 | + // 2. test Bus: VIRTIO and broken qemu version -> discard unmap |
| 6372 | + vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.VIRTIO.name()); |
| 6373 | + { |
| 6374 | + LibvirtVMDef vm = new LibvirtVMDef(); |
| 6375 | + vm.addComp(new DevicesDef()); |
| 6376 | + libvirtComputingResourceSpy.createVbd(connect, to, name, vm); |
| 6377 | + |
| 6378 | + DiskDef rootDisk = vm.getDevices().getDisks().get(0); |
| 6379 | + assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType()); |
| 6380 | + assertEquals(DiskDef.DiskBus.VIRTIO, rootDisk.getBusType()); |
| 6381 | + assertEquals(DiskDef.DiscardType.UNMAP, rootDisk.getDiscard()); |
| 6382 | + } |
| 6383 | + |
| 6384 | + // 3. test Bus; IDE and "good" qemu version -> discard unmap |
| 6385 | + vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.IDE.name()); |
| 6386 | + when(libvirtComputingResourceSpy.getHypervisorQemuVersion()).thenReturn(7000000L); |
| 6387 | + { |
| 6388 | + LibvirtVMDef vm = new LibvirtVMDef(); |
| 6389 | + vm.addComp(new DevicesDef()); |
| 6390 | + libvirtComputingResourceSpy.createVbd(connect, to, name, vm); |
| 6391 | + |
| 6392 | + DiskDef rootDisk = vm.getDevices().getDisks().get(0); |
| 6393 | + assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType()); |
| 6394 | + assertEquals(DiskDef.DiskBus.IDE, rootDisk.getBusType()); |
| 6395 | + assertEquals(DiskDef.DiscardType.UNMAP, rootDisk.getDiscard()); |
| 6396 | + } |
| 6397 | + |
| 6398 | + // 4. test Bus: VIRTIO and "good" qemu version -> discard unmap |
| 6399 | + vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.VIRTIO.name()); |
| 6400 | + { |
| 6401 | + LibvirtVMDef vm = new LibvirtVMDef(); |
| 6402 | + vm.addComp(new DevicesDef()); |
| 6403 | + libvirtComputingResourceSpy.createVbd(connect, to, name, vm); |
| 6404 | + |
| 6405 | + DiskDef rootDisk = vm.getDevices().getDisks().get(0); |
| 6406 | + assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType()); |
| 6407 | + assertEquals(DiskDef.DiskBus.VIRTIO, rootDisk.getBusType()); |
| 6408 | + assertEquals(DiskDef.DiscardType.UNMAP, rootDisk.getDiscard()); |
| 6409 | + } |
| 6410 | + } |
6298 | 6411 | } |
0 commit comments