diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index a60412d41e6..3831f88f21e 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1144,15 +1144,16 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use // Verify input parameters VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId); - if(vmInstance.getHypervisorType() != HypervisorType.XenServer && vmInstance.getHypervisorType() != HypervisorType.VMware){ - throw new InvalidParameterValueException("This operation not permitted for this hypervisor of the vm"); - } if(vmInstance.getState().equals(State.Stopped)){ upgradeStoppedVirtualMachine(vmId, newServiceOfferingId); return true; } + if(vmInstance.getHypervisorType() != HypervisorType.XenServer && vmInstance.getHypervisorType() != HypervisorType.VMware){ + throw new InvalidParameterValueException("This operation not permitted for this hypervisor of the vm"); + } + _accountMgr.checkAccess(caller, null, true, vmInstance); // Check that the specified service offering ID is valid diff --git a/server/test/com/cloud/vm/UserVmManagerTest.java b/server/test/com/cloud/vm/UserVmManagerTest.java index 70a342246f5..2af0e70894e 100755 --- a/server/test/com/cloud/vm/UserVmManagerTest.java +++ b/server/test/com/cloud/vm/UserVmManagerTest.java @@ -272,7 +272,8 @@ public class UserVmManagerTest { // UserContext.current().setEventDetails("Vm Id: "+getId()); Account account = (Account) new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid"); //AccountVO(String accountName, long domainId, String networkDomain, short type, int regionId) - UserContext.registerContext(1, account, null, true); + doReturn(VirtualMachine.State.Running).when(_vmInstance).getState(); + UserContext.registerContext(1, account, null, true); when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);