Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
}
if (!volumeMigrateRequired && !volumeResizeRequired) {

if (newDiskOffering != null && newDiskOffering.getId()!=diskOffering.getId()) {
if (newDiskOffering != null && newDiskOffering.getId() != diskOffering.getId()) {
_volsDao.updateDiskOffering(volume.getId(), newDiskOffering.getId());
volume = _volsDao.findById(volume.getId());
updateStorageWithTheNewDiskOffering(volume, newDiskOffering);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
Expand Down Expand Up @@ -2054,6 +2055,75 @@ public void testResizeVolumeInAllocateState() throws ResourceAllocationException
verify(volumeServiceMock, times(0)).resize(any(VolumeInfo.class));
}
}

@Test
public void testResizeVolumeNoChangeSkipsDriver() throws ResourceAllocationException, ExecutionException, InterruptedException {
ResizeVolumeCmd cmd = new ResizeVolumeCmd();
ReflectionTestUtils.setField(cmd, "id", volumeMockId);

testResizeVolumeSetup();
when(storageMgr.storagePoolHasEnoughSpaceForResize(any(), nullable(Long.class), nullable(Long.class))).thenReturn(true);

try (MockedStatic<UsageEventUtils> ignored = Mockito.mockStatic(UsageEventUtils.class)) {
Volume result = volumeApiServiceImpl.resizeVolume(cmd);

Assert.assertSame(volumeVoMock, result);
verify(volumeServiceMock, times(0)).resize(any(VolumeInfo.class));
verify(volumeDaoMock, times(0)).updateDiskOffering(anyLong(), anyLong());
}
}

@Test
public void testResizeVolumeSameDiskOfferingSkipsDriver() throws ResourceAllocationException, ExecutionException, InterruptedException {
ResizeVolumeCmd cmd = new ResizeVolumeCmd();
ReflectionTestUtils.setField(cmd, "id", volumeMockId);
ReflectionTestUtils.setField(cmd, "newDiskOfferingId", newDiskOfferingMockId);

testResizeVolumeSetup();
when(newDiskOfferingMock.getDiskSize()).thenReturn(volumeSizeMock);
when(diskOfferingMock.getId()).thenReturn(diskOfferingMockId);
when(newDiskOfferingMock.getId()).thenReturn(diskOfferingMockId);
when(storageMgr.storagePoolHasEnoughSpaceForResize(any(), nullable(Long.class), nullable(Long.class))).thenReturn(true);

try (MockedStatic<UsageEventUtils> ignored = Mockito.mockStatic(UsageEventUtils.class)) {
Volume result = volumeApiServiceImpl.resizeVolume(cmd);

Assert.assertSame(volumeVoMock, result);
verify(volumeServiceMock, times(0)).resize(any(VolumeInfo.class));
verify(volumeDaoMock, times(0)).updateDiskOffering(anyLong(), anyLong());
}
}

@Test
public void testResizeVolumeNewDiskOfferingSameSizeUpdatesOfferingWithoutResize() throws ResourceAllocationException, ExecutionException, InterruptedException {
ResizeVolumeCmd cmd = new ResizeVolumeCmd();
ReflectionTestUtils.setField(cmd, "id", volumeMockId);
ReflectionTestUtils.setField(cmd, "newDiskOfferingId", newDiskOfferingMockId);

testResizeVolumeSetup();
when(newDiskOfferingMock.getDiskSize()).thenReturn(volumeSizeMock);
when(diskOfferingMock.getId()).thenReturn(diskOfferingMockId);
when(newDiskOfferingMock.getId()).thenReturn(newDiskOfferingMockId);
when(storageMgr.storagePoolHasEnoughSpaceForResize(any(), nullable(Long.class), nullable(Long.class))).thenReturn(true);

DataStore offeringStore = Mockito.mock(DataStore.class);
PrimaryDataStoreDriver driver = Mockito.mock(PrimaryDataStoreDriver.class);
when(dataStoreMgr.getDataStore(anyLong(), eq(DataStoreRole.Primary))).thenReturn(offeringStore);
when(offeringStore.getDriver()).thenReturn(driver);
when(driver.informStorageForDiskOfferingChange()).thenReturn(true);

try (MockedStatic<UsageEventUtils> ignored = Mockito.mockStatic(UsageEventUtils.class)) {
Mockito.clearInvocations(volumeDaoMock);
Volume result = volumeApiServiceImpl.resizeVolume(cmd);

Assert.assertSame(volumeVoMock, result);
verify(volumeDaoMock).updateDiskOffering(volumeMockId, newDiskOfferingMockId);
verify(volumeDaoMock, times(2)).findById(volumeMockId);
verify(driver).updateStorageWithTheNewDiskOffering(volumeVoMock, newDiskOfferingMock);
verify(volumeServiceMock, times(0)).resize(any(VolumeInfo.class));
}
}

private UserVmVO getMockedVm() {
UserVmVO vm = Mockito.mock(UserVmVO.class);
Mockito.when(vm.getId()).thenReturn(1L);
Expand Down
Loading