From 10a6a3eb5fd6b66b1b55d6d65e910a9c9a8fa7b6 Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Thu, 9 Apr 2015 13:58:10 -0400 Subject: move the failure emails into functions so they can be re-used --- leap-platform-test | 81 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/leap-platform-test b/leap-platform-test index 44c38cd..a2723ef 100755 --- a/leap-platform-test +++ b/leap-platform-test @@ -148,32 +148,6 @@ deploy() { echo "Deploying \"$vm\" on $( date )"|tee -a "$LOG1" "$LOG2" $LEAP_CMD $OPTS -v 2 deploy "$vm" 2>&1 | ts | tee -a "$LOG1" "$LOG2" | egrep -v "$FILTER_ALL" | tee -a "$ERRLOG1" "$ERRLOG2" > /dev/null - - if [ -s "$ERRLOG1" ] - then - touch "$deploy_failure" - versions=$( versions ) - subj="WARNING - \"leap deploy\" of platform $PLATFORM_BRANCH branch on \"$vm\" had errors !" - echo "$( date ): $msg" | tee -a "$LOG1" "$LOG2" "$ERRLOG2" - echo - msg="Output of error log below:\n\n$( cat "$ERRLOG1" ) \n\n" - msg="${msg}-------------------------------------------------------------------\n\n" - msg="${msg}error log: ${ERRLOG1}\n" - msg="${msg}comlete log: ${LOG2}\n\n" - - msg="${msg}Tested on $( date ) on \"$vm\" with following versions/git commit IDs: \n\n$versions" - - cat "$ERRLOG1" - - if [ "$MAIL_TO" != '' ]; then - echo "Sending this mail to $MAIL_TO:" - sendemail -f "$MAIL_FROM" -t "$MAIL_TO" -o tls=no -m "${msg}" -u "${subj}" - fi - - else - echo "Deploy to $vm on $( date ) went fine."| tee -a "$LOG1" "$LOG2" - rm "$ERRLOG1" - fi done } @@ -192,17 +166,60 @@ log_start() { } +deploy_failure_email() { + versions=$( versions ) + if [ -s "$ERRLOG1" ] + then + touch "$deploy_failure" + subj="WARNING - \"leap deploy\" of platform $PLATFORM_BRANCH branch on \"$vm\" had errors !" + echo "$( date ): $msg" | tee -a "$LOG1" "$LOG2" "$ERRLOG2" + echo + msg="Output of error log below:\n\n$( cat "$ERRLOG1" ) \n\n" + msg="${msg}-------------------------------------------------------------------\n\n" + msg="${msg}error log: ${ERRLOG1}\n" + msg="${msg}comlete log: ${LOG2}\n\n" + + msg="${msg}Tested on $( date ) on \"$vm\" with following versions/git commit IDs: \n\n$versions" + + cat "$ERRLOG1" + + if [ "$MAIL_TO" != '' ]; then + echo "Sending this mail to $MAIL_TO:" + sendemail -f "$MAIL_FROM" -t "$MAIL_TO" -o tls=no -m "${msg}" -u "${subj}" + fi + + elif [ ! -e "$deploy_failure" -a -n "$MAIL_TO" ] + then + echo "Deploy to $vm on $( date ) went fine."| tee -a "$LOG1" "$LOG2" + rm "$ERRLOG1" + subj="OK - \"leap deploy\" of platform $PLATFORM_BRANCH branch went fine." + msg="Tested on $( date ) on these nodes: \"$nodes\"\nwith following versions/git commit IDs: \n\n$versions" + + echo "Sending deploy success mail to $MAIL_TO" + sendemail -f "$MAIL_FROM" -t "$MAIL_TO" -o tls=no -m "${msg}" -u "${subj}" + fi +} reset_deploy() { - check_for_running_instances || exit $? +test_failure_email() { + test_failure=$? - local nodes="$*" - update_platform - update_leap_cli + versions=$( versions ) + msg="Tested on $( date ) on these nodes: \"$nodes\"\nwith following versions/git commit IDs: \n\n$versions" + if [ $test_failure -eq 0 ] + then + subj="OK - \"leap test\" of platform $PLATFORM_BRANCH branch is all green." + else + subj="WARNING - \"leap test\" of platform $PLATFORM_BRANCH branch failed !!" + fi - cd "$PROVIDERDIR" + echo "$subj" - log_start + echo "Sending test mail to $MAIL_TO" + # unfortunatly, no tls atm, fixed in sendemail 1.56-3 + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=679911 + sendemail -f "$MAIL_FROM" -t "$MAIL_TO" -o tls=no -m "${msg}" -u "${subj}" -a "$TEST_LOG2" +} echo "Starting deploy_nodes for nodes $@ as background tasks on $( date )" -- cgit v1.2.3