#!/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_ppc64le_osimage
make_bogus_petitboot_nodes

function custom_cleanup()
{
	destory_bogus_nodes
	destory_bogus_osimages
}

chdef tz001+4 serialport=0 serialspeed=115200
exit_if_bad "$?" "chdef command failed"

chdef tz002 mac=
chdef tz003 arch=
chdef tz004 serialspeed=

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

nodeset tz001+4 osimage=rhels7.99-ppc64le-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"

grep 'tz004: .*o serialspeed' "${NODESET_STDERR}"
exit_if_bad "$?" "nodeset command error message checking failed"

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

nodeset tz001+4 offline

exit 0
