From fa88fb14697b33388e705d0e4dcdbfdd98196eae Mon Sep 17 00:00:00 2001 From: Sateesh Chodapuneedi Date: Mon, 21 Oct 2013 16:31:45 +0530 Subject: [PATCH] CLOUDSTACK-4911 - [Mixed Hypervisor] VM Status is marked as alive when exit status of ping command is not available within command timeout Currently during ssh execution of remote command, if no response is received within timeout, Cloudstack is returning success result. This is resulting in false positives. Fix is to check if exit status of remote command is available or not. If not, return failure result. Signed-off-by: Sateesh Chodapuneedi CLOUDSTACK-4911 [Mixed Hypervisor] VM Status is marked as alive when exit status of ping command is not available within command timeout Supplementing the fix/commit 748315620bbbc472652e38df960d136beee4882e While remote executing commands through ssh, wait for channel condition of EXIT_STATUS. Signed-off-by: Sateesh Chodapuneedi --- utils/src/com/cloud/utils/ssh/SshHelper.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/utils/src/com/cloud/utils/ssh/SshHelper.java b/utils/src/com/cloud/utils/ssh/SshHelper.java index fb81e506ee5..84d8bc8056f 100755 --- a/utils/src/com/cloud/utils/ssh/SshHelper.java +++ b/utils/src/com/cloud/utils/ssh/SshHelper.java @@ -157,7 +157,7 @@ public class SshHelper { int currentReadBytes = 0; while (true) { if ((stdout.available() == 0) && (stderr.available() == 0)) { - int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, + int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF | ChannelCondition.EXIT_STATUS, waitResultTimeoutInMs); if ((conditions & ChannelCondition.TIMEOUT) != 0) { @@ -166,7 +166,7 @@ public class SshHelper { throw new Exception(msg); } - if ((conditions & ChannelCondition.EOF) != 0) { + if ((conditions & ChannelCondition.EXIT_STATUS) != 0) { if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) { break; } @@ -185,6 +185,12 @@ public class SshHelper { } String result = sbResult.toString(); + + if (sess.getExitStatus() == null) { + //Exit status is NOT available. Returning failure result. + return new Pair(false, result); + } + if (sess.getExitStatus() != null && sess.getExitStatus().intValue() != 0) { s_logger.error("SSH execution of command " + command + " has an error status code in return. result output: " + result); return new Pair(false, result);