Blame IbaTools/nodeverify/opaverifynodes.sh

Packit 857059
#!/bin/bash
Packit 857059
# BEGIN_ICS_COPYRIGHT8 ****************************************
Packit 857059
# 
Packit 857059
# Copyright (c) 2015-2017, Intel Corporation
Packit 857059
# 
Packit 857059
# Redistribution and use in source and binary forms, with or without
Packit 857059
# modification, are permitted provided that the following conditions are met:
Packit 857059
# 
Packit 857059
#     * Redistributions of source code must retain the above copyright notice,
Packit 857059
#       this list of conditions and the following disclaimer.
Packit 857059
#     * Redistributions in binary form must reproduce the above copyright
Packit 857059
#       notice, this list of conditions and the following disclaimer in the
Packit 857059
#       documentation and/or other materials provided with the distribution.
Packit 857059
#     * Neither the name of Intel Corporation nor the names of its contributors
Packit 857059
#       may be used to endorse or promote products derived from this software
Packit 857059
#       without specific prior written permission.
Packit 857059
# 
Packit 857059
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 857059
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 857059
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit 857059
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
Packit 857059
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 857059
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit 857059
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Packit 857059
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Packit 857059
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 857059
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 857059
# 
Packit 857059
# END_ICS_COPYRIGHT8   ****************************************
Packit 857059
Packit 857059
# [ICS VERSION STRING: unknown]
Packit 857059
Packit 857059
# verify hosts basic single node configuration and performance via hostverify.sh
Packit 857059
# prior to using this, copy /usr/share/opa/samples/hostverify.sh to FF_HOSTVERIFY_DIR,
Packit 857059
# and edit to set proper expectations for node configuration and performance, 
Packit 857059
Packit 857059
# optional override of defaults
Packit 857059
if [ -f /etc/opa/opafastfabric.conf ]
Packit 857059
then
Packit 857059
	. /etc/opa/opafastfabric.conf
