From e7cf513064e3e09f5ae25ec20b64052f519b95d3 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 2 Jun 2021 17:51:07 +0000 Subject: [PATCH] test_infra: Return an error if SSH executed command exits with non-zero Signed-off-by: Rob Bradford --- test_infra/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index 532f0018f..5e25903a7 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -503,6 +503,8 @@ pub enum SshCommandError { Authentication(ssh2::Error), ChannelSession(ssh2::Error), Command(ssh2::Error), + ExitStatus(ssh2::Error), + NonZeroExitStatus(i32), } pub fn ssh_command_ip_with_auth( @@ -537,7 +539,14 @@ pub fn ssh_command_ip_with_auth( let _ = channel.read_to_string(&mut s); let _ = channel.close(); let _ = channel.wait_close(); - Ok(()) + + let status = channel.exit_status().map_err(SshCommandError::ExitStatus)?; + + if status != 0 { + Err(SshCommandError::NonZeroExitStatus(status)) + } else { + Ok(()) + } })() { Ok(_) => break, Err(e) => {