Skip to content

Commit 8827182

Browse files
KVM: add unit test for RBD format on the import/manage-volume flow
importVolume (managing a previously-unmanaged volume) routes through VolumeOrchestrator.importVolume() and therefore also benefits from the pool-type-aware format fix (RBD -> RAW). Add a VolumeImportUnmanageManagerImplTest case asserting the RBD pool type and KVM hypervisor are forwarded to the orchestrator.
1 parent f720a9a commit 8827182

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

server/src/test/java/org/apache/cloudstack/storage/volume/VolumeImportUnmanageManagerImplTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,55 @@ public void testImportVolumeAllGood() throws ResourceAllocationException {
290290
}
291291
}
292292

293+
@Test
294+
public void testImportVolumeForwardsRbdPoolTypeToOrchestrator() throws ResourceAllocationException {
295+
ImportVolumeCmd cmd = mock(ImportVolumeCmd.class);
296+
when(cmd.getPath()).thenReturn(path);
297+
when(cmd.getStorageId()).thenReturn(poolId);
298+
when(cmd.getDiskOfferingId()).thenReturn(diskOfferingId);
299+
when(volumeDao.findByPoolIdAndPath(poolId, path)).thenReturn(null);
300+
when(templatePoolDao.findByPoolPath(poolId, path)).thenReturn(null);
301+
302+
// Import a KVM volume residing on an RBD (Ceph) pool
303+
when(storagePoolVO.getPoolType()).thenReturn(Storage.StoragePoolType.RBD);
304+
305+
VolumeOnStorageTO volumeOnStorageTO = new VolumeOnStorageTO(Hypervisor.HypervisorType.KVM, path, name, fullPath,
306+
"raw", size, virtualSize);
307+
List<VolumeOnStorageTO> volumesOnStorageTO = new ArrayList<>();
308+
volumesOnStorageTO.add(volumeOnStorageTO);
309+
doReturn(volumesOnStorageTO).when(volumeImportUnmanageManager).listVolumesForImportInternal(storagePoolVO, path, null);
310+
311+
doNothing().when(volumeImportUnmanageManager).checkIfVolumeIsLocked(volumeOnStorageTO);
312+
doNothing().when(volumeImportUnmanageManager).checkIfVolumeIsEncrypted(volumeOnStorageTO);
313+
doNothing().when(volumeImportUnmanageManager).checkIfVolumeHasBackingFile(volumeOnStorageTO);
314+
315+
DiskOfferingVO diskOffering = mock(DiskOfferingVO.class);
316+
when(diskOffering.isCustomized()).thenReturn(true);
317+
doReturn(diskOffering).when(volumeImportUnmanageManager).getOrCreateDiskOffering(account, diskOfferingId, zoneId, isLocal);
318+
doNothing().when(volumeApiService).validateCustomDiskOfferingSizeRange(anyLong());
319+
doReturn(true).when(volumeApiService).doesStoragePoolSupportDiskOffering(any(), any());
320+
doReturn(diskProfile).when(volumeManager).importVolume(any(), anyString(), any(), eq(virtualSize), isNull(), isNull(), anyLong(),
321+
any(), isNull(), isNull(), any(), isNull(), anyLong(), any(), anyString(), isNull());
322+
when(diskProfile.getVolumeId()).thenReturn(volumeId);
323+
when(volumeDao.findById(volumeId)).thenReturn(volumeVO);
324+
325+
doNothing().when(resourceLimitService).incrementResourceCount(accountId, Resource.ResourceType.volume);
326+
doNothing().when(resourceLimitService).incrementResourceCount(accountId, Resource.ResourceType.primary_storage, virtualSize);
327+
328+
VolumeResponse response = mock(VolumeResponse.class);
329+
doReturn(response).when(responseGenerator).createVolumeResponse(ResponseObject.ResponseView.Full, volumeVO);
330+
try (MockedStatic<UsageEventUtils> ignored = Mockito.mockStatic(UsageEventUtils.class);
331+
MockedStatic<ActionEventUtils> ignoredtoo = Mockito.mockStatic(ActionEventUtils.class)) {
332+
volumeImportUnmanageManager.importVolume(cmd);
333+
}
334+
335+
// The RBD pool type and KVM hypervisor are forwarded to the orchestrator, which is what makes the
336+
// imported volume be recorded with RAW format (see VolumeOrchestrator.getSupportedImageFormatForCluster).
337+
verify(volumeManager).importVolume(eq(Volume.Type.DATADISK), anyString(), any(), eq(virtualSize), isNull(), isNull(),
338+
anyLong(), eq(Hypervisor.HypervisorType.KVM), isNull(), isNull(), any(), isNull(), anyLong(),
339+
eq(Storage.StoragePoolType.RBD), anyString(), isNull());
340+
}
341+
293342
@Test
294343
public void testListVolumesForImportInternal() {
295344
Pair<HostVO, String> hostAndLocalPath = mock(Pair.class);

0 commit comments

Comments
 (0)