#!/bin/bash

BASE_DIR="${0%/*}"

! source "${BASE_DIR}/functions.sh" >/dev/null 2>&1 &&
        echo "File \"${BASE_DIR}/functions.sh\" not found" >&2 && exit 1

make_bogus_ppc64_osimage
make_bogus_grub2_nodes

function custom_cleanup()
{
	destory_bogus_nodes
	destory_bogus_osimages
}

chdef tz002 mac=
chdef tz003 arch=

NODESET_STDOUT="${TMP_DIR}/nodeset.out"
NODESET_STDERR="${TMP_DIR}/nodeset.err"

nodeset tz001+4 osimage=rhels7.99-ppc64-install-compute \
	> >(tee "${NODESET_STDOUT}") 2> >(tee "${NODESET_STDERR}")
# Check $? != 0
[ "$?" -ne "0" ]
exit_if_bad "$?" "nodeset command should exit with non-zero"

grep 'tz002: .*o MAC address' "${NODESET_STDERR}"
exit_if_bad "$?" "nodeset command error message checking failed"

#grep 'tz003: .*o archictecture defined' "${NODESET_STDERR}"
#exit_if_bad "$?" "nodeset command error message checking failed"

# Make sure all other nodes are good
for node in tz001 tz004 tz005
do
	[ -f "/tftpboot/boot/grub2/${node}" ]
	exit_if_bad "$?" "file not found /tftpboot/boot/grub2/${node}"
done

nodeset tz001+4 offline

exit 0
