Skip to content

Commit fa88fb1

Browse files
author
Sateesh Chodapuneedi
committed
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 <sateesh@apache.org> 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 7483156 While remote executing commands through ssh, wait for channel condition of EXIT_STATUS. Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>
1 parent d61e60b commit fa88fb1

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

utils/src/com/cloud/utils/ssh/SshHelper.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static Pair<Boolean, String> sshExecute(String host, int port, String use
157157
int currentReadBytes = 0;
158158
while (true) {
159159
if ((stdout.available() == 0) && (stderr.available() == 0)) {
160-
int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF,
160+
int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF | ChannelCondition.EXIT_STATUS,
161161
waitResultTimeoutInMs);
162162

163163
if ((conditions & ChannelCondition.TIMEOUT) != 0) {
@@ -166,7 +166,7 @@ public static Pair<Boolean, String> sshExecute(String host, int port, String use
166166
throw new Exception(msg);
167167
}
168168

169-
if ((conditions & ChannelCondition.EOF) != 0) {
169+
if ((conditions & ChannelCondition.EXIT_STATUS) != 0) {
170170
if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
171171
break;
172172
}
@@ -185,6 +185,12 @@ public static Pair<Boolean, String> sshExecute(String host, int port, String use
185185
}
186186

187187
String result = sbResult.toString();
188+
189+
if (sess.getExitStatus() == null) {
190+
//Exit status is NOT available. Returning failure result.
191+
return new Pair<Boolean, String>(false, result);
192+
}
193+
188194
if (sess.getExitStatus() != null && sess.getExitStatus().intValue() != 0) {
189195
s_logger.error("SSH execution of command " + command + " has an error status code in return. result output: " + result);
190196
return new Pair<Boolean, String>(false, result);

0 commit comments

Comments
 (0)