@@ -688,6 +688,66 @@ public void testResizeVolumeFromCustomSizeIopsPerGbToFixedSizeFixedIops() throws
688688 }
689689 }
690690
691+ @ Test
692+ public void testResizeVolumeFromCustomSizeIopsPerGbToCustomSizeIopsPerGb () throws NoSuchFieldException , IllegalAccessException {
693+ Long oldSize = 10L * 1024 * 1024 * 1024 ;
694+ Long oldSizeGb = 10L ;
695+ Long oldMinIopsPerGb = 10L ;
696+ Long oldMaxIopsPerGb = 30L ;
697+
698+ Long newSize = 10L * 1024 * 1024 * 1024 ;
699+ Long newSizeGb = 10L ;
700+ Long newMinIopsPerGb = 20L ;
701+ Long newMaxIopsPerGb = 50L ;
702+
703+ ResizeVolumeCmd resizeVolumeCmd = Mockito .mock (ResizeVolumeCmd .class );
704+ when (resizeVolumeCmd .getNewDiskOfferingId ()).thenReturn (2L );
705+ when (resizeVolumeCmd .getEntityId ()).thenReturn (1L );
706+
707+ VolumeVO volumeVO = new VolumeVO (Volume .Type .DATADISK , "test-vol" , 1 , 1 , 1 , 1 , Storage .ProvisioningType .THIN ,
708+ oldSize , oldSizeGb * oldMinIopsPerGb , oldSizeGb * oldMaxIopsPerGb , null );
709+
710+ Field IdField = VolumeVO .class .getDeclaredField ("id" );
711+ IdField .setAccessible (true );
712+ IdField .set (volumeVO , 1L );
713+
714+ Field maxVolSizeField = _svc .getClass ().getDeclaredField ("_maxVolumeSizeInGb" );
715+ maxVolSizeField .setAccessible (true );
716+ maxVolSizeField .setLong (_svc , 2 * 1024 ); // 2 TB max vol size
717+
718+ DiskOfferingVO diskOfferingVO = new DiskOfferingVO (1L , "custom-size-iopspergb-old" , "custom-size-iopspergb-old" , Storage .ProvisioningType .THIN ,
719+ 0L , "" , true , false , null , null , null );
720+ diskOfferingVO .setMinIopsPerGb (oldMinIopsPerGb );
721+ diskOfferingVO .setMaxIopsPerGb (oldMaxIopsPerGb );
722+
723+ DiskOfferingVO newDiskOfferingVO = new DiskOfferingVO (1L ,"custom-size-iopspergb-new" ,"custom-size-iopspergb-new" ,
724+ Storage .ProvisioningType .THIN , newSize , "" , false , false , null , null , null );
725+ newDiskOfferingVO .setMinIopsPerGb (newMinIopsPerGb );
726+ newDiskOfferingVO .setMaxIopsPerGb (newMaxIopsPerGb );
727+
728+ VolumeVO newVolume ;
729+
730+ when (_svc ._volsDao .findById (1L )).thenReturn (volumeVO );
731+ when (_svc ._volsDao .getHypervisorType (1L )).thenReturn (HypervisorType .XenServer );
732+ when (_svc ._volsDao .update (anyLong (), any (VolumeVO .class ))).thenReturn (true );
733+
734+ when (_svc ._vmSnapshotDao .findByVm (anyLong ())).thenReturn (new ArrayList <VMSnapshotVO >());
735+
736+ when (_svc ._diskOfferingDao .findById (1L )).thenReturn (diskOfferingVO );
737+ when (_svc ._diskOfferingDao .findById (2L )).thenReturn (newDiskOfferingVO );
738+ doNothing ().when (_svc ._configMgr ).checkDiskOfferingAccess (any (Account .class ), any (DiskOffering .class ));
739+
740+ try {
741+ newVolume = _svc .resizeVolume (resizeVolumeCmd );
742+ Assert .assertEquals (new Long (newMinIopsPerGb * newSizeGb ), newVolume .getMinIops ());
743+ Assert .assertEquals (new Long (newMaxIopsPerGb * newSizeGb ), newVolume .getMaxIops ());
744+ Assert .assertEquals (newSize , newVolume .getSize ());
745+ Assert .assertEquals (Volume .State .Allocated , newVolume .getState ());
746+ } catch (ResourceAllocationException e ) {
747+ fail (e .getMessage ());
748+ }
749+ }
750+
691751 @ After
692752 public void tearDown () {
693753 CallContext .unregister ();
0 commit comments