|
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;
|
@@ -6415,4 +6418,114 @@ public void calculateVmMetricsTestOldStatsIsNotNullCalculatesUtilization() throw
|
6415 | 6418 | Assert.assertEquals(newStats.getDiskReadKBs() - oldStats.getDiskReadKBs(), metrics.getDiskReadKBs(), 0);
|
6416 | 6419 | Assert.assertEquals(newStats.getDiskWriteKBs() - oldStats.getDiskWriteKBs(), metrics.getDiskWriteKBs(), 0);
|
6417 | 6420 | }
|
| 6421 | + |
| 6422 | + @Test |
| 6423 | + public void createLinstorVdb() throws LibvirtException, InternalErrorException, URISyntaxException { |
| 6424 | + final Connect connect = Mockito.mock(Connect.class); |
| 6425 | + |
| 6426 | + final int id = random.nextInt(65534); |
| 6427 | + final String name = "test-instance-1"; |
| 6428 | + |
| 6429 | + final int cpus = 2; |
| 6430 | + final int speed = 1024; |
| 6431 | + final int minRam = 256 * 1024; |
| 6432 | + final int maxRam = 512 * 1024; |
| 6433 | + final String os = "Ubuntu"; |
| 6434 | + final String vncPassword = "mySuperSecretPassword"; |
| 6435 | + |
| 6436 | + final VirtualMachineTO to = new VirtualMachineTO(id, name, VirtualMachine.Type.User, cpus, speed, minRam, |
| 6437 | + maxRam, BootloaderType.HVM, os, false, false, vncPassword); |
| 6438 | + to.setVncAddr(""); |
| 6439 | + to.setArch("x86_64"); |
| 6440 | + to.setUuid("b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9"); |
| 6441 | + to.setVcpuMaxLimit(cpus + 1); |
| 6442 | + final HashMap<String, String> vmToDetails = new HashMap<>(); |
| 6443 | + to.setDetails(vmToDetails); |
| 6444 | + |
| 6445 | + String diskLinPath = "9ebe53c1-3d35-46e5-b7aa-6fc223ba0fcf"; |
| 6446 | + final DiskTO diskTO = new DiskTO(); |
| 6447 | + diskTO.setDiskSeq(1L); |
| 6448 | + diskTO.setType(Volume.Type.ROOT); |
| 6449 | + diskTO.setDetails(new HashMap<>()); |
| 6450 | + diskTO.setPath(diskLinPath); |
| 6451 | + |
| 6452 | + final PrimaryDataStoreTO primaryDataStoreTO = Mockito.mock(PrimaryDataStoreTO.class); |
| 6453 | + String pDSTOUUID = "9ebe53c1-3d35-46e5-b7aa-6fc223ac4fcf"; |
| 6454 | + when(primaryDataStoreTO.getPoolType()).thenReturn(StoragePoolType.Linstor); |
| 6455 | + when(primaryDataStoreTO.getUuid()).thenReturn(pDSTOUUID); |
| 6456 | + |
| 6457 | + VolumeObjectTO dataTO = new VolumeObjectTO(); |
| 6458 | + |
| 6459 | + dataTO.setUuid("12be53c1-3d35-46e5-b7aa-6fc223ba0f34"); |
| 6460 | + dataTO.setPath(diskTO.getPath()); |
| 6461 | + dataTO.setDataStore(primaryDataStoreTO); |
| 6462 | + diskTO.setData(dataTO); |
| 6463 | + to.setDisks(new DiskTO[]{diskTO}); |
| 6464 | + |
| 6465 | + String path = "/dev/drbd1020"; |
| 6466 | + final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class); |
| 6467 | + final KVMStoragePool storagePool = Mockito.mock(KVMStoragePool.class); |
| 6468 | + final KVMPhysicalDisk vol = Mockito.mock(KVMPhysicalDisk.class); |
| 6469 | + |
| 6470 | + when(libvirtComputingResourceSpy.getStoragePoolMgr()).thenReturn(storagePoolMgr); |
| 6471 | + when(storagePool.getType()).thenReturn(StoragePoolType.Linstor); |
| 6472 | + when(storagePoolMgr.getPhysicalDisk(StoragePoolType.Linstor, pDSTOUUID, diskLinPath)).thenReturn(vol); |
| 6473 | + when(vol.getPath()).thenReturn(path); |
| 6474 | + when(vol.getPool()).thenReturn(storagePool); |
| 6475 | + when(vol.getFormat()).thenReturn(PhysicalDiskFormat.RAW); |
| 6476 | + |
| 6477 | + // 1. test Bus: IDE and broken qemu version -> NO discard |
| 6478 | + when(libvirtComputingResourceSpy.getHypervisorQemuVersion()).thenReturn(6000000L); |
| 6479 | + vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.IDE.name()); |
| 6480 | + { |
| 6481 | + LibvirtVMDef vm = new LibvirtVMDef(); |
| 6482 | + vm.addComp(new DevicesDef()); |
| 6483 | + libvirtComputingResourceSpy.createVbd(connect, to, name, vm); |
| 6484 | + |
| 6485 | + DiskDef rootDisk = vm.getDevices().getDisks().get(0); |
| 6486 | + assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType()); |
| 6487 | + assertEquals(DiskDef.DiskBus.IDE, rootDisk.getBusType()); |
| 6488 | + assertEquals(DiskDef.DiscardType.IGNORE, rootDisk.getDiscard()); |
| 6489 | + } |
| 6490 | + |
| 6491 | + // 2. test Bus: VIRTIO and broken qemu version -> discard unmap |
| 6492 | + vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.VIRTIO.name()); |
| 6493 | + { |
| 6494 | + LibvirtVMDef vm = new LibvirtVMDef(); |
| 6495 | + vm.addComp(new DevicesDef()); |
| 6496 | + libvirtComputingResourceSpy.createVbd(connect, to, name, vm); |
| 6497 | + |
| 6498 | + DiskDef rootDisk = vm.getDevices().getDisks().get(0); |
| 6499 | + assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType()); |
| 6500 | + assertEquals(DiskDef.DiskBus.VIRTIO, rootDisk.getBusType()); |
| 6501 | + assertEquals(DiskDef.DiscardType.UNMAP, rootDisk.getDiscard()); |
| 6502 | + } |
| 6503 | + |
| 6504 | + // 3. test Bus; IDE and "good" qemu version -> discard unmap |
| 6505 | + vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.IDE.name()); |
| 6506 | + when(libvirtComputingResourceSpy.getHypervisorQemuVersion()).thenReturn(7000000L); |
| 6507 | + { |
| 6508 | + LibvirtVMDef vm = new LibvirtVMDef(); |
| 6509 | + vm.addComp(new DevicesDef()); |
| 6510 | + libvirtComputingResourceSpy.createVbd(connect, to, name, vm); |
| 6511 | + |
| 6512 | + DiskDef rootDisk = vm.getDevices().getDisks().get(0); |
| 6513 | + assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType()); |
| 6514 | + assertEquals(DiskDef.DiskBus.IDE, rootDisk.getBusType()); |
| 6515 | + assertEquals(DiskDef.DiscardType.UNMAP, rootDisk.getDiscard()); |
| 6516 | + } |
| 6517 | + |
| 6518 | + // 4. test Bus: VIRTIO and "good" qemu version -> discard unmap |
| 6519 | + vmToDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, DiskDef.DiskBus.VIRTIO.name()); |
| 6520 | + { |
| 6521 | + LibvirtVMDef vm = new LibvirtVMDef(); |
| 6522 | + vm.addComp(new DevicesDef()); |
| 6523 | + libvirtComputingResourceSpy.createVbd(connect, to, name, vm); |
| 6524 | + |
| 6525 | + DiskDef rootDisk = vm.getDevices().getDisks().get(0); |
| 6526 | + assertEquals(DiskDef.DiskType.BLOCK, rootDisk.getDiskType()); |
| 6527 | + assertEquals(DiskDef.DiskBus.VIRTIO, rootDisk.getBusType()); |
| 6528 | + assertEquals(DiskDef.DiscardType.UNMAP, rootDisk.getDiscard()); |
| 6529 | + } |
| 6530 | + } |
6418 | 6531 | }
|
0 commit comments