Skip to content

Commit c0f8bc4

Browse files
Address review comments on upstream PR 14259 on apache/main (#135)
### Description This PR... <!--- Describe your changes in DETAIL - And how has behaviour functionally changed. --> <!-- For new features, provide link to FS, dev ML discussion etc. --> <!-- In case of bug fix, the expected and actual behaviours, steps to reproduce. --> <!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be closed when this PR gets merged --> <!-- For addressing multiple issues/PRs, use multiple "Fixes: #<id>" --> <!-- Fixes: # --> <!--- ******************************************************************************* --> <!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE DOCUMENTATION. --> <!--- PLEASE PUT AN 'X' in only **ONE** box --> <!--- ******************************************************************************* --> ### Types of changes - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] New feature (non-breaking change which adds functionality) - [X] Bug fix (non-breaking change which fixes an issue) - [ ] Enhancement (improves an existing feature and functionality) - [ ] Cleanup (Code refactoring and cleanup, that may add test cases) - [ ] Build/CI - [X] Test (unit or integration test code) ### Feature/Enhancement Scale or Bug Severity #### Feature/Enhancement Scale - [ ] Major - [ ] Minor #### Bug Severity - [ ] BLOCKER - [ ] Critical - [ ] Major - [ ] Minor - [X] Trivial ### Screenshots (if appropriate): ### How Has This Been Tested? <!-- Please describe in detail how you tested your changes. --> <!-- Include details of your testing environment, and the tests you ran to --> #### How did you try to break this feature and the system with this change? <!-- see how your change affects other areas of the code, etc. --> <!-- Please read the [CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md) document -->
1 parent 42b3d88 commit c0f8bc4

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

‎server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
14581458
}
14591459
if (!volumeMigrateRequired && !volumeResizeRequired) {
14601460

1461-
if (newDiskOffering != null && newDiskOffering.getId()!=diskOffering.getId()) {
1461+
if (newDiskOffering != null && newDiskOffering.getId() != diskOffering.getId()) {
14621462
_volsDao.updateDiskOffering(volume.getId(), newDiskOffering.getId());
14631463
volume = _volsDao.findById(volume.getId());
14641464
updateStorageWithTheNewDiskOffering(volume, newDiskOffering);

‎server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
5555
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
5656
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
57+
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
5758
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
5859
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
5960
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
@@ -2054,6 +2055,75 @@ public void testResizeVolumeInAllocateState() throws ResourceAllocationException
20542055
verify(volumeServiceMock, times(0)).resize(any(VolumeInfo.class));
20552056
}
20562057
}
2058+
2059+
@Test
2060+
public void testResizeVolumeNoChangeSkipsDriver() throws ResourceAllocationException, ExecutionException, InterruptedException {
2061+
ResizeVolumeCmd cmd = new ResizeVolumeCmd();
2062+
ReflectionTestUtils.setField(cmd, "id", volumeMockId);
2063+
2064+
testResizeVolumeSetup();
2065+
when(storageMgr.storagePoolHasEnoughSpaceForResize(any(), nullable(Long.class), nullable(Long.class))).thenReturn(true);
2066+
2067+
try (MockedStatic<UsageEventUtils> ignored = Mockito.mockStatic(UsageEventUtils.class)) {
2068+
Volume result = volumeApiServiceImpl.resizeVolume(cmd);
2069+
2070+
Assert.assertSame(volumeVoMock, result);
2071+
verify(volumeServiceMock, times(0)).resize(any(VolumeInfo.class));
2072+
verify(volumeDaoMock, times(0)).updateDiskOffering(anyLong(), anyLong());
2073+
}
2074+
}
2075+
2076+
@Test
2077+
public void testResizeVolumeSameDiskOfferingSkipsDriver() throws ResourceAllocationException, ExecutionException, InterruptedException {
2078+
ResizeVolumeCmd cmd = new ResizeVolumeCmd();
2079+
ReflectionTestUtils.setField(cmd, "id", volumeMockId);
2080+
ReflectionTestUtils.setField(cmd, "newDiskOfferingId", newDiskOfferingMockId);
2081+
2082+
testResizeVolumeSetup();
2083+
when(newDiskOfferingMock.getDiskSize()).thenReturn(volumeSizeMock);
2084+
when(diskOfferingMock.getId()).thenReturn(diskOfferingMockId);
2085+
when(newDiskOfferingMock.getId()).thenReturn(diskOfferingMockId);
2086+
when(storageMgr.storagePoolHasEnoughSpaceForResize(any(), nullable(Long.class), nullable(Long.class))).thenReturn(true);
2087+
2088+
try (MockedStatic<UsageEventUtils> ignored = Mockito.mockStatic(UsageEventUtils.class)) {
2089+
Volume result = volumeApiServiceImpl.resizeVolume(cmd);
2090+
2091+
Assert.assertSame(volumeVoMock, result);
2092+
verify(volumeServiceMock, times(0)).resize(any(VolumeInfo.class));
2093+
verify(volumeDaoMock, times(0)).updateDiskOffering(anyLong(), anyLong());
2094+
}
2095+
}
2096+
2097+
@Test
2098+
public void testResizeVolumeNewDiskOfferingSameSizeUpdatesOfferingWithoutResize() throws ResourceAllocationException, ExecutionException, InterruptedException {
2099+
ResizeVolumeCmd cmd = new ResizeVolumeCmd();
2100+
ReflectionTestUtils.setField(cmd, "id", volumeMockId);
2101+
ReflectionTestUtils.setField(cmd, "newDiskOfferingId", newDiskOfferingMockId);
2102+
2103+
testResizeVolumeSetup();
2104+
when(newDiskOfferingMock.getDiskSize()).thenReturn(volumeSizeMock);
2105+
when(diskOfferingMock.getId()).thenReturn(diskOfferingMockId);
2106+
when(newDiskOfferingMock.getId()).thenReturn(newDiskOfferingMockId);
2107+
when(storageMgr.storagePoolHasEnoughSpaceForResize(any(), nullable(Long.class), nullable(Long.class))).thenReturn(true);
2108+
2109+
DataStore offeringStore = Mockito.mock(DataStore.class);
2110+
PrimaryDataStoreDriver driver = Mockito.mock(PrimaryDataStoreDriver.class);
2111+
when(dataStoreMgr.getDataStore(anyLong(), eq(DataStoreRole.Primary))).thenReturn(offeringStore);
2112+
when(offeringStore.getDriver()).thenReturn(driver);
2113+
when(driver.informStorageForDiskOfferingChange()).thenReturn(true);
2114+
2115+
try (MockedStatic<UsageEventUtils> ignored = Mockito.mockStatic(UsageEventUtils.class)) {
2116+
Mockito.clearInvocations(volumeDaoMock);
2117+
Volume result = volumeApiServiceImpl.resizeVolume(cmd);
2118+
2119+
Assert.assertSame(volumeVoMock, result);
2120+
verify(volumeDaoMock).updateDiskOffering(volumeMockId, newDiskOfferingMockId);
2121+
verify(volumeDaoMock, times(2)).findById(volumeMockId);
2122+
verify(driver).updateStorageWithTheNewDiskOffering(volumeVoMock, newDiskOfferingMock);
2123+
verify(volumeServiceMock, times(0)).resize(any(VolumeInfo.class));
2124+
}
2125+
}
2126+
20572127
private UserVmVO getMockedVm() {
20582128
UserVmVO vm = Mockito.mock(UserVmVO.class);
20592129
Mockito.when(vm.getId()).thenReturn(1L);

0 commit comments

Comments
 (0)