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>
This commit is contained in:
Marcus Sorensen 2013-04-26 17:25:52 +01:00 committed by Chip Childers
parent 15c791d7f5
commit 2aeb46072c
2 changed files with 9 additions and 2 deletions

View File

@ -3685,9 +3685,15 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
UserVO user = _userDao.findById(userId);
boolean status = false;
try {
VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid());
vmEntity.stop(new Long(userId).toString());
status = vmEntity.stop(new Long(userId).toString());
if (status) {
return _vmDao.findById(vmId);
} else {
return null;
}
} catch (ResourceUnavailableException e) {
throw new CloudRuntimeException(
"Unable to contact the agent to stop the virtual machine "
@ -3698,7 +3704,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
+ vm, e);
}
return _vmDao.findById(vmId);
}
@Override

View File

@ -1083,7 +1083,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
vmGuru.finalizeStop(profile, answer);
} catch (AgentUnavailableException e) {
s_logger.warn("Unable to stop vm, agent unavailable: " + e.toString());
} catch (OperationTimedoutException e) {
s_logger.warn("Unable to stop vm, operation timed out: " + e.toString());
} finally {
if (!stopped) {
if (!forced) {