Packit 857059
fi
Packit 857059
Packit 857059
. /usr/lib/opa/tools/opafastfabric.conf.def
Packit 857059
Packit 857059
. /usr/lib/opa/tools/ff_funcs
Packit 857059
Packit 857059
trap "exit 1" SIGHUP SIGTERM SIGINT
Packit 857059
Packit 857059
punchlist=$FF_RESULT_DIR/punchlist.csv
Packit 857059
del=';' # TBD what will work best for import
Packit 857059
Packit 857059
Usage_full()
Packit 857059
{
Packit 857059
	echo "Usage: opaverifyhosts [-kc] [-f hostfile] [-u upload_file] [-d upload_dir]" >&2
Packit 857059
	echo "                         [-h 'hosts'] [-T timelimit] [test ...]" >&2
Packit 857059
	echo "              or" >&2
Packit 857059
	echo "       opaverifyhosts --help" >&2
Packit 857059
	echo "   --help - produce full help text" >&2
Packit 857059
	echo "   -k - at start and end of verification, kill any existing hostverify" >&2
Packit 857059
	echo "        or xhpl jobs on the hosts" >&2
Packit 857059
	echo "   -c - copy hostverify.sh to hosts first, useful if you have edited it" >&2
Packit 857059
	echo "   -f hostfile - file with hosts in cluster, default is $CONFIG_DIR/opa/hosts" >&2
Packit 857059
	echo "   -h hosts - list of hosts to ping" >&2
Packit 857059
	echo "   -u upload_file - filename to upload hostverify.res to after verification" >&2
Packit 857059
	echo "                    to allow backup and review of the detailed results" >&2
Packit 857059
	echo "                    for each node" >&2
Packit 857059
	echo "                    The default upload destination file is hostverify.res" >&2
Packit 857059
	echo "                    If -u '' is specified, no upload will occur" >&2
Packit 857059
	echo "   -d upload_dir - directory to upload result from each host to" >&2
Packit 857059
	echo "                   default is uploads" >&2
Packit 857059
	echo "   -T timelimit - timelimit in seconds for host to complete tests" >&2
Packit 857059
	echo "                  default of 300 seconds (5 minutes)" >&2
Packit 857059
	echo "   -F filename - filename of hostverify script to use. Default is $FF_HOSTVERIFY_DIR/hostverify.sh" >&2
Packit 857059
	echo "	 test - one or more specific tests to run" >&2
Packit 857059
	echo "	        see /usr/share/opa/samples/hostverify.sh for a list of available tests" >&2
Packit 857059
	echo "This verifies basic node configuration and performance by running" >&2
Packit 857059
	echo "FF_HOSTVERIFY_DIR/hostverify.sh on all specified hosts" >&2
Packit 857059
	echo >&2
Packit 857059
	echo "Prior to using this, copy /usr/share/opa/samples/hostverify.sh to FF_HOSTVERIFY_DIR" >&2
Packit 857059
	echo "and edit to set proper expectations for node configuration and performance" >&2
Packit 857059
	echo "Then be sure to use the -c option on first run for a given node" >&2
Packit 857059
	echo "so that hostverify.sh gets copied to each node." >&2
Packit 857059
	echo "FF_HOSTVERIFY_DIR is configured in /etc/opa/opafastfabric.conf" >&2
Packit 857059
	echo >&2
Packit 857059
	echo "A summary of results is appended to FF_RESULT_DIR/verifyhosts.res." >&2
Packit 857059
	echo "A punchlist of failures is also appended to FF_RESULT_DIR/punchlist.csv" >&2
Packit 857059
	echo "Only failures are shown on stdout" >&2
Packit 857059
	echo >&2
Packit 857059
	echo " Environment:" >&2
Packit 857059
	echo "   HOSTS - list of hosts, used if -h option not supplied" >&2
Packit 857059
	echo "   HOSTS_FILE - file containing list of hosts, used in absence of -f and -h" >&2
Packit 857059
	echo "   UPLOADS_DIR - directory to upload to, used in absence of -d" >&2
Packit 857059
	echo "   FF_MAX_PARALLEL - maximum concurrent operations" >&2
Packit 857059
	echo "example:">&2
Packit 857059
	echo "   opaverifyhosts -c" >&2
Packit 857059
	echo "   opaverifyhosts -h 'arwen elrond'" >&2
Packit 857059
	echo "   HOSTS='arwen elrond' opaverifyhosts" >&2
Packit 857059
	exit 0
Packit 857059
}
Packit 857059
Packit 857059
Usage()
Packit 857059
{
Packit 857059
	echo "Usage: opaverifyhosts [-kc] [-f hostfile] [-u upload_file]" >&2
Packit 857059
	echo "              or" >&2
Packit 857059
	echo "       opaverifyhosts --help" >&2
Packit 857059
	echo "   --help - produce full help text" >&2
Packit 857059
	echo "   -k - at start and end of verification, kill any existing hostverify" >&2
Packit 857059
	echo "        or xhpl jobs on the hosts" >&2
Packit 857059
	echo "   -c - copy hostverify.sh to hosts first, useful if you have edited it" >&2
Packit 857059
	echo "   -f hostfile - file with hosts in cluster, default is $CONFIG_DIR/opa/hosts" >&2
Packit 857059
	echo "   -u upload_file - filename to upload hostverify.res to after verification" >&2
Packit 857059
	echo "                    to allow backup and review of the detailed results" >&2
Packit 857059
	echo "                    for each node" >&2
Packit 857059
	echo "                    The default upload destination file is hostverify.res" >&2
Packit 857059
	echo "                    If -u '' is specified, no upload will occur" >&2
Packit 857059
	echo >&2
Packit 857059
	echo "This verifies basic node configuration and performance by running" >&2
Packit 857059
	echo "FF_HOSTVERIFY_DIR/hostverify.sh on all specified hosts" >&2
Packit 857059
	echo >&2
Packit 857059
	echo "Prior to using this, copy /usr/share/opa/samples/hostverify.sh to FF_HOSTVERIFY_DIR" >&2
Packit 857059
	echo "and edit to set proper expectations for node configuration and performance" >&2
Packit 857059
	echo "Then be sure to use the -c option on first run for a given node" >&2
Packit 857059
	echo "so that hostverify.sh gets copied to each node." >&2
Packit 857059
	echo "FF_HOSTVERIFY_DIR is configured in /etc/opa/opafastfabric.conf" >&2
Packit 857059
	echo >&2
Packit 857059
	echo "A summary of results is appended to FF_RESULT_DIR/verifyhosts.res." >&2
Packit 857059
	echo "A punchlist of failures is also appended to FF_RESULT_DIR/punchlist.csv" >&2
Packit 857059
	echo "Only failures are shown on stdout" >&2
Packit 857059
	echo >&2
Packit 857059
	echo "example:">&2
Packit 857059
	echo "   opaverifyhosts" >&2
Packit 857059
	echo "   opaverifyhosts -c" >&2
Packit 857059
	exit 2
Packit 857059
}
Packit 857059
Packit 857059
if [ x"$1" = "x--help" ]
Packit 857059
then
Packit 857059
	Usage_full
