Skip to content

Commit 7b5cafa

Browse files
Fix ScaleVM to consider resize volume in any type of compute offering
1 parent dd51534 commit 7b5cafa

File tree

2 files changed

+26
-87
lines changed

2 files changed

+26
-87
lines changed

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

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.HashSet;
2727
import java.util.List;
2828
import java.util.Map;
29+
import java.util.Objects;
2930
import java.util.Optional;
3031
import java.util.Set;
3132
import java.util.UUID;
@@ -1741,12 +1742,6 @@ private Volume changeDiskOfferingForVolumeInternal(VolumeVO volume, Long newDisk
17411742
boolean volumeMigrateRequired = false;
17421743
boolean volumeResizeRequired = false;
17431744

1744-
// Skip the Disk offering change on Volume if Disk Offering is the same and is linked to a custom Service Offering
1745-
if(isNewDiskOfferingTheSameAndCustomServiceOffering(existingDiskOffering, newDiskOffering)) {
1746-
s_logger.debug(String.format("Scaling CPU and/or Memory of VM with custom service offering. New disk offering stills the same. Skipping the Disk offering change on Volume %s.", volume.getUuid()));
1747-
return volume;
1748-
}
1749-
17501745
// VALIDATIONS
17511746
Long[] updateNewSize = {newSize};
17521747
Long[] updateNewMinIops = {newMinIops};
@@ -1853,19 +1848,6 @@ private boolean compareEqualsIncludingNullOrZero(Long a, Long b) {
18531848
return a.equals(b);
18541849
}
18551850

1856-
/**
1857-
* Returns true if the new disk offering is the same than current offering, and the respective Service offering is a custom (constraint or unconstraint) offering.
1858-
*/
1859-
protected boolean isNewDiskOfferingTheSameAndCustomServiceOffering(DiskOfferingVO existingDiskOffering, DiskOfferingVO newDiskOffering) {
1860-
if (newDiskOffering.getId() == existingDiskOffering.getId()) {
1861-
ServiceOfferingVO serviceOffering = _serviceOfferingDao.findServiceOfferingByComputeOnlyDiskOffering(newDiskOffering.getId());
1862-
if (serviceOffering != null && serviceOffering.isCustomized()) {
1863-
return true;
1864-
}
1865-
}
1866-
return false;
1867-
}
1868-
18691851
private VolumeVO resizeVolumeInternal(VolumeVO volume, DiskOfferingVO newDiskOffering, Long currentSize, Long newSize, Long newMinIops, Long newMaxIops, Integer newHypervisorSnapshotReserve, boolean shrinkOk) throws ResourceAllocationException {
18701852
UserVmVO userVm = _userVmDao.findById(volume.getInstanceId());
18711853
HypervisorType hypervisorType = _volsDao.getHypervisorType(volume.getId());
@@ -1965,30 +1947,6 @@ private void validateVolumeResizeWithNewDiskOfferingAndLoad(VolumeVO volume, Dis
19651947
throw new InvalidParameterValueException("Requested disk offering has been removed.");
19661948
}
19671949

1968-
if (newDiskOffering.getId() == existingDiskOffering.getId()) {
1969-
throw new InvalidParameterValueException(String.format("Volume %s already have the new disk offering %s provided.", volume.getUuid(), existingDiskOffering.getUuid()));
1970-
}
1971-
1972-
if (existingDiskOffering.getDiskSizeStrictness() != newDiskOffering.getDiskSizeStrictness()) {
1973-
throw new InvalidParameterValueException("Disk offering size strictness does not match with new disk offering.");
1974-
}
1975-
1976-
if (MatchStoragePoolTagsWithDiskOffering.valueIn(volume.getDataCenterId())) {
1977-
if (!doesNewDiskOfferingHasTagsAsOldDiskOffering(existingDiskOffering, newDiskOffering)) {
1978-
throw new InvalidParameterValueException(String.format("Selected disk offering %s does not have tags as in existing disk offering of volume %s", existingDiskOffering.getUuid(), volume.getUuid()));
1979-
}
1980-
}
1981-
1982-
Long instanceId = volume.getInstanceId();
1983-
VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(instanceId);
1984-
if (volume.getVolumeType().equals(Volume.Type.ROOT)) {
1985-
ServiceOfferingVO serviceOffering = _serviceOfferingDao.findById(vmInstanceVO.getServiceOfferingId());
1986-
if (serviceOffering != null && serviceOffering.getDiskOfferingStrictness()) {
1987-
throw new InvalidParameterValueException(String.format("Cannot resize ROOT volume [%s] with new disk offering since existing disk offering is strictly assigned to the ROOT volume.", volume.getName()));
1988-
}
1989-
}
1990-
1991-
_configMgr.checkDiskOfferingAccess(_accountMgr.getActiveAccountById(volume.getAccountId()), newDiskOffering, _dcDao.findById(volume.getDataCenterId()));
19921950
if (newDiskOffering.getDiskSize() > 0 && !newDiskOffering.isComputeOnly()) {
19931951
newSize[0] = (Long) newDiskOffering.getDiskSize();
19941952
} else if (newDiskOffering.isCustomized() && !newDiskOffering.isComputeOnly()) {
@@ -2022,6 +1980,31 @@ private void validateVolumeResizeWithNewDiskOfferingAndLoad(VolumeVO volume, Dis
20221980
newHypervisorSnapshotReserve[0] = volume.getHypervisorSnapshotReserve() != null ? newDiskOffering.getHypervisorSnapshotReserve() : null;
20231981
}
20241982

1983+
if (existingDiskOffering.getId() == newDiskOffering.getId() &&
1984+
(!newDiskOffering.isCustomized() || (newDiskOffering.isCustomized() && Objects.equals(volume.getSize(), newSize[0] << 30)))) {
1985+
throw new InvalidParameterValueException(String.format("Volume %s is already having disk offering %s", volume, newDiskOffering.getUuid()));
1986+
}
1987+
1988+
if (existingDiskOffering.getDiskSizeStrictness() != newDiskOffering.getDiskSizeStrictness()) {
1989+
throw new InvalidParameterValueException("Disk offering size strictness does not match with new disk offering.");
1990+
}
1991+
1992+
if (MatchStoragePoolTagsWithDiskOffering.valueIn(volume.getDataCenterId())) {
1993+
if (!doesNewDiskOfferingHasTagsAsOldDiskOffering(existingDiskOffering, newDiskOffering)) {
1994+
throw new InvalidParameterValueException(String.format("Selected disk offering %s does not have tags as in existing disk offering of volume %s", existingDiskOffering.getUuid(), volume.getUuid()));
1995+
}
1996+
}
1997+
Long instanceId = volume.getInstanceId();
1998+
VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(instanceId);
1999+
if (volume.getVolumeType().equals(Volume.Type.ROOT)) {
2000+
ServiceOfferingVO serviceOffering = _serviceOfferingDao.findById(vmInstanceVO.getServiceOfferingId());
2001+
if (serviceOffering != null && serviceOffering.getDiskOfferingStrictness()) {
2002+
throw new InvalidParameterValueException(String.format("Cannot resize ROOT volume [%s] with new disk offering since existing disk offering is strictly assigned to the ROOT volume.", volume.getName()));
2003+
}
2004+
}
2005+
2006+
_configMgr.checkDiskOfferingAccess(_accountMgr.getActiveAccountById(volume.getAccountId()), newDiskOffering, _dcDao.findById(volume.getDataCenterId()));
2007+
20252008
if (existingDiskOffering.getDiskSizeStrictness() && !(volume.getSize().equals(newSize[0]))) {
20262009
throw new InvalidParameterValueException(String.format("Resize volume for %s is not allowed since disk offering's size is fixed", volume.getName()));
20272010
}

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

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,50 +1154,6 @@ private void prepareAndRunTestOfIsNotPossibleToResize(Type volumeType, Long root
11541154
Assert.assertEquals(expectedIsNotPossibleToResize, result);
11551155
}
11561156

1157-
@Test
1158-
public void isNewDiskOfferingTheSameAndCustomServiceOfferingTestDifferentOfferings() {
1159-
prepareAndRunIsNewDiskOfferingTheSameAndCustomServiceOffering(1l, 2l, false, true, false);
1160-
}
1161-
1162-
@Test
1163-
public void isNewDiskOfferingTheSameAndCustomServiceOfferingTestDifferentOfferingsCustom() {
1164-
prepareAndRunIsNewDiskOfferingTheSameAndCustomServiceOffering(1l, 2l, true, true, false);
1165-
}
1166-
1167-
@Test
1168-
public void isNewDiskOfferingTheSameAndCustomServiceOfferingTestSameOfferingsCustom() {
1169-
prepareAndRunIsNewDiskOfferingTheSameAndCustomServiceOffering(1l, 1l, true, true, true);
1170-
}
1171-
1172-
@Test
1173-
public void isNewDiskOfferingTheSameAndCustomServiceOfferingTestSameOfferingsNotCustom() {
1174-
prepareAndRunIsNewDiskOfferingTheSameAndCustomServiceOffering(1l, 1l, false, true, false);
1175-
}
1176-
1177-
@Test
1178-
public void isNewDiskOfferingTheSameAndCustomServiceOfferingTestDifferentOfferingsAndNullOffering() {
1179-
prepareAndRunIsNewDiskOfferingTheSameAndCustomServiceOffering(1l, 2l, true, false, false);
1180-
}
1181-
@Test
1182-
public void isNewDiskOfferingTheSameAndCustomServiceOfferingTestSameOfferingsNullOffering() {
1183-
prepareAndRunIsNewDiskOfferingTheSameAndCustomServiceOffering(1l, 1l, false, false, false);
1184-
}
1185-
1186-
private void prepareAndRunIsNewDiskOfferingTheSameAndCustomServiceOffering(long existingDiskOfferingId, long newDiskOfferingId, boolean isCustomized,
1187-
boolean isNotNullServiceOffering, boolean expectedResult) {
1188-
DiskOfferingVO existingDiskOffering = Mockito.mock(DiskOfferingVO.class);
1189-
when(existingDiskOffering.getId()).thenReturn(existingDiskOfferingId);
1190-
DiskOfferingVO newDiskOffering = Mockito.mock(DiskOfferingVO.class);
1191-
when(newDiskOffering.getId()).thenReturn(newDiskOfferingId);
1192-
if(isNotNullServiceOffering) {
1193-
ServiceOfferingVO serviceOfferingVO = Mockito.mock(ServiceOfferingVO.class);
1194-
when(serviceOfferingVO.isCustomized()).thenReturn(isCustomized);
1195-
when(serviceOfferingDao.findServiceOfferingByComputeOnlyDiskOffering(anyLong())).thenReturn(serviceOfferingVO);
1196-
}
1197-
boolean result = volumeApiServiceImpl.isNewDiskOfferingTheSameAndCustomServiceOffering(existingDiskOffering, newDiskOffering);
1198-
Assert.assertEquals(expectedResult, result);
1199-
}
1200-
12011157
private void testBaseListOrderedHostsHypervisorVersionInDc(List<String> hwVersions, HypervisorType hypervisorType,
12021158
String expected) {
12031159
when(_hostDao.listOrderedHostsHypervisorVersionsInDatacenter(anyLong(), any(HypervisorType.class)))

0 commit comments

Comments
 (0)