Commit 763c22b4 authored by Dan Reading's avatar Dan Reading
Browse files

Current state: Run in MFS mode on Linux and Freebsd to gather inventory.

Major work done to support MFS mode. New gatherinv function that is only
called if in MFS mode. Gathered info is saved into /proj/emulab-ops/nodecheck

checkutils.sh
Start using traps for ERR and EXIT. New functions to make and use a list
of command to run at exit time. New function to save and set state of exit
on error flag.
instead of 100's

cpucheck
Adjust the rount1p function, round up to nearest 10's.

diskcheck
getmodel() and getserial() working in MFS mode for both Linux and FreeBSD
dd iflag=direct can not be used with if=/dev/zero

gatherinv
New file called only at MFS time to gather hwinventory

rc.nodecheck_sh and rc.nodecheck_perl
rewritten to handle calling gaterinv at MFS mode time, and finding
a functional bash adding it to the PATH
parent c2cd9aaa
#function debugging by setting FUNCDEBUG=y
#exit on unbound var
set -u
#exit on any error
set -e
#only source this file once
if [ "${checkutils+"beenhere"}" == "beenhere" ] ; then
return 0
else
checkutils="sourced"
fi
# add static binaries if needed
declare mfsmode="" #are we running in a MFS (ie busybox) mode
if [ -f /etc/emulab/ismfs ] ; then
......@@ -18,10 +30,7 @@ else
mfsmode=0
fi
#exit on unbound var
set -u
#exit on any error
set -e
declare errext_val
# Gobal Vars
......@@ -30,10 +39,11 @@ declare host #emulab hostname
declare failed="" #major falure to be commicated to user
declare os="" #[Linux|FreeBSD] for now
declare -a todo_exit
declare -A hwinv # hwinv from tmcc.bin
#declare -A tcm_out # hwinv for output
#declare -A tcm_inv # what we have discovered
# declare -p todo_exit
# any command causes exit if -e option set
# including a grep just used so see if some sting is in a file
......@@ -48,7 +58,8 @@ restore_e() {
err_report() {
echo "TRAP ERR at $1"
}
trap 'err_report $FUNCNAME:$LINENO' ERR
#trap 'err_report $FUNCNAME:$LINENO' ERR
trap 'err_report $LINENO' ERR
# read info from tmcc no args uses the globel array hwinv
......@@ -207,18 +218,21 @@ findSmartctl() {
function on_exit()
{
for i in "${todo_exit[@]}" ; do
echo "EXIT TODO: $i"
#echo "EXIT TODO doing: $i"
$($i)
done
return 0
}
function add_on_exit()
{
local n=${#todo_exit[*]}
todo_exit[$n]="$@"
if [[ $n -eq 0 ]]; then
local nex=${#todo_exit[*]}
#echo "add on exit called B4n=${#todo_exit[*]} SHELL=$$ |$@|++++++++++++++++++++"
todo_exit[$nex]="$@"
if [[ $nex -eq 0 ]]; then
trap on_exit EXIT
fi
return 0
}
# setup logging
......@@ -231,7 +245,7 @@ initlogs () {
logfile4tb=${2-"/tmp/nodecheck.log.tb"}
touch ${logfile4tb}
# end XXX XXX
tmplog=/tmp/.$$.log ; cat /dev/null > ${tmplog} # create and truncate
tmplog=/tmp/.$$tmp.log ; cat /dev/null > ${tmplog} # create and truncate
add_on_exit "rm -f $tmplog"
logout=/tmp/.$$logout.log ; touch ${logout} # make it exist
......
......@@ -59,22 +59,22 @@ round1p() {
n=${#y}
# according to #digits add roundup and get most sig-bits
if [ $n == 6 ] ; then
y=$(($y + 5000))
y=$(($y / 10000))
y=$(($y * 10000))
echo -n $y
elif [ $n == 5 ] ; then
y=$(($y + 500))
y=$(($y + 1000))
y=$(($y / 1000))
y=$(($y * 1000))
echo -n $y
elif [ $n == 4 ] ; then
y=$(($y + 50))
elif [ $n == 5 ] ; then
y=$(($y + 100))
y=$(($y / 100))
y=$(($y * 100))
echo -n $y
elif [ $n == 4 ] ; then
y=$(($y + 10))
y=$(($y / 10))
y=$(($y * 10))
echo -n $y
elif [ $n == 3 ] ; then
y=$(($y + 25))
y=$(($y + 1))
y=$(($y / 10))
y=$(($y * 10))
echo -n $y
......@@ -175,7 +175,10 @@ case $os in
"IntelPentiumII") arch="i386" ;;
* ) arch="Unknown" ;;
esac
echo $-
save_e
set +e
echo $-
x=$(grep 'FreeBSD/SMP:' /var/run/dmesg.boot | grep package)
x=${x#FreeBSD/SMP: }
[[ $x ]] && sockets=${x%%package*} || sockets=1
......@@ -192,6 +195,7 @@ case $os in
[[ $x ]] && threads_core=${x%%SMT*} || threads_core=1
x=$(grep 'CPU\|SMP' /var/run/dmesg.boot | grep CPU:)
restore_e
# example CPU: Intel(R) Xeon(TM) CPU 3.00GHz (2992.71-MHz 686-class CPU)
x=${x%%-MHz*}
mhz=$(round1p ${x##*(})
......
......@@ -14,13 +14,16 @@ declare err=""
source getfromtb.sh
source hbis.sh
# if in mfsmode checkutils has all ready been sourced, don't to it again
# else with get second set of varibles
if [ -f /etc/emulab/mfs ] ; then
:
else
#if [ -f /etc/emulab/mfs ] ; then
# :
#else
source checkutils.sh
fi
#fi
## declare -p todo_exit
main() {
inithostname
......@@ -109,7 +112,6 @@ main() {
done
#now fill in the array values
#set -x
for ((idx=0; idx<$numberofdrives; idx++)) ; do
unset -v d ; declare -a d=(${driveinv[$idx]})
for ((i=0;i<=$lastslot;i++)) ; do
......@@ -123,15 +125,15 @@ main() {
$temp_val ) d[$temp_val]=$(gettemp ${drive[$idx]}) ;;
$model_val ) d[$model_val]=$(getmodel ${drive[$idx]}) ;;
$serial_val ) d[$serial_val]=$(getserial ${drive[$idx]}) ;;
$wspeed_val ) d[$wspeed_val]=$(getwspeed ${drive[$idx]}) ;;
$wspeed_val ) d[$wspeed_val]=$(getwspeed ${drive[$idx]})
esac
done
#set +x
# Must have sectors and dpers values first and case statments
# might now execute in order
# for/case loop not need since only one values is being filled
# keep commented just for documentation
# same gos for rspeel, wspeed must be done first
for ((i=0;i<=$lastslot;i++)) ; do
case $i in
$size_val )
......@@ -142,8 +144,7 @@ main() {
$rspeed_val ) d[$rspeed_val]=$(getrspeed ${drive[$idx]}) ;;
esac
done
# just in case
rm -f /var/tmp/ddout
# update driveinv with modified data
driveinv[$idx]=${d[@]}
done
......@@ -163,7 +164,6 @@ main() {
## tbdata=getfromtb $host driveinfo ${d[$name]}
## done
# if saving data for testbed database
if [ -f ${logfile4tb} ] ; then
printf "%s%d\n" "DISKINFO UNITS=" ${numberofdrives} >> ${logfile4tb}
......@@ -185,6 +185,11 @@ if [ -f ${logfile4tb} ] ; then
${d[$driver]} ${d[$driver_val]} >> ${logfile4tb}
done
fi
# we are done if in MFS mode
if [ -f /etc/emulab/ismfs ] ; then
exit 0
fi
#output to log file
{
echo -e "name\t\tdriver\ttype\tsize\ttemp\tmodel\t\t\tserial"
......@@ -417,33 +422,64 @@ gettemp() {
getmodel() {
smtcl=$(findSmartctl)
if [ "${smtcl/smartctl}" == "$smtcl" ] ; then
echo "NA"
return 0
fi
res=$($smtcl -a $1 | grep 'Device Model:')
res=${res/Device Model: }
if [ -z "$res" ] ; then
res=$($smtcl -a $1 | grep 'Product:')
res=${res/Product: }
#don't have smartctl, maybe we can use hdparm
hdp=$(which hdparm)
if [ "${hdp/hdparm}" != "${hdp}" ] ; then
x=$(hdparm -I $1 | grep -i 'Model Number:')
x=${x/Model Number: }
res=${x/# */}
res=${res%# */}
# note: can get the model from '/proc/scsi/scsi'
else
# XXX # note: 'camcontrol devlist'
# will give model on FreeBSD
echo "NA"
return 0
fi
else
res=$($smtcl -a $1 | grep 'Device Model:')
res=${res/Device Model: }
if [ -z "$res" ] ; then
res=$($smtcl -a $1 | grep 'Product:')
res=${res/Product: }
fi
# remove leading spaces
res=${res##* }
fi
# remove leading spaces
res=${res##* }
# no internal spaces
res=${res// /}
res=${res// /-}
[[ $res ]] && echo "$res" || echo "UNKNOWN"
return 0
}
getserial() {
smtcl=$(findSmartctl)
if [ "${smtcl/smartctl}" == "$smtcl" ] ; then
echo "NA"
return 0
getserial() {
res=""
if [ "$os" == "Linux" ] ; then
smtcl=$(findSmartctl)
if [ "${smtcl/smartctl}" == "$smtcl" ] ; then
#don't have smartctl, maybe we can use hdparm
hdp=$(which hdparm)
if [ "${hdp/hdparm}" != "${hdp}" ] ; then
res=$(hdparm -I $1 | grep -i 'Serial number:')
fi
else
res=$($smtcl -a $1 | grep -i 'Serial number:')
fi
res=${res,,} # lower case
res=${res/serial number: }
res=$(echo $res | tr 'a-z' 'A-Z') # upper case
fi
res=$($smtcl -a $1 | grep -i 'Serial number:')
res=${res,,} # lower case
res=${res/serial number: }
res=$(echo $res | tr 'a-z' 'A-Z') # upper case
if [ "$os" == "FreeBSD" ] ; then
# note: if the device is mfi then 'mfiutil show drives' will list
# serial numbers
cmc=$(which camcontrol)
if [ "${cmc/camcontrol}" != "${cmc}" ] ; then
sd=$1
sd=${sd#/dev/}
res=$(camcontrol inquiry $sd -S)
fi
fi
[[ $res ]] && echo "$res" || echo "UNKNOWN"
return 0
}
......@@ -554,12 +590,9 @@ getwspeed() {
canwe=$(df | grep $hdname)
[[ $canwe ]] && { echo mounted; return 0; }
if [ "$os" == "Linux" ] ; then
if [ "$mfsmode" == "1" ] ; then
# static dd we are using may now match kernel call for direct i/o, guess
args="bs=64k count=8000"
else
args="bs=64k iflag=direct count=8000"
fi
#args="bs=64k iflag=direct count=8000"
#note iflag direct can't be used with /dev/zero as infile
args="bs=64k count=8000"
elif [ "$os" == "FreeBSD" ] ; then
args="bs=64k count=8000"
fi
......@@ -567,12 +600,15 @@ getwspeed() {
canwe=$(which dd)
canwe=$(ls -l $canwe | grep busybox)
[[ $canwe ]] && { echo bad_dd; return 0; }
add_on_exit 'rm -f /tmp/ddresultw'
mynn=${#todo_exit[*]}
todo_exit[$mynn]='those are mine'
{
$(dd if=/dev/zero of=$hdname $args)
} > /tmp/ddresultw 2>&1
add_on_exit "rm -f /tmp/ddresultw"
res=$(grep bytes /tmp/ddresultw)
echo $(parsedd $res)
rm -f /tmp/ddresultw
return 0
}
getrspeed() {
......@@ -586,29 +622,40 @@ getrspeed() {
canwe=$(which dd)
canwe=$(ls -l $canwe | grep busybox)
[[ $canwe ]] && { echo bad_dd; return 0; }
add_on_exit 'rm -f /tmp/ddresultr'
{
$(dd of=/dev/null if=$hdname $args)
} > /tmp/ddresultr 2>&1
add_on_exit "rm -f /tmp/ddresultr"
res=$(grep bytes /tmp/ddresultr)
echo $(parsedd $res)
rm -f /tmp/ddresultr
return 0
}
parsedd() {
if [ "$os" == "Linux" ] ; then
y=$9
if [ $y != ${y/MB} ] ; then
x=$8
# linux dd returns 9 positional elements
if [ $# -lt 9 ] ; then
x="DDtimeinERR"
else
x="PareddError"
y=$9
if [ $y != ${y/MB} ] ; then
x=$8
else
x="PareddError"
fi
fi
elif [ "$os" == "FreeBSD" ] ; then
x=$7
x=${x#(}
y=$8
if [ "$y" == "bytes/sec)" ] ; then
x=$(( $x / 1048576 ))
if [ $# -lt 8 ] ; then
x="DDtimeinERR"
else
x=$7
x=${x#(}
y=$8
# FreeBSD seems to return val in bytes/sec, check and convirt to Mb/sec
if [ "$y" == "bytes/sec)" ] ; then
x=$(( $x / 1048576 ))
fi
fi
fi
echo $x
......
#! /bin/bash
mywhich() {
mypath=$(env | grep PATH)
mypath=${mypath/PATH=/}
mypath=${mypath//:/ }
for i in $mypath ; do
if [ -e $i/$1 ] ; then
echo $i/$1
return 0
fi
done
return 1
}
# need to make sure we are running with a full verseion of bash
if [ -f '/etc/emulab/ismfs' ] ; then
# check to see if we are using correct bash
verbash=$(file `which bash`)
verbash=$(file `mywhich bash`)
if [ -z $verbash ] ; then
verbash=$(file -m /proj/emulab-ops/nodecheck/FreeBSD/bin/magic `mywhich bash`)
fi
if [ "$verbash" != "${verbash/busybox}" ] ; then
# NO! we do not, retstart using new bash
# NO! we are not, retstart using the correct bash
# we not be in a loop since correct path is now set
export PATH=/proj/emulab-ops/nodecheck/$(uname -s)/bin:$PATH
bash $0
......@@ -21,30 +37,30 @@ gatherinv_main() {
$(cp /dev/null /tmp/nodecheck.log.tb)
checks="disk cpu mem nic"
set +e
for i in $checks ; do
bash /usr/local/etc/emulab/${i}check /var/emulab/logs/nodecheck.log /tmp/nodecheck.log.tb
done
set +e
# cat /tmp/nodecheck.log.tb
# read in the newly found info
readtmcinfo /tmp/nodecheck.log.tb
#mv /tmp/nodecheck.log.tb /tmp/nodecheck.bk
# print it back out
{ printtmcinfo
} > /tmp/nodecheck.log.tb
} > /tmp/nodecheck.log.tb.new
# print
{ printhwinv
} > /tmp/nodecheck.log.inv
host=$(tmcc.bin nodeid)
host=$(/usr/local/etc/emulab/tmcc.bin nodeid)
$(cp /tmp/nodecheck.log.tb /proj/emulab-ops/nodecheck/$host);
$(cp /tmp/nodecheck.log.tb.new /proj/emulab-ops/nodecheck/$host);
$(cp /tmp/nodecheck.log.inv /proj/emulab-ops/nodecheck/$host.full);
$(chmod a+r /proj/emulab-ops/nodecheck/$host*);
echo "NEED TO ENABLE rm -f /tmp/nodecheck.log.tb /tmp/nodecheck.log.inv"
# echo "NEED TO ENABLE rm -f /tmp/nodecheck.log.tb /tmp/nodecheck.log.inv"
}
gatherinv_main $0
......
......@@ -33,7 +33,8 @@ cat ${tmplog} >> ${logfile}
cat ${tmplog2} >> ${logfile}
rm -f ${tmplog2}
[[ -z ${failed} ]] && exit 1 || exit 0
# XXXX XXXX XXX [[ -z ${failed} ]] && exit 1 || exit 0
exit 0
}
......
......@@ -37,7 +37,7 @@ BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
# do not run timecheck for MFS hw gather mode
@checkscripts = ("disk", "cpu", "mem", "time", "nic");
$host = `/usr/bin/tmcc.bin nodid`;
$host = `/usr/local/etc/emulab/tmcc.bin nodeid`;
#$host = `hostname`;
#if ( -r '/var/emulab/boot/realname' ) {
......@@ -49,7 +49,9 @@ $host = `/usr/bin/tmcc.bin nodid`;
chomp($host);
if ( -r '/etc/emulab/ismfs' ) {
system("mount fs.emulab.net:/q/proj/emulab-ops /proj/emulab-ops");
if ( ! -r '/proj/emulab-ops/nodecheck' ) {
system("mount fs.emulab.net:/q/proj/emulab-ops /proj/emulab-ops");
}
my $os = `uname -s`;
chomp($os);
if ($os eq "Linux") {
......
......@@ -15,21 +15,10 @@ if [ -r /etc/emulab/paths.sh ]; then
else
BINDIR=/etc/testbed
fi
if [ "`uname -s`" = "FreeBSD" ]; then
PATH=/usr/local/bin:/proj/emulab-ops/nodecheck/bin_freebsd:$PATH
export PATH
fi
# FREEBSD
host=`hostname`
if [ -e "/var/emulab/boot/realname" ]; then
host=$(cat /var/emulab/boot/realname)
elif
[ -e "/var/emulab/boot/nodeid" ]; then
host=$(cat /var/emulab/boot/nodeid)
fi
host=`/usr/local/etc/emulab/tmcc.bin nodeid`
#checks="disk cpu mem time nic diskspeed"
......@@ -37,6 +26,23 @@ fi
#checks="disk cpu mem time nic"
checks="disk cpu mem nic gather"
if [ -f '/etc/emulab/ismfs' ] ; then
if [ ! -d '/proj/emulab-ops/nodecheck' ] ; then
$("mount fs.emulab.net:/q/proj/emulab-ops /proj/emulab-ops")
fi
os=`uname -s`
if [ "$os" = "Linux" ] ; then
export PATH="/usr/local/bin:/proj/emulab-ops/nodecheck/Linux/bin:$PATH"
elif [ "$os" = "FreeBSD" ] ; then
export PATH="/usr/local/bin:/proj/emulab-ops/nodecheck/FreeBSD/bin:$PATH"
fi
echo 'Running Hardware Inventory Gather'
bash /usr/local/etc/emulab/gatherinv
echo 'Done Running Hardware Inventory'
exit 0
fi
echo "Running nodechecks"
# truncate file at boot time
if [ "$1" = "boot" ] ; then
......
......@@ -39,7 +39,7 @@ bsd=""
#echo "linux||$linux||"
utils="diskcheck diskspeedcheck memcheck cpucheck checkutils.sh getfromtb.sh hbis.sh timecheck niccheck gathercheck"
utils="diskcheck diskspeedcheck memcheck cpucheck checkutils.sh getfromtb.sh hbis.sh timecheck niccheck gatherinv"
arg=${arg=""} # use var if set else use ""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment