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"* ]] +}