Skip to content

Commit c6e2e46

Browse files
bvbharatnitinmeh
authored andcommitted
CLOUDSTACK-4068 scaling up user vm and system vm is failing with NPE if current service offering is deleted
Nitin Mehta <nitin.mehta@citrix.com>
1 parent 81b4966 commit c6e2e46

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
12421242

12431243
//Check if its a scale "up"
12441244
ServiceOffering newServiceOffering = _configMgr.getServiceOffering(newServiceOfferingId);
1245-
ServiceOffering currentServiceOffering = _configMgr.getServiceOffering(vmInstance.getServiceOfferingId());
1245+
ServiceOffering currentServiceOffering = _offeringDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
12461246
int newCpu = newServiceOffering.getCpu();
12471247
int newMemory = newServiceOffering.getRamSize();
12481248
int newSpeed = newServiceOffering.getSpeed();

‎server/test/com/cloud/vm/UserVmManagerTest.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.List;
3232
import java.util.UUID;
3333

34+
import com.cloud.service.dao.ServiceOfferingDao;
3435
import org.apache.cloudstack.acl.ControlledEntity;
3536
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
3637
import org.apache.cloudstack.api.ServerApiException;
@@ -102,6 +103,7 @@ public class UserVmManagerTest {
102103
@Mock VolumeVO _volumeMock;
103104
@Mock List<VolumeVO> _rootVols;
104105
@Mock Account _accountMock2;
106+
@Mock ServiceOfferingDao _offeringDao;
105107
@Before
106108
public void setup(){
107109
MockitoAnnotations.initMocks(this);
@@ -117,6 +119,7 @@ public void setup(){
117119
_userVmMgr._userDao = _userDao;
118120
_userVmMgr._accountMgr = _accountMgr;
119121
_userVmMgr._configMgr = _configMgr;
122+
_userVmMgr._offeringDao= _offeringDao;
120123
_userVmMgr._capacityMgr = _capacityMgr;
121124
_userVmMgr._scaleRetry = 2;
122125

@@ -309,10 +312,8 @@ public void testScaleVMF2() throws Exception {
309312

310313
ServiceOffering so1 = (ServiceOffering) getSvcoffering(512);
311314
ServiceOffering so2 = (ServiceOffering) getSvcoffering(256);
312-
313315
when(_configMgr.getServiceOffering(anyLong())).thenReturn(so1);
314-
when(_configMgr.getServiceOffering(1L)).thenReturn(so1);
315-
316+
when(_offeringDao.findByIdIncludingRemoved(anyLong())).thenReturn((ServiceOfferingVO) so1);
316317
_userVmMgr.upgradeVirtualMachine(cmd);
317318

318319
}

0 commit comments

Comments
 (0)