From 1190d76a65e93eefec7c19255e07cea18cf4db1f Mon Sep 17 00:00:00 2001 From: nvazquez Date: Wed, 24 Aug 2016 09:32:55 -0300 Subject: [PATCH] CLOUDSTACK-9470: Fix for SshHelper - test_network_acl was failing on Vmware due to a bug in sshExecute, in which value returned was null and there was still stdout to consume. This fix addresses this problem, consuming stdout peoperly to return expected value in sshExecute --- .../main/java/com/cloud/utils/ssh/SshHelper.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java b/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java index 4d7a852d417..1f6d30c0099 100644 --- a/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java +++ b/utils/src/main/java/com/cloud/utils/ssh/SshHelper.java @@ -22,6 +22,10 @@ package com.cloud.utils.ssh; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -196,6 +200,16 @@ public class SshHelper { String result = sbResult.toString(); + if (StringUtils.isBlank(result)) { + try { + result = IOUtils.toString(stdout, StandardCharsets.UTF_8); + } + catch (IOException e) { + s_logger.error("Couldn't get content of input stream due to: " + e.getMessage()); + return new Pair(false, result); + } + } + if (sess.getExitStatus() == null) { //Exit status is NOT available. Returning failure result. s_logger.error(String.format("SSH execution of command %s has no exit status set. Result output: %s", command, result));