Skip to content

Commit 2aeb460

Browse files
mlsorensenchipchilders
authored andcommitted
CLOUDSTACK-2195: Don't return a UserVM object if we fail to stop vm
pass back null if we fail to connect to agent or stop the vm, rather than something that looks like success to the stopVirtualMachine api command. Testing: Applied to 4.1 branch, attempted to stop VM with KVM agent disconnected, finally saw it fail. The logs also showed why, which is good: 2013-04-25 17:37:09,933 ERROR [cloud.vm.VirtualMachineManagerImpl] (Job-Executor-1:job-44) Unable to stop vm, agent unavailable: com.cloud.exception.AgentUnavailableException: Resource [Host:1] is unreachable: Host 1: Host with specified id is not in the right state: Disconnected Started the KVM agent, and stopping succeeded. Signed-off-by: Chip Childers <chip.childers@gmail.com>
1 parent 15c791d commit 2aeb460

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,9 +3685,15 @@ public UserVm stopVirtualMachine(long vmId, boolean forced)
36853685

36863686
UserVO user = _userDao.findById(userId);
36873687

3688+
boolean status = false;
36883689
try {
36893690
VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid());
3690-
vmEntity.stop(new Long(userId).toString());
3691+
status = vmEntity.stop(new Long(userId).toString());
3692+
if (status) {
3693+
return _vmDao.findById(vmId);
3694+
} else {
3695+
return null;
3696+
}
36913697
} catch (ResourceUnavailableException e) {
36923698
throw new CloudRuntimeException(
36933699
"Unable to contact the agent to stop the virtual machine "
@@ -3698,7 +3704,6 @@ public UserVm stopVirtualMachine(long vmId, boolean forced)
36983704
+ vm, e);
36993705
}
37003706

3701-
return _vmDao.findById(vmId);
37023707
}
37033708

37043709
@Override

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,9 @@ public <T extends VMInstanceVO> boolean advanceStop(T vm, boolean forced, User u
10831083
vmGuru.finalizeStop(profile, answer);
10841084

10851085
} catch (AgentUnavailableException e) {
1086+
s_logger.warn("Unable to stop vm, agent unavailable: " + e.toString());
10861087
} catch (OperationTimedoutException e) {
1088+
s_logger.warn("Unable to stop vm, operation timed out: " + e.toString());
10871089
} finally {
10881090
if (!stopped) {
10891091
if (!forced) {

0 commit comments

Comments
 (0)