Packit 857059
fi
Packit 857059
Packit 857059
append_punchlist()
Packit 857059
# stdin has verifyhosts.res failure lines generated in this run
Packit 857059
{
Packit 857059
	(
Packit 857059
	export IFS=':'
Packit 857059
	opasorthosts | while read host failinfo
Packit 857059
	do
Packit 857059
		echo "$timestamp$del$host$del$failinfo"
Packit 857059
	done >> $punchlist
Packit 857059
	)
Packit 857059
}
Packit 857059
Packit 857059
job_cleanup()
Packit 857059
{
Packit 857059
	# HOSTS is exported
Packit 857059
	if [ "$do_kill" = y ]
Packit 857059
	then
Packit 857059
		# we don't log this
Packit 857059
		echo "Killing hostverify and xhpl on hosts..."
Packit 857059
		# we use patterns so the pkill doesn't kill this script or opacmdall itself
Packit 857059
		# use an echo at end so exit status is good
Packit 857059
		opacmdall -p -T 60 "pkill -9 -f -x 'host[v]erify.*.sh'; pkill -9 '[x]hpl'; echo -n"
Packit 857059
	fi
Packit 857059
}
Packit 857059
Packit 857059
do_copy=n
Packit 857059
upload_file=hostverify.res
Packit 857059
timelimit=300
Packit 857059
do_kill=n
Packit 857059
filename=$FF_HOSTVERIFY_DIR/hostverify.sh
Packit 857059
while getopts kcf:h:d:u:T:F: param
Packit 857059
do
Packit 857059
	case $param in
Packit 857059
	k)
Packit 857059
		do_kill=y;;
Packit 857059
	c)
Packit 857059
		do_copy=y;;
Packit 857059
	h)
Packit 857059
		HOSTS="$OPTARG";;
Packit 857059
	f)
Packit 857059
		HOSTS_FILE="$OPTARG";;
Packit 857059
	d)
Packit 857059
		export UPLOADS_DIR="$OPTARG";;
Packit 857059
	u)
Packit 857059
		upload_file="$OPTARG";;
Packit 857059
	T)
Packit 857059
		timelimit="$OPTARG";;
Packit 857059
	F)
Packit 857059
		filename="$OPTARG";;
Packit 857059
	?)
Packit 857059
		Usage;;
Packit 857059
	esac
Packit 857059
done
Packit 857059
shift $((OPTIND -1))
Packit 857059
check_host_args opaverifyhosts
Packit 857059
# HOSTS now lists all the hosts, pass it along to the commands below via env
Packit 857059
export HOSTS
Packit 857059
unset HOSTS_FILE
Packit 857059
Packit 857059
job_cleanup
Packit 857059
Packit 857059
echo "=============================================================================" >> $FF_RESULT_DIR/verifyhosts.res
Packit 857059
date >> $FF_RESULT_DIR/verifyhosts.res
Packit 857059
echo "$(echo "$HOSTS"|tr -s ' ' '\n'|sed -e '/^$/d'|sort -u| wc -l) hosts will be verified" | tee -a $FF_RESULT_DIR/verifyhosts.res
Packit 857059
Packit 857059
if [ "$do_copy" = y ]
Packit 857059
then
Packit 857059
	echo "SCPing $filename to $FF_HOSTVERIFY_DIR/hostverify.sh ..."| tee -a $FF_RESULT_DIR/verifyhosts.res
Packit 857059
	opascpall -p "$filename" "$FF_HOSTVERIFY_DIR/hostverify.sh" 2>&1|tee -a $FF_RESULT_DIR/verifyhosts.res
Packit 857059
	date >> $FF_RESULT_DIR/verifyhosts.res
Packit 857059
fi
Packit 857059
Packit 857059
timestamp=$(date +"%Y/%m/%d %T")
Packit 857059
echo "Running $FF_HOSTVERIFY_DIR/hostverify.sh -d $FF_HOSTVERIFY_DIR $* ..."
Packit 857059
resultlineno=$(cat $FF_RESULT_DIR/verifyhosts.res|wc -l)	# for punchlist
Packit 857059
opacmdall -p -T $timelimit "bash $FF_HOSTVERIFY_DIR/hostverify.sh -d $FF_HOSTVERIFY_DIR $*" 2>&1|tee -a $FF_RESULT_DIR/verifyhosts.res|egrep 'FAIL'
Packit 857059
# update punchlist using new failures
Packit 857059
tail -n +$resultlineno $FF_RESULT_DIR/verifyhosts.res| egrep 'FAIL'|append_punchlist
Packit 857059
date >> $FF_RESULT_DIR/verifyhosts.res
Packit 857059
Packit 857059
job_cleanup
Packit 857059
Packit 857059
# upload the result file from each host
Packit 857059
if [ z"$upload_file" != z ]
Packit 857059
then
Packit 857059
	echo "Uploading $FF_HOSTVERIFY_DIR/hostverify.res to $UPLOADS_DIR/$upload_file ..."| tee -a $FF_RESULT_DIR/verifyhosts.res
Packit 857059
	opauploadall -p $FF_HOSTVERIFY_DIR/hostverify.res $upload_file 2>&1|tee -a $FF_RESULT_DIR/verifyhosts.res
Packit 857059
	date >> $FF_RESULT_DIR/verifyhosts.res
Packit 857059
fi