From da7cbf13a85b09659b1d64b0018e6b9177507147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Tue, 9 Jan 2024 13:10:37 +0100 Subject: [PATCH] Exit immediately if ssh-setup.sh fails --- test/scripts/ssh-setup.sh | 7 +++++-- test/test-manager/src/vm/provision.rs | 11 ++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/scripts/ssh-setup.sh b/test/scripts/ssh-setup.sh index 4aefcfdeed9d..bfe0b66f12c7 100644 --- a/test/scripts/ssh-setup.sh +++ b/test/scripts/ssh-setup.sh @@ -106,5 +106,8 @@ fi setup_systemd # Install required packages -which apt &>/dev/null && apt install -f xvfb wireguard-tools -which dnf &>/dev/null && dnf install -y xorg-x11-server-Xvfb wireguard-tools +if which apt &>/dev/null; then + apt install -f xvfb wireguard-tools +elif which dnf &>/dev/null; then + dnf install -y xorg-x11-server-Xvfb wireguard-tools +fi diff --git a/test/test-manager/src/vm/provision.rs b/test/test-manager/src/vm/provision.rs index b3b39a2c18ee..5f01e8f192b9 100644 --- a/test/test-manager/src/vm/provision.rs +++ b/test/test-manager/src/vm/provision.rs @@ -1,6 +1,6 @@ use crate::config::{OsType, Provisioner, VmConfig}; use crate::package; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use ssh2::Session; use std::fs::File; use std::io::{self, Read}; @@ -203,5 +203,14 @@ fn ssh_exec(session: &Session, command: &str) -> Result { channel.send_eof()?; channel.wait_eof()?; channel.wait_close()?; + + let exit_status = channel + .exit_status() + .context("Failed to obtain exit status")?; + if exit_status != 0 { + log::error!("command failed: {command}\n{output}"); + bail!("command failed: {exit_status}"); + } + Ok(output) }