Added support for multiple modules at a time and exclude pattern.

This commit is contained in:
Christoph Niethammer 2016-09-08 08:51:31 +00:00
parent 5d51934894
commit d710e1f528

View file

@ -1,24 +1,46 @@
#!/bin/bash -l #!/bin/bash -l
# #
# Copyright (c) 2012-2015 Christoph Niethammer <niethammer@hlrs.de> # Copyright (c) 2012-2016 Christoph Niethammer <niethammer@hlrs.de>
# #
# Script checking the module environment for problems during module loading/unloading # Script checking the module environment for problems during module loading/unloading
# #
# Usage:
# check_modules.sh [MODULE] function print_usage() {
# echo <<EOT
# Options: Script checking the module environment for problems during module loading/unloading
# MODULE May be any valid module path as used for 'module avail [MODULE]' usage: $0 [MODULE_PATTERN] [--exclude PATTERN]"
# EOT
}
# Command line options: # Command line options:
moduleclass=$1 # check only subset of modules declare -a moduleclasses # check only subset of modules
declare -a exclude_pattern # exclude modules with given pattern, e.g. nightly builds
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--exclude-pattern|--exclude)
exclude_patterns+=($2)
shift 2
;;
-h|--help)
print_usage
exit 0
;;
*)
moduleclasses+=($1)
shift
;;
esac
done
# definitions for esear color output to display # definitions for esear color output to display
Color_Off='\e[0m' # Text Reset Color_Off='\e[0m' # Text Reset
IGreen='\e[0;92m' # Intense Green IGreen='\e[0;92m' # Intense Green
IRed='\e[0;91m' # Intense Red IRed='\e[0;91m' # Intense Red
echo Moduleclasses: ${moduleclasses[@]}
echo Exclude: ${exclude_patterns[@]}
# intermediate files, logfiles # intermediate files, logfiles
LOGDIR=${LOGDIR:=$PWD} LOGDIR=${LOGDIR:=$PWD}
tmpdir=/tmp/check_modules-$USER tmpdir=/tmp/check_modules-$USER
@ -48,60 +70,74 @@ echo "Environment:" >> $logfile
cat $module_clean_env_file >> $logfile cat $module_clean_env_file >> $logfile
echo "--------------------" >> $logfile echo "--------------------" >> $logfile
for m_original in $(module av -t $moduleclass 2>&1); do for moduleclass in ${moduleclasses[@]}
if [[ $m_original =~ ^[A-Za-z] ]]; then # skip any non module line in output do
m=$(echo $m_original | sed -e 's/(.*)//') # Remove aliases e.g. (default) for m_original in $(module av -t $moduleclass 2>&1); do
echo -n "Checking $m_original ... " match=0
echo "Checking $m_original ... " >> $logfile for exclude_pattern in ${exclude_patterns[@]}
do
if [[ "$m_original" =~ "$exclude_pattern" ]]; then
echo MATCH: $exclude_pattern
match=1
fi
done
if [ $match == 1 ]; then
continue
fi
if [[ $m_original =~ ^[A-Za-z] ]]; then # skip any non module line in output
m=$(echo $m_original | sed -e 's/(.*)//') # Remove aliases e.g. (default)
echo -n "Checking $m_original ... "
echo "Checking $m_original ... " >> $logfile
cmd="module load $m" cmd="module load $m"
echo $cmd >> $logfile
$cmd > $module_load_logfile 2>&1
cat $module_load_logfile >> $logfile
module li >>$logfile 2>&1
# check if module was loaded and did not report errors during loading
if module li -t 2>&1 | grep $m >/dev/null && ! grep ERROR $module_load_logfile >/dev/null ; then
cmd="module rm $m"
echo $cmd >> $logfile echo $cmd >> $logfile
$cmd > $module_rm_logfile 2>&1 $cmd > $module_load_logfile 2>&1
cat $module_rm_logfile >> $logfile cat $module_load_logfile >> $logfile
module li >>$logfile 2>&1 module li >>$logfile 2>&1
# check if module was unloaded # check if module was loaded and did not report errors during loading
if module li -t 2>&1 | grep $m > /dev/null; then if module li -t 2>&1 | grep $m >/dev/null && ! grep ERROR $module_load_logfile >/dev/null ; then
echo -e "${IRed}unloading failed${Color_Off}"
echo "ERROR: unloading module '$m' failed" >> $logfile cmd="module rm $m"
failed_modules=(${failed_modules[@]} $m_original) echo $cmd >> $logfile
$cmd > $module_rm_logfile 2>&1
cat $module_rm_logfile >> $logfile
module li >>$logfile 2>&1
# check if module was unloaded
if module li -t 2>&1 | grep $m > /dev/null; then
echo -e "${IRed}unloading failed${Color_Off}"
echo "ERROR: unloading module '$m' failed" >> $logfile
failed_modules=(${failed_modules[@]} $m_original)
else
echo -e "${IGreen}success${Color_Off}"
echo "SUCCESS" >> $logfile
fi
else else
echo -e "${IGreen}success${Color_Off}" echo -e "${IRed}loading failed${Color_Off}"
echo "SUCCESS" >> $logfile echo "ERROR: loading module '$m' failed" >> $logfile
failed_modules=(${failed_modules[@]} $m)
fi fi
else # clean up module environment
echo -e "${IRed}loading failed${Color_Off}" cmd="module purge"
echo "ERROR: loading module '$m' failed" >> $logfile echo $cmd >> $logfile
failed_modules=(${failed_modules[@]} $m) $cmd >>$logfile 2>&1
module li >>$logfile 2>&1
echo "Resetting environment ..." >>$logfile
# Reset the complete environment manually to overcome problems with
# inconsistent internal caches of the module command after module purge.
source $module_clean_env_file 2>/dev/null
# clean up intermediate files
rm -f $module_load_logfile
rm -f $module_rm_logfile
echo >>$logfile 2>&1
fi fi
done
# clean up module environment
cmd="module purge"
echo $cmd >> $logfile
$cmd >>$logfile 2>&1
module li >>$logfile 2>&1
echo "Resetting environment ..." >>$logfile
# Reset the complete environment manually to overcome problems with
# inconsistent internal caches of the module command after module purge.
source $module_clean_env_file 2>/dev/null
# clean up intermediate files
rm -f $module_load_logfile
rm -f $module_rm_logfile
echo >>$logfile 2>&1
fi
done done
# clean up file storing the initial environment # clean up file storing the initial environment