Fix a bug in the helper's monitoring system
authorNikos Skalkotos <skalkoto@grnet.gr>
Wed, 31 Oct 2012 09:59:45 +0000 (11:59 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Tue, 13 Nov 2012 13:03:23 +0000 (15:03 +0200)
Fix a bug where the helper will not send a image-helper-error msg
if an error occures when running snf-image-helper main script and
not one of the configuration tasks.

Conflicts:

snf-image-helper/common.sh

snf-image-helper/common.sh

index c2f2efc..92725c1 100644 (file)
@@ -53,9 +53,24 @@ add_cleanup() {
     CLEANUP+=("$cmd")
 }
 
+report_error() {
+    if [ ${#ERRORS[*]} -eq 0 ]; then
+        # No error message. Print stderr
+       local lines=$(tail --lines=${STDERR_LINE_SIZE} "$STDERR_FILE" | wc -l)
+        echo -n "STDERR:${lines}:" > "$MONITOR"
+        tail --lines=$lines  "$STDERR_FILE" > "$MONITOR"
+    else
+        echo -n "ERROR:" > "$MONITOR"
+        for line in "${ERRORS[@]}"; do
+            echo "$line" > "$MONITOR"
+        done
+    fi
+}
+
 log_error() {
     ERRORS+=("$@")
     echo "ERROR: $@" | tee $RESULT >&2
+    report_error
     exit 1
 }
 
@@ -72,20 +87,6 @@ report_task_end() {
     echo "$MSG_TYPE_TASK_END:${PROGNAME:2}" > "$MONITOR"
 }
 
-report_error() {
-    if [ ${#ERRORS[*]} -eq 0 ]; then
-        # No error message. Print stderr
-       local lines=$(tail --lines=${STDERR_LINE_SIZE} "$STDERR_FILE" | wc -l)
-        echo -n "STDERR:${lines}:" > "$MONITOR"
-        tail --lines=$lines  "$STDERR_FILE" > "$MONITOR"
-    else
-        echo -n "ERROR:" > "$MONITOR"
-        for line in "${ERRORS[@]}"; do
-            echo "$line" > "$MONITOR"
-        done
-    fi
-}
-
 system_poweroff() {
     echo o > /proc/sysrq-trigger
 }
@@ -377,8 +378,6 @@ task_cleanup() {
 
     if [ $rc -eq 0 ]; then
        report_task_end
-    else
-       report_error
     fi
 
     cleanup