mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-10-21 15:18:19 +00:00
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>
This commit is contained in:
@@ -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"* ]]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user