Skip to content

Commit a7be64a

Browse files
suryag1201Gupta, Surya
andauthored
Resize Volume form does not show current size and Custom IOPS (#14262)
* [CCS-5] Volume Resize Fix for IOPS and Size (#106) ### Description On Resize Volume, the form did not show the volume’s current size and IOPS. It also used the first disk offering in the list, not the offering already attached to the volume. So the dialog often opened empty or with the wrong IOPS fields, and a resize could send the wrong values. Root cause Three UI issues in fetchData(): Size unit — the API stores size in bytes. The form label is GB. Size was never copied onto the form, so the GB field stayed empty. Wrong offering — the code always used this.offerings[0] (first offering returned by listDiskOfferings), not this.resource.diskofferingid (the volume’s offering). Custom size / custom IOPS flags could be wrong. IOPS not filled — even when min/max IOPS existed on the volume, they were not copied into form.miniops / form.maxiops. Steps to reproduce Create a volume with a custom IOPS disk offering (for example min 2000, max 5000) and a known size (for example 20 GB). Open Storage → Volumes → Resize. Check the Size (GB) field and the Min/Max IOPS fields. <!--- 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) - [ ] 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 - [ ] Test (unit or integration test code) ### Feature/Enhancement Scale or Bug Severity #### Feature/Enhancement Scale - [ ] Major - [ ] Minor #### Bug Severity - [ ] BLOCKER - [ ] Critical - [ ] Major - [ ] Minor - [ ] Trivial ### Screenshots (if appropriate): Before Fix: <img width="533" height="353" alt="image" src="https://github.com/user-attachments/assets/ccfc698e-501c-442e-a7b2-9582dc2a53ba" /> After Fix: <img width="528" height="472" alt="image" src="https://github.com/user-attachments/assets/5125bb21-9b9b-4e48-a9bc-8d5eaef07118" /> ### How Has This Been Tested? Tested with both Fix and Custom IOPS: 1- Resize Shows IOPS value for custom IOPS not for fix, along with size 2- Exact 20 GB volume → shows as 20 float 20.1 -> shows on UI as 20 #### 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 --> --------- Co-authored-by: Gupta, Surya <Surya.Gupta@netapp.com> * Resize Upstream PR Review Comment (#124) Root Volume created with custom IOPS and not overridden by the custom disk offering should also show the min and max IOPS on form <!--- ******************************************************************************* --> <!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE DOCUMENTATION. --> <!--- PLEASE PUT AN 'X' in only **ONE** box --> <!--- ******************************************************************************* --> - [ ] 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 - [ ] Test (unit or integration test code) - [x] Major - [ ] Minor - [ ] BLOCKER - [ ] Critical - [x] Major - [ ] Minor - [ ] Trivial <img width="655" height="529" alt="image" src="https://github.com/user-attachments/assets/335b1c6c-e979-4976-a7a3-1c1b52f535e7" /> <img width="526" height="407" alt="image" src="https://github.com/user-attachments/assets/76a5e0e5-ec23-4b0f-96ea-ee43c81cfa44" /> <img width="599" height="460" alt="image" src="https://github.com/user-attachments/assets/923c44a5-b53f-452f-944c-73ef3c75d804" /> 1- Created a Fix IOPS Offering of compute/disk and use to create VM/Volume, resize should not show min max IOPS - success 2- Created a Custom IOPS Offering of compute/disk and use to create VM/Volume, resize should show min max IOPS - success 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 --> --------- Co-authored-by: Gupta, Surya <Surya.Gupta@netapp.com> * [CSTACKEX-368] Resize Form Size issue fix --------- Co-authored-by: Gupta, Surya <Surya.Gupta@netapp.com>
1 parent f8f3848 commit a7be64a

4 files changed

Lines changed: 208 additions & 18 deletions

File tree

‎api/src/main/java/org/apache/cloudstack/api/response/VolumeResponse.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public class VolumeResponse extends BaseResponseWithTagInformation implements Co
117117
@Param(description = "Max IOPS of the disk volume")
118118
private Long maxIops;
119119

120+
@SerializedName("iscustomizediops")
121+
@Param(description = "True if the volume's disk offering uses custom IOPS, false otherwise")
122+
private Boolean customizedIops;
123+
120124
@SerializedName(ApiConstants.CREATED)
121125
@Param(description = "The date the disk volume was created")
122126
private Date created;
@@ -410,6 +414,10 @@ public void setMaxIops(Long maxIops) {
410414
this.maxIops = maxIops;
411415
}
412416

417+
public void setCustomizedIops(Boolean customizedIops) {
418+
this.customizedIops = customizedIops;
419+
}
420+
413421
public void setCreated(Date created) {
414422
this.created = created;
415423
}
@@ -712,6 +720,14 @@ public Long getMaxIops() {
712720
return maxIops;
713721
}
714722

723+
public Boolean isCustomizedIops() {
724+
return customizedIops;
725+
}
726+
727+
public Boolean getCustomizedIops() {
728+
return customizedIops;
729+
}
730+
715731
public Date getCreated() {
716732
return created;
717733
}

‎server/src/main/java/com/cloud/api/query/dao/VolumeJoinDaoImpl.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ public VolumeResponse newVolumeResponse(ResponseView view, VolumeJoinVO volume)
227227
volResponse.setDiskOfferingName(volume.getDiskOfferingName());
228228
volResponse.setDiskOfferingDisplayText(volume.getDiskOfferingDisplayText());
229229
}
230+
DiskOffering diskOffering = computeOnlyDiskOffering != null
231+
? computeOnlyDiskOffering
232+
: ApiDBUtils.findDiskOfferingById(volume.getDiskOfferingId());
233+
if (diskOffering != null) {
234+
volResponse.setCustomizedIops(diskOffering.isCustomizedIops());
235+
}
230236

231237
if (view == ResponseView.Full) {
232238
volResponse.setStorageType(volume.isUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString());

‎server/src/test/java/com/cloud/api/query/dao/VolumeJoinDaoImplTest.java‎

Lines changed: 171 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,70 @@
1616
// under the License.
1717
package com.cloud.api.query.dao;
1818

19-
import com.cloud.api.query.vo.VolumeJoinVO;
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNull;
22+
import static org.junit.Assert.assertTrue;
23+
import static org.mockito.ArgumentMatchers.any;
24+
import static org.mockito.ArgumentMatchers.anyBoolean;
25+
import static org.mockito.ArgumentMatchers.anyString;
26+
import static org.mockito.ArgumentMatchers.eq;
27+
import static org.mockito.Mockito.lenient;
28+
import static org.mockito.Mockito.mock;
29+
import static org.mockito.Mockito.mockStatic;
30+
import static org.mockito.Mockito.when;
31+
32+
import java.util.function.Consumer;
33+
34+
import org.apache.cloudstack.annotation.dao.AnnotationDao;
35+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2036
import org.apache.cloudstack.api.response.VolumeResponse;
2137
import org.junit.Assert;
38+
import org.apache.cloudstack.context.CallContext;
2239
import org.junit.Before;
2340
import org.junit.Test;
2441
import org.junit.runner.RunWith;
2542
import org.mockito.InjectMocks;
2643
import org.mockito.Mockito;
44+
import org.mockito.Mock;
45+
import org.mockito.MockedStatic;
2746
import org.mockito.junit.MockitoJUnitRunner;
2847

48+
import com.cloud.api.ApiDBUtils;
49+
import com.cloud.api.ApiResponseHelper;
50+
import com.cloud.api.query.vo.VolumeJoinVO;
51+
import com.cloud.service.ServiceOfferingVO;
52+
import com.cloud.storage.DiskOfferingVO;
53+
import com.cloud.storage.Volume;
54+
import com.cloud.user.Account;
55+
import com.cloud.user.AccountManager;
56+
2957
@RunWith(MockitoJUnitRunner.class)
3058
public class VolumeJoinDaoImplTest extends GenericDaoBaseWithTagInformationBaseTest<VolumeJoinVO, VolumeResponse> {
3159

60+
private static final long DISK_OFFERING_ID = 10L;
61+
3262
@InjectMocks
3363
private VolumeJoinDaoImpl _volumeJoinDaoImpl;
3464

65+
@Mock
66+
private AnnotationDao annotationDao;
67+
68+
@Mock
69+
private AccountManager _accountMgr;
70+
3571
private VolumeJoinVO volume = new VolumeJoinVO();
3672
private VolumeResponse volumeResponse = new VolumeResponse();
3773

3874
@Before
3975
public void setup() {
40-
prepareSetup();
76+
lenient().when(annotationDao.hasAnnotations(anyString(), anyString(), anyBoolean())).thenReturn(false);
77+
lenient().when(_accountMgr.isRootAdmin(eq(1L))).thenReturn(true);
4178
}
4279

4380
@Test
4481
public void testUpdateVolumeTagInfo(){
82+
prepareSetup();
4583
testUpdateTagInformation(_volumeJoinDaoImpl, volume, volumeResponse);
4684
}
4785

@@ -62,4 +100,135 @@ public void testSetThrottleRatesMapsReadAndWriteDistinctly() {
62100
Assert.assertEquals(Long.valueOf(400L), response.getIopsWriteRate());
63101
}
64102

103+
@Test
104+
public void testNewVolumeResponseSetsCustomizedIopsForComputeOfferingRoot() {
105+
VolumeJoinVO volumeJoin = mockVolumeWithDiskOffering();
106+
DiskOfferingVO computeOnlyOffering = mock(DiskOfferingVO.class);
107+
when(computeOnlyOffering.isCustomizedIops()).thenReturn(true);
108+
ServiceOfferingVO serviceOffering = mock(ServiceOfferingVO.class);
109+
when(serviceOffering.getId()).thenReturn(5L);
110+
when(serviceOffering.getName()).thenReturn("FullCustom_Compute");
111+
when(serviceOffering.getDisplayText()).thenReturn("FullCustom_Compute");
112+
113+
VolumeResponse response = newVolumeResponse(volumeJoin, apiDBUtils -> {
114+
apiDBUtils.when(() -> ApiDBUtils.findComputeOnlyDiskOfferingById(DISK_OFFERING_ID))
115+
.thenReturn(computeOnlyOffering);
116+
apiDBUtils.when(() -> ApiDBUtils.findServiceOfferingByComputeOnlyDiskOffering(DISK_OFFERING_ID, false))
117+
.thenReturn(serviceOffering);
118+
});
119+
120+
assertTrue(response.isCustomizedIops());
121+
assertEquals("5", response.getServiceOfferingId());
122+
assertEquals("FullCustom_Compute", response.getServiceOfferingName());
123+
assertNull(response.getDiskOfferingId());
124+
}
125+
126+
@Test
127+
public void testNewVolumeResponseSetsCustomizedIopsForDiskOffering() {
128+
VolumeJoinVO volumeJoin = mockVolumeWithDiskOffering();
129+
when(volumeJoin.getDiskOfferingUuid()).thenReturn("disk-offering-uuid");
130+
when(volumeJoin.getDiskOfferingName()).thenReturn("NFS_Disk_Custom75");
131+
when(volumeJoin.getDiskOfferingDisplayText()).thenReturn("NFS_Disk_Custom75");
132+
DiskOfferingVO diskOffering = mock(DiskOfferingVO.class);
133+
when(diskOffering.isCustomizedIops()).thenReturn(true);
134+
135+
VolumeResponse response = newVolumeResponse(volumeJoin, apiDBUtils -> {
136+
apiDBUtils.when(() -> ApiDBUtils.findComputeOnlyDiskOfferingById(DISK_OFFERING_ID)).thenReturn(null);
137+
apiDBUtils.when(() -> ApiDBUtils.findDiskOfferingById(DISK_OFFERING_ID)).thenReturn(diskOffering);
138+
});
139+
140+
assertTrue(response.isCustomizedIops());
141+
assertEquals("disk-offering-uuid", response.getDiskOfferingId());
142+
assertNull(response.getServiceOfferingId());
143+
}
144+
145+
@Test
146+
public void testNewVolumeResponseSetsCustomizedIopsFalseWhenOfferingIsFixed() {
147+
VolumeJoinVO volumeJoin = mockVolumeWithDiskOffering();
148+
DiskOfferingVO diskOffering = mock(DiskOfferingVO.class);
149+
when(diskOffering.isCustomizedIops()).thenReturn(false);
150+
151+
VolumeResponse response = newVolumeResponse(volumeJoin, apiDBUtils -> {
152+
apiDBUtils.when(() -> ApiDBUtils.findComputeOnlyDiskOfferingById(DISK_OFFERING_ID)).thenReturn(null);
153+
apiDBUtils.when(() -> ApiDBUtils.findDiskOfferingById(DISK_OFFERING_ID)).thenReturn(diskOffering);
154+
});
155+
156+
assertFalse(response.isCustomizedIops());
157+
}
158+
159+
@Test
160+
public void testNewVolumeResponseSetsCustomizedIopsFalseForFixedComputeOffering() {
161+
VolumeJoinVO volumeJoin = mockVolumeWithDiskOffering();
162+
DiskOfferingVO computeOnlyOffering = mock(DiskOfferingVO.class);
163+
when(computeOnlyOffering.isCustomizedIops()).thenReturn(false);
164+
ServiceOfferingVO serviceOffering = mock(ServiceOfferingVO.class);
165+
when(serviceOffering.getId()).thenReturn(5L);
166+
when(serviceOffering.getName()).thenReturn("Fixed_Compute");
167+
when(serviceOffering.getDisplayText()).thenReturn("Fixed_Compute");
168+
169+
VolumeResponse response = newVolumeResponse(volumeJoin, apiDBUtils -> {
170+
apiDBUtils.when(() -> ApiDBUtils.findComputeOnlyDiskOfferingById(DISK_OFFERING_ID))
171+
.thenReturn(computeOnlyOffering);
172+
apiDBUtils.when(() -> ApiDBUtils.findServiceOfferingByComputeOnlyDiskOffering(DISK_OFFERING_ID, false))
173+
.thenReturn(serviceOffering);
174+
});
175+
176+
assertFalse(response.isCustomizedIops());
177+
assertEquals("5", response.getServiceOfferingId());
178+
assertEquals("Fixed_Compute", response.getServiceOfferingName());
179+
assertNull(response.getDiskOfferingId());
180+
}
181+
182+
@Test
183+
public void testNewVolumeResponseLeavesCustomizedIopsNullWhenOfferingValueIsNull() {
184+
VolumeJoinVO volumeJoin = mockVolumeWithDiskOffering();
185+
when(volumeJoin.getDiskOfferingUuid()).thenReturn("disk-offering-uuid");
186+
DiskOfferingVO diskOffering = mock(DiskOfferingVO.class);
187+
when(diskOffering.isCustomizedIops()).thenReturn(null);
188+
189+
VolumeResponse response = newVolumeResponse(volumeJoin, apiDBUtils -> {
190+
apiDBUtils.when(() -> ApiDBUtils.findComputeOnlyDiskOfferingById(DISK_OFFERING_ID)).thenReturn(null);
191+
apiDBUtils.when(() -> ApiDBUtils.findDiskOfferingById(DISK_OFFERING_ID)).thenReturn(diskOffering);
192+
});
193+
194+
assertNull(response.isCustomizedIops());
195+
assertNull(response.getCustomizedIops());
196+
}
197+
198+
private VolumeJoinVO mockVolumeWithDiskOffering() {
199+
VolumeJoinVO volumeJoin = mock(VolumeJoinVO.class);
200+
when(volumeJoin.getUuid()).thenReturn("volume-uuid");
201+
when(volumeJoin.getName()).thenReturn("ROOT-67");
202+
when(volumeJoin.getDiskOfferingId()).thenReturn(DISK_OFFERING_ID);
203+
when(volumeJoin.getVmId()).thenReturn(0L);
204+
when(volumeJoin.getState()).thenReturn(Volume.State.Ready);
205+
when(volumeJoin.getVolumeType()).thenReturn(Volume.Type.ROOT);
206+
when(volumeJoin.getTemplateId()).thenReturn(0L);
207+
when(volumeJoin.getTagId()).thenReturn(0L);
208+
when(volumeJoin.getMinIops()).thenReturn(0L);
209+
when(volumeJoin.getMaxIops()).thenReturn(1000L);
210+
when(volumeJoin.getDeleteProtection()).thenReturn(false);
211+
when(volumeJoin.isDisplayVolume()).thenReturn(true);
212+
when(volumeJoin.getKmsWrappedKeyId()).thenReturn(null);
213+
when(volumeJoin.getJobId()).thenReturn(null);
214+
return volumeJoin;
215+
}
216+
217+
private VolumeResponse newVolumeResponse(VolumeJoinVO volumeJoin, Consumer<MockedStatic<ApiDBUtils>> apiStubs) {
218+
Account callingAccount = mock(Account.class);
219+
when(callingAccount.getId()).thenReturn(1L);
220+
CallContext callContext = mock(CallContext.class);
221+
when(callContext.getCallingAccount()).thenReturn(callingAccount);
222+
223+
try (MockedStatic<ApiDBUtils> apiDBUtils = mockStatic(ApiDBUtils.class);
224+
MockedStatic<CallContext> callContextMocked = mockStatic(CallContext.class);
225+
MockedStatic<ApiResponseHelper> apiResponseHelperMocked = mockStatic(ApiResponseHelper.class)) {
226+
apiStubs.accept(apiDBUtils);
227+
callContextMocked.when(CallContext::current).thenReturn(callContext);
228+
apiResponseHelperMocked.when(() -> ApiResponseHelper.populateOwner(any(), any()))
229+
.thenAnswer(invocation -> null);
230+
return _volumeJoinDaoImpl.newVolumeResponse(ResponseView.Restricted, volumeJoin);
231+
}
232+
}
233+
65234
}

‎ui/src/views/storage/ResizeVolume.vue‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</template>
6666
<script>
6767
import { ref, reactive, toRaw } from 'vue'
68-
import { getAPI, postAPI } from '@/api'
68+
import { postAPI } from '@/api'
6969
import { mixinForm } from '@/utils/mixin'
7070
import TooltipLabel from '@/components/widgets/TooltipLabel'
7171
@@ -83,10 +83,9 @@ export default {
8383
},
8484
data () {
8585
return {
86-
offerings: [],
87-
customDiskOffering: false,
8886
loading: false,
89-
customDiskOfferingIops: false
87+
customDiskOfferingIops: false,
88+
initialSize: null
9089
}
9190
},
9291
created () {
@@ -104,24 +103,24 @@ export default {
104103
})
105104
},
106105
fetchData () {
107-
this.loading = true
108-
getAPI('listDiskOfferings', {
109-
zoneid: this.resource.zoneid,
110-
listall: true
111-
}).then(json => {
112-
this.offerings = json.listdiskofferingsresponse.diskoffering || []
113-
this.form.diskofferingid = this.offerings[0].id || ''
114-
this.customDiskOffering = this.offerings[0].iscustomized || false
115-
this.customDiskOfferingIops = this.offerings[0].iscustomizediops || false
116-
}).finally(() => {
117-
this.loading = false
118-
})
106+
if (this.resource.size != null) {
107+
this.form.size = this.resource.size / (1024 * 1024 * 1024)
108+
this.initialSize = this.form.size
109+
}
110+
this.customDiskOfferingIops = this.resource.iscustomizediops
111+
if (this.customDiskOfferingIops) {
112+
this.form.miniops = this.resource.miniops
113+
this.form.maxiops = this.resource.maxiops
114+
}
119115
},
120116
handleSubmit (e) {
121117
if (this.loading) return
122118
this.formRef.value.validate().then(() => {
123119
const formRaw = toRaw(this.form)
124120
const values = this.handleRemoveFields(formRaw)
121+
if (this.initialSize != null && values.size != null && Number(values.size) === Number(this.initialSize)) {
122+
delete values.size
123+
}
125124
this.loading = true
126125
values.id = this.resource.id
127126
postAPI('resizeVolume', values).then(response => {

0 commit comments

Comments
 (0)