DaanHoogland commented on code in PR #7359:
URL: https://github.com/apache/cloudstack/pull/7359#discussion_r1152124897


##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -2022,13 +1982,41 @@ private void 
validateVolumeResizeWithNewDiskOfferingAndLoad(VolumeVO volume, Dis
             newHypervisorSnapshotReserve[0] = 
volume.getHypervisorSnapshotReserve() != null ? 
newDiskOffering.getHypervisorSnapshotReserve() : null;
         }
 
-        if (existingDiskOffering.getDiskSizeStrictness() && 
!(volume.getSize().equals(newSize[0]))) {
-            throw new InvalidParameterValueException(String.format("Resize 
volume for %s is not allowed since disk offering's size is fixed", 
volume.getName()));
-        }
+        Long instanceId = volume.getInstanceId();
+        VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(instanceId);
+
+        checkIfVolumeCanResizeWithNewDiskOffering(volume, 
existingDiskOffering, newDiskOffering, newSize[0], vmInstanceVO);
         checkIfVolumeIsRootAndVmIsRunning(newSize[0], volume, vmInstanceVO);
 
     }
 
+    private void checkIfVolumeCanResizeWithNewDiskOffering(VolumeVO volume, 
DiskOfferingVO existingDiskOffering, DiskOfferingVO newDiskOffering, Long 
newSize, VMInstanceVO vmInstanceVO) {
+        if (existingDiskOffering.getId() == newDiskOffering.getId() &&
+                (!newDiskOffering.isCustomized() || 
(newDiskOffering.isCustomized() && Objects.equals(volume.getSize(), newSize << 
30)))) {
+            throw new InvalidParameterValueException(String.format("Volume %s 
is already having disk offering %s", volume, newDiskOffering.getUuid()));
+        }
+
+        if (existingDiskOffering.getDiskSizeStrictness() != 
newDiskOffering.getDiskSizeStrictness()) {
+            throw new InvalidParameterValueException("Disk offering size 
strictness does not match with new disk offering.");
+        }
+
+        if 
(MatchStoragePoolTagsWithDiskOffering.valueIn(volume.getDataCenterId())) {
+            if 
(!doesNewDiskOfferingHasTagsAsOldDiskOffering(existingDiskOffering, 
newDiskOffering)) {

Review Comment:
   these can be one condition/if-statement



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to