From cec3d05b3c5cdfd5246fc96e8aa17cf84741077c Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Wed, 7 Oct 2026 13:46:22 -0300 Subject: [PATCH] test(xcat-core): capture the SUSE NIC backup that hides a copy failure nic_cfg.sh backup ends its SUSE branch with "|| :" and sends stderr to /dev/null. A cp that fails on a real ifcfg file therefore returns 0 and prints nothing, and the restore later puts back an incomplete backup. The new cases check that a directory with no ifcfg file still backs up, that an ifcfg file is copied, and that a failed copy returns non-zero with the cp error on stderr. The last case fails on the current script. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/bats/nic_cfg_backup_absent_dir.bats | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/xCAT-test/bats/nic_cfg_backup_absent_dir.bats b/xCAT-test/bats/nic_cfg_backup_absent_dir.bats index e4fd1f88f..61cfdc845 100644 --- a/xCAT-test/bats/nic_cfg_backup_absent_dir.bats +++ b/xCAT-test/bats/nic_cfg_backup_absent_dir.bats @@ -1,6 +1,8 @@ #!/usr/bin/env bats # nic_cfg.sh backup must succeed on a node with no persistent network configuration. +bats_require_minimum_version 1.5.0 + load 'helpers/shell_source' setup() @@ -51,3 +53,31 @@ setup() NIC_CFG_BACKEND=ubuntu run "$SCRIPT" backup [ "$status" -ne 0 ] } + +@test "a SUSE node with no ifcfg file is backed up without an error and nothing copied" { + mkdir -p "$SUSEDIR" + printf 'default 192.0.2.1 - -\n' >"$SUSEDIR/routes" + NIC_CFG_BACKEND=suse run "$SCRIPT" backup + [ "$status" -eq 0 ] + [ -z "$(ls -A "$BACKUP")" ] +} + +@test "a SUSE node has its ifcfg files backed up" { + mkdir -p "$SUSEDIR" + printf "BOOTPROTO='static'\n" >"$SUSEDIR/ifcfg-eth0" + NIC_CFG_BACKEND=suse run "$SCRIPT" backup + [ "$status" -eq 0 ] + [ -f "$BACKUP/ifcfg-eth0" ] +} + +@test "a SUSE ifcfg file that cannot be copied fails the backup" { + mkdir -p "$SUSEDIR" + printf "BOOTPROTO='static'\n" >"$SUSEDIR/ifcfg-eth0" + # nic_cfg.sh is a bash script, so it inherits this exported function. + cp() { echo "cp: cannot create regular file: Read-only file system" >&2; return 1; } + export -f cp + NIC_CFG_BACKEND=suse run --separate-stderr "$SCRIPT" backup + unset -f cp + [ "$status" -ne 0 ] + [[ "$stderr" == *"Read-only file system"* ]] +}