From 9ddf1b5f28f4cf0e79c73d370286aa5d95b0bdf9 Mon Sep 17 00:00:00 2001
From: Javi Fontan <jfontan@fdi.ucm.es>
Date: Tue, 26 Apr 2011 21:08:15 +0200
Subject: [PATCH 1/5] feature #575: Added error messages to vmm scripts

---
 src/vmm_mad/remotes/kvm/cancel   | 10 ++++++++++
 src/vmm_mad/remotes/kvm/deploy   |  2 ++
 src/vmm_mad/remotes/kvm/migrate  | 10 ++++++++++
 src/vmm_mad/remotes/kvm/restore  | 10 ++++++++++
 src/vmm_mad/remotes/kvm/save     | 10 ++++++++++
 src/vmm_mad/remotes/kvm/shutdown |  3 +++
 src/vmm_mad/remotes/xen/cancel   | 10 ++++++++++
 src/vmm_mad/remotes/xen/deploy   |  9 +++++++--
 src/vmm_mad/remotes/xen/migrate  | 10 ++++++++++
 src/vmm_mad/remotes/xen/restore  | 10 ++++++++++
 src/vmm_mad/remotes/xen/save     |  9 +++++++++
 src/vmm_mad/remotes/xen/shutdown | 12 +++++++++++-
 12 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/src/vmm_mad/remotes/kvm/cancel b/src/vmm_mad/remotes/kvm/cancel
index 11bbffe5db..3943889905 100755
--- a/src/vmm_mad/remotes/kvm/cancel
+++ b/src/vmm_mad/remotes/kvm/cancel
@@ -17,7 +17,17 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/kvmrc
+source $(dirname $0)/../../scripts_common.sh
 
 deploy_id=$1
 
 virsh --connect $LIBVIRT_URI destroy $deploy_id
+
+error_code=$?
+
+if [ "x$?" = "x0" ]; then
+    exit $error_code
+else
+    error_message "Could not destroy $deploy_id"
+    exit $error_code
+fi
diff --git a/src/vmm_mad/remotes/kvm/deploy b/src/vmm_mad/remotes/kvm/deploy
index fe611ce7d0..dd39ead402 100755
--- a/src/vmm_mad/remotes/kvm/deploy
+++ b/src/vmm_mad/remotes/kvm/deploy
@@ -17,6 +17,7 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/kvmrc
+source $(dirname $0)/../../scripts_common.sh
 
 domain=$1
 
@@ -28,5 +29,6 @@ data=`virsh --connect $LIBVIRT_URI create $domain`
 if [ "x$?" = "x0" ]; then
     echo $data | sed 's/Domain //' | sed 's/ created from .*$//'
 else
+    error_message "Could not create domain from $domain"
     exit -1
 fi
diff --git a/src/vmm_mad/remotes/kvm/migrate b/src/vmm_mad/remotes/kvm/migrate
index 1f95602bc4..6cc4c85428 100755
--- a/src/vmm_mad/remotes/kvm/migrate
+++ b/src/vmm_mad/remotes/kvm/migrate
@@ -17,8 +17,18 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/kvmrc
+source $(dirname $0)/../../scripts_common.sh
 
 deploy_id=$1
 dest_host=$2
 
 virsh --connect $LIBVIRT_URI migrate --live $deploy_id $QEMU_PROTOCOL://$dest_host/system
+
+error_code=$?
+
+if [ "x$?" = "x0" ]; then
+    exit $error_code
+else
+    error_message "Could not migrate $deploy_id to $dest_host"
+    exit $error_code
+fi
diff --git a/src/vmm_mad/remotes/kvm/restore b/src/vmm_mad/remotes/kvm/restore
index 8a83fc92b5..da64b18c10 100755
--- a/src/vmm_mad/remotes/kvm/restore
+++ b/src/vmm_mad/remotes/kvm/restore
@@ -17,7 +17,17 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/kvmrc
+source $(dirname $0)/../../scripts_common.sh
 
 file=$1
 
 virsh --connect $LIBVIRT_URI restore $file
+
+error_code=$?
+
+if [ "x$?" = "x0" ]; then
+    exit $error_code
+else
+    error_message "Could not restore from $file"
+    exit $error_code
+fi
diff --git a/src/vmm_mad/remotes/kvm/save b/src/vmm_mad/remotes/kvm/save
index b51735188f..39dc8fdf09 100755
--- a/src/vmm_mad/remotes/kvm/save
+++ b/src/vmm_mad/remotes/kvm/save
@@ -17,6 +17,7 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/kvmrc
+source $(dirname $0)/../../scripts_common.sh
 
 deploy_id=$1
 file=$2
@@ -27,3 +28,12 @@ if [ ! -f $file ]; then
 fi
 
 virsh --connect $LIBVIRT_URI save $deploy_id $file
+
+error_code=$?
+
+if [ "x$?" = "x0" ]; then
+    exit $error_code
+else
+    error_message "Could not save $deploy_id to $file"
+    exit $error_code
+fi
diff --git a/src/vmm_mad/remotes/kvm/shutdown b/src/vmm_mad/remotes/kvm/shutdown
index e7d4c8d7a4..bd2491ab2f 100755
--- a/src/vmm_mad/remotes/kvm/shutdown
+++ b/src/vmm_mad/remotes/kvm/shutdown
@@ -17,6 +17,7 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/kvmrc
+source $(dirname $0)/../../scripts_common.sh
 
 #------------------------------------------------------------------------------
 # Wait the VM to shutdown TIMEOUT (xPOLL_INTERVAL) seconds.
@@ -32,6 +33,7 @@ virsh --connect $LIBVIRT_URI shutdown $deploy_id
 exit_code=$?
 
 if [ "$exit_code" != "0" ]; then
+    error_message "Could not shutdown $deploy_id"
     exit $exit_code
 fi
 
@@ -41,6 +43,7 @@ do
 	sleep $POLL_INTERVAL
 	if [ "$count" -gt "$TIMEOUT" ]
 	then
+	    error_message "Timeout reached and VM $deploy_id is still alive"
 		echo "Timeout reached" >&2
 		exit 1
 	fi
diff --git a/src/vmm_mad/remotes/xen/cancel b/src/vmm_mad/remotes/xen/cancel
index b8c0a484c2..9f6928d5cc 100755
--- a/src/vmm_mad/remotes/xen/cancel
+++ b/src/vmm_mad/remotes/xen/cancel
@@ -17,7 +17,17 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/xenrc
+source $(dirname $0)/../../scripts_common.sh
 
 deploy_id=$1
 
 $XM_CANCEL $deploy_id
+
+error_code=$?
+
+if [ "x$?" = "x0" ]; then
+    exit $error_code
+else
+    error_message "Could not destroy $deploy_id"
+    exit $error_code
+fi
diff --git a/src/vmm_mad/remotes/xen/deploy b/src/vmm_mad/remotes/xen/deploy
index 99c771c6fe..b91569c1cc 100755
--- a/src/vmm_mad/remotes/xen/deploy
+++ b/src/vmm_mad/remotes/xen/deploy
@@ -17,10 +17,13 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/xenrc
+source $(dirname $0)/../../scripts_common.sh
 
 function error_exit() {
     exit_code=$1
+    message=$2
     if [ "x$exit_code" != "x0" ]; then
+        error_message $message
         exit $exit_code
     fi
 }
@@ -32,7 +35,7 @@ cat > $domain
 
 output=`$XM_CREATE $domain`
 
-error_exit $?
+error_exit $? "Unable to create domain"
 
 domain_name=`echo $output | grep 'Started domain' | sed 's/^.*Started domain //' | tr -d '\n'`
 
@@ -41,11 +44,13 @@ out=`grep -e '^\#O CPU_CREDITS =' < $domain`
 if [ "x$?" = "x0" ]; then
     credits=`echo $out | cut -d= -f2 | tr -d ' '`
     
+    log_debug "Credits set to $credits"
+    
     name=`grep -e '^name =' < $domain | cut -d= -f2 | tr -d ' ' | tr -d "\'"`
     
     $XM_CREDITS -d $name -w $credits
     
-    error_exit $?
+    error_exit $? "Unable to set VM credits"
 fi
 
 echo $domain_name
diff --git a/src/vmm_mad/remotes/xen/migrate b/src/vmm_mad/remotes/xen/migrate
index bd5c074799..1e1a915afe 100755
--- a/src/vmm_mad/remotes/xen/migrate
+++ b/src/vmm_mad/remotes/xen/migrate
@@ -17,8 +17,18 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/xenrc
+source $(dirname $0)/../../scripts_common.sh
 
 deploy_id=$1
 dest_host=$2
 
 $XM_MIGRATE $deploy_id $dest_host
+
+error_code=$?
+
+if [ "x$?" = "x0" ]; then
+    exit $error_code
+else
+    error_message "Could not migrate $deploy_id to $dest_host"
+    exit $error_code
+fi
diff --git a/src/vmm_mad/remotes/xen/restore b/src/vmm_mad/remotes/xen/restore
index c92cb1e1ec..c8d2480800 100755
--- a/src/vmm_mad/remotes/xen/restore
+++ b/src/vmm_mad/remotes/xen/restore
@@ -17,8 +17,18 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/xenrc
+source $(dirname $0)/../../scripts_common.sh
 
 file=$1
 
 $XM_RESTORE $file
 
+error_code=$?
+
+if [ "x$?" = "x0" ]; then
+    exit $error_code
+else
+    error_message "Could not restore from $file"
+    exit $error_code
+fi
+
diff --git a/src/vmm_mad/remotes/xen/save b/src/vmm_mad/remotes/xen/save
index fc653c569f..906f8c3965 100755
--- a/src/vmm_mad/remotes/xen/save
+++ b/src/vmm_mad/remotes/xen/save
@@ -17,9 +17,18 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/xenrc
+source $(dirname $0)/../../scripts_common.sh
 
 deploy_id=$1
 file=$2
 
 $XM_SAVE $deploy_id $file
 
+error_code=$?
+
+if [ "x$?" = "x0" ]; then
+    exit $error_code
+else
+    error_message "Could not save $deploy_id to $file"
+    exit $error_code
+fi
diff --git a/src/vmm_mad/remotes/xen/shutdown b/src/vmm_mad/remotes/xen/shutdown
index 9d3ca25367..4effaa375e 100755
--- a/src/vmm_mad/remotes/xen/shutdown
+++ b/src/vmm_mad/remotes/xen/shutdown
@@ -17,6 +17,7 @@
 #--------------------------------------------------------------------------- #
 
 source $(dirname $0)/xenrc
+source $(dirname $0)/../../scripts_common.sh
 
 deploy_id=$1
 
@@ -24,7 +25,16 @@ function gdm {
     $XM_LIST | grep "$deploy_id "
 }
 
-$XM_SHUTDOWN $deploy_id || exit -1
+$XM_SHUTDOWN $deploy_id
+
+error_code=$?
+
+if [ "x$?" = "x0" ]; then
+    exit $error_code
+else
+    error_message "Could not shutdown $deploy_id"
+    exit $error_code
+fi
 
 OUT=$(gdm)
 

From 5fa3006adfd5ee08f3c1c9304bd4402c0ea38a09 Mon Sep 17 00:00:00 2001
From: Javi Fontan <jfontan@fdi.ucm.es>
Date: Wed, 27 Apr 2011 12:02:23 +0200
Subject: [PATCH 2/5] feature #575: exec_and_log function accepts a user
 defined error message

---
 src/mad/sh/scripts_common.sh | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh
index 0e5a9781a6..455f83b529 100755
--- a/src/mad/sh/scripts_common.sh
+++ b/src/mad/sh/scripts_common.sh
@@ -83,20 +83,29 @@ function error_message
     ) 1>&2
 }
 
-# Executes a command, if it fails return error message and exits
+# Executes a command, if it fails returns error message and exits
+# If a second parameter is present it is used as the error message when
+# the command fails
 function exec_and_log
 {
+    message=$2
     output=`$1 2>&1 1>/dev/null`
     code=$?
     if [ "x$code" != "x0" ]; then
         log_error "Command \"$1\" failed."
         log_error "$output"
-        error_message "$output"
+        if [ -n "$message" ]; then
+            error_message "$output"
+        else
+            error_message "$message"
+        fi
         exit $code
     fi
     log "Executed \"$1\"."
 }
 
+
+
 # Like exec_and_log but the first argument is the number of seconds
 # before here is timeout and kills the command
 #

From f41f12f1904a833aa2d9f216748ddbe81c6c1ea3 Mon Sep 17 00:00:00 2001
From: Javi Fontan <jfontan@fdi.ucm.es>
Date: Wed, 27 Apr 2011 12:11:59 +0200
Subject: [PATCH 3/5] feature #575: changed vmm remotes to use exec_and_log

---
 src/vmm_mad/remotes/kvm/cancel   | 12 ++----------
 src/vmm_mad/remotes/kvm/migrate  | 12 ++----------
 src/vmm_mad/remotes/kvm/restore  | 12 ++----------
 src/vmm_mad/remotes/kvm/save     | 12 ++----------
 src/vmm_mad/remotes/xen/cancel   | 12 ++----------
 src/vmm_mad/remotes/xen/migrate  | 12 ++----------
 src/vmm_mad/remotes/xen/restore  | 12 ++----------
 src/vmm_mad/remotes/xen/save     | 12 ++----------
 src/vmm_mad/remotes/xen/shutdown | 12 ++----------
 9 files changed, 18 insertions(+), 90 deletions(-)

diff --git a/src/vmm_mad/remotes/kvm/cancel b/src/vmm_mad/remotes/kvm/cancel
index 3943889905..cbcdad3eb7 100755
--- a/src/vmm_mad/remotes/kvm/cancel
+++ b/src/vmm_mad/remotes/kvm/cancel
@@ -21,13 +21,5 @@ source $(dirname $0)/../../scripts_common.sh
 
 deploy_id=$1
 
-virsh --connect $LIBVIRT_URI destroy $deploy_id
-
-error_code=$?
-
-if [ "x$?" = "x0" ]; then
-    exit $error_code
-else
-    error_message "Could not destroy $deploy_id"
-    exit $error_code
-fi
+exec_and_log "virsh --connect $LIBVIRT_URI destroy $deploy_id" \
+    "Could not destroy $deploy_id"
diff --git a/src/vmm_mad/remotes/kvm/migrate b/src/vmm_mad/remotes/kvm/migrate
index 6cc4c85428..2dbdf8a521 100755
--- a/src/vmm_mad/remotes/kvm/migrate
+++ b/src/vmm_mad/remotes/kvm/migrate
@@ -22,13 +22,5 @@ source $(dirname $0)/../../scripts_common.sh
 deploy_id=$1
 dest_host=$2
 
-virsh --connect $LIBVIRT_URI migrate --live $deploy_id $QEMU_PROTOCOL://$dest_host/system
-
-error_code=$?
-
-if [ "x$?" = "x0" ]; then
-    exit $error_code
-else
-    error_message "Could not migrate $deploy_id to $dest_host"
-    exit $error_code
-fi
+exec_and_log "virsh --connect $LIBVIRT_URI migrate --live $deploy_id $QEMU_PROTOCOL://$dest_host/system" \
+    "Could not migrate $deploy_id to $dest_host"
diff --git a/src/vmm_mad/remotes/kvm/restore b/src/vmm_mad/remotes/kvm/restore
index da64b18c10..761a82227a 100755
--- a/src/vmm_mad/remotes/kvm/restore
+++ b/src/vmm_mad/remotes/kvm/restore
@@ -21,13 +21,5 @@ source $(dirname $0)/../../scripts_common.sh
 
 file=$1
 
-virsh --connect $LIBVIRT_URI restore $file
-
-error_code=$?
-
-if [ "x$?" = "x0" ]; then
-    exit $error_code
-else
-    error_message "Could not restore from $file"
-    exit $error_code
-fi
+exec_and_log "virsh --connect $LIBVIRT_URI restore $file" \
+    "Could not restore from $file"
diff --git a/src/vmm_mad/remotes/kvm/save b/src/vmm_mad/remotes/kvm/save
index 39dc8fdf09..4b09cf7fc4 100755
--- a/src/vmm_mad/remotes/kvm/save
+++ b/src/vmm_mad/remotes/kvm/save
@@ -27,13 +27,5 @@ if [ ! -f $file ]; then
     chmod 666 $file
 fi
 
-virsh --connect $LIBVIRT_URI save $deploy_id $file
-
-error_code=$?
-
-if [ "x$?" = "x0" ]; then
-    exit $error_code
-else
-    error_message "Could not save $deploy_id to $file"
-    exit $error_code
-fi
+exec_and_log "virsh --connect $LIBVIRT_URI save $deploy_id $file" \
+    "Could not save $deploy_id to $file"
diff --git a/src/vmm_mad/remotes/xen/cancel b/src/vmm_mad/remotes/xen/cancel
index 9f6928d5cc..4beab6b21c 100755
--- a/src/vmm_mad/remotes/xen/cancel
+++ b/src/vmm_mad/remotes/xen/cancel
@@ -21,13 +21,5 @@ source $(dirname $0)/../../scripts_common.sh
 
 deploy_id=$1
 
-$XM_CANCEL $deploy_id
-
-error_code=$?
-
-if [ "x$?" = "x0" ]; then
-    exit $error_code
-else
-    error_message "Could not destroy $deploy_id"
-    exit $error_code
-fi
+exec_and_log "$XM_CANCEL $deploy_id" \
+    "Could not destroy $deploy_id"
diff --git a/src/vmm_mad/remotes/xen/migrate b/src/vmm_mad/remotes/xen/migrate
index 1e1a915afe..6458d3b542 100755
--- a/src/vmm_mad/remotes/xen/migrate
+++ b/src/vmm_mad/remotes/xen/migrate
@@ -22,13 +22,5 @@ source $(dirname $0)/../../scripts_common.sh
 deploy_id=$1
 dest_host=$2
 
-$XM_MIGRATE $deploy_id $dest_host
-
-error_code=$?
-
-if [ "x$?" = "x0" ]; then
-    exit $error_code
-else
-    error_message "Could not migrate $deploy_id to $dest_host"
-    exit $error_code
-fi
+exec_and_log "$XM_MIGRATE $deploy_id $dest_host" \
+    "Could not migrate $deploy_id to $dest_host"
diff --git a/src/vmm_mad/remotes/xen/restore b/src/vmm_mad/remotes/xen/restore
index c8d2480800..aa4bc0402b 100755
--- a/src/vmm_mad/remotes/xen/restore
+++ b/src/vmm_mad/remotes/xen/restore
@@ -21,14 +21,6 @@ source $(dirname $0)/../../scripts_common.sh
 
 file=$1
 
-$XM_RESTORE $file
-
-error_code=$?
-
-if [ "x$?" = "x0" ]; then
-    exit $error_code
-else
-    error_message "Could not restore from $file"
-    exit $error_code
-fi
+exec_and_log "$XM_RESTORE $file" \
+    "Could not restore from $file"
 
diff --git a/src/vmm_mad/remotes/xen/save b/src/vmm_mad/remotes/xen/save
index 906f8c3965..7be9ce93cc 100755
--- a/src/vmm_mad/remotes/xen/save
+++ b/src/vmm_mad/remotes/xen/save
@@ -22,13 +22,5 @@ source $(dirname $0)/../../scripts_common.sh
 deploy_id=$1
 file=$2
 
-$XM_SAVE $deploy_id $file
-
-error_code=$?
-
-if [ "x$?" = "x0" ]; then
-    exit $error_code
-else
-    error_message "Could not save $deploy_id to $file"
-    exit $error_code
-fi
+exec_and_log "$XM_SAVE $deploy_id $file" \
+    "Could not save $deploy_id to $file"
diff --git a/src/vmm_mad/remotes/xen/shutdown b/src/vmm_mad/remotes/xen/shutdown
index 4effaa375e..d6b240672c 100755
--- a/src/vmm_mad/remotes/xen/shutdown
+++ b/src/vmm_mad/remotes/xen/shutdown
@@ -25,16 +25,8 @@ function gdm {
     $XM_LIST | grep "$deploy_id "
 }
 
-$XM_SHUTDOWN $deploy_id
-
-error_code=$?
-
-if [ "x$?" = "x0" ]; then
-    exit $error_code
-else
-    error_message "Could not shutdown $deploy_id"
-    exit $error_code
-fi
+exec_and_log "$XM_SHUTDOWN $deploy_id" \
+    "Could not shutdown $deploy_id"
 
 OUT=$(gdm)
 

From 0513a98094513fb7e6bfd99f2d661bd526a55aa3 Mon Sep 17 00:00:00 2001
From: Javi Fontan <jfontan@fdi.ucm.es>
Date: Wed, 27 Apr 2011 12:53:10 +0200
Subject: [PATCH 4/5] feature #575: added error messages to tm ssh and nfs

---
 src/tm_mad/nfs/tm_clone.sh   | 10 ++++++----
 src/tm_mad/nfs/tm_context.sh |  9 ++++++---
 src/tm_mad/nfs/tm_delete.sh  |  3 ++-
 src/tm_mad/nfs/tm_ln.sh      |  3 ++-
 src/tm_mad/nfs/tm_mkimage.sh |  9 ++++++---
 src/tm_mad/nfs/tm_mkswap.sh  | 12 +++++++-----
 src/tm_mad/nfs/tm_mv.sh      |  3 ++-
 src/tm_mad/ssh/tm_clone.sh   | 13 ++++++++-----
 src/tm_mad/ssh/tm_context.sh | 18 ++++++++++++------
 src/tm_mad/ssh/tm_delete.sh  |  3 ++-
 src/tm_mad/ssh/tm_mkimage.sh | 11 +++++++----
 src/tm_mad/ssh/tm_mkswap.sh  |  6 ++++--
 src/tm_mad/ssh/tm_mv.sh      |  6 ++++--
 13 files changed, 68 insertions(+), 38 deletions(-)

diff --git a/src/tm_mad/nfs/tm_clone.sh b/src/tm_mad/nfs/tm_clone.sh
index b54c826517..62c33fc2e8 100755
--- a/src/tm_mad/nfs/tm_clone.sh
+++ b/src/tm_mad/nfs/tm_clone.sh
@@ -34,8 +34,8 @@ DST_PATH=`arg_path $DST`
 
 fix_paths
 
-log "$1 $2"
-log "DST: $DST_PATH"
+log_debug "$1 $2"
+log_debug "DST: $DST_PATH"
 
 DST_DIR=`dirname $DST_PATH`
 
@@ -46,12 +46,14 @@ exec_and_log "chmod a+w $DST_DIR"
 case $SRC in
 http://*)
     log "Downloading $SRC"
-    exec_and_log "$WGET -O $DST_PATH $SRC"
+    exec_and_log "$WGET -O $DST_PATH $SRC" \
+        "Error downloading $SRC"
     ;;
 
 *)
     log "Cloning $SRC_PATH"
-    exec_and_log "cp -r $SRC_PATH $DST_PATH"
+    exec_and_log "cp -r $SRC_PATH $DST_PATH" \
+        "Error copying $SRC to $DST"
     ;;
 esac
 
diff --git a/src/tm_mad/nfs/tm_context.sh b/src/tm_mad/nfs/tm_context.sh
index b079622054..f211024f3d 100755
--- a/src/tm_mad/nfs/tm_context.sh
+++ b/src/tm_mad/nfs/tm_context.sh
@@ -48,16 +48,19 @@ exec_and_log "mkdir -p $ISO_DIR"
 for f in $SRC; do
     case $f in
     http://*)
-        exec_and_log "$WGET -O $ISO_DIR $f"
+        exec_and_log "$WGET -O $ISO_DIR $f" \
+            "Error downloading $f"
         ;;
 
     *)
-        exec_and_log "cp -R $f $ISO_DIR"
+        exec_and_log "cp -R $f $ISO_DIR" \
+            "Error copying $f to $ISO_DIR"
         ;;
     esac
 done
 
-exec_and_log "$MKISOFS -o $DST_PATH -J -R $ISO_DIR"
+exec_and_log "$MKISOFS -o $DST_PATH -J -R $ISO_DIR" \
+    "Error creating iso fs"
 
 exec_and_log "rm -rf $ISO_DIR"
 
diff --git a/src/tm_mad/nfs/tm_delete.sh b/src/tm_mad/nfs/tm_delete.sh
index cf1ff88742..942e0678cf 100755
--- a/src/tm_mad/nfs/tm_delete.sh
+++ b/src/tm_mad/nfs/tm_delete.sh
@@ -34,4 +34,5 @@ SRC_PATH=`arg_path $SRC`
 fix_src_path
 
 log "Deleting $SRC_PATH"
-exec_and_log "rm -rf $SRC_PATH"
+exec_and_log "rm -rf $SRC_PATH" \
+    "Error deleting $SRC_PATH"
diff --git a/src/tm_mad/nfs/tm_ln.sh b/src/tm_mad/nfs/tm_ln.sh
index 33b4a2a21c..1a3578e7b6 100755
--- a/src/tm_mad/nfs/tm_ln.sh
+++ b/src/tm_mad/nfs/tm_ln.sh
@@ -37,7 +37,8 @@ fix_dst_path
 DST_DIR=`dirname $DST_PATH`
 
 log "Creating directory $DST_DIR"
-exec_and_log "mkdir -p $DST_DIR"
+exec_and_log "mkdir -p $DST_DIR" \
+    "Could not create directory $DST_DIR"
 exec_and_log "chmod a+w $DST_DIR"
 
 log "Link $SRC_PATH"
diff --git a/src/tm_mad/nfs/tm_mkimage.sh b/src/tm_mad/nfs/tm_mkimage.sh
index ddafb405ec..b30c0ff327 100755
--- a/src/tm_mad/nfs/tm_mkimage.sh
+++ b/src/tm_mad/nfs/tm_mkimage.sh
@@ -36,8 +36,11 @@ fix_dst_path
 
 DST_DIR=`dirname $DST_PATH`
 
-exec_and_log "mkdir -p $DST_DIR"
-exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
-exec_and_log "$MKFS -t $FSTYPE -F $DST_PATH"
+exec_and_log "mkdir -p $DST_DIR" \
+    "Error creating directory $DST_DIR"
+exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
+    "Could not create image $DST_PATH"
+exec_and_log "$MKFS -t $FSTYPE -F $DST_PATH" \
+    "Unable to create filesystem $FSTYPE in $DST_PATH"
 exec_and_log "chmod a+rw $DST_PATH"
 
diff --git a/src/tm_mad/nfs/tm_mkswap.sh b/src/tm_mad/nfs/tm_mkswap.sh
index af78a59087..58b1e286fb 100755
--- a/src/tm_mad/nfs/tm_mkswap.sh
+++ b/src/tm_mad/nfs/tm_mkswap.sh
@@ -35,15 +35,17 @@ fix_dst_path
 
 DST_DIR=`dirname $DST_PATH`
 
-log "Creating directory $DST_DIR"
+log_debug "Creating directory $DST_DIR"
 exec_and_log "mkdir -p $DST_DIR"
 exec_and_log "chmod a+w $DST_DIR"
 
-log "Creating ${SIZE}Mb image in $DST_PATH"
-exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
+log_debug "Creating ${SIZE}Mb image in $DST_PATH"
+exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
+    "Could not create image file $DST_PATH"
 
-log "Initializing swap space"
-exec_and_log "$MKSWAP $DST_PATH"
+log_debug "Initializing swap space"
+exec_and_log "$MKSWAP $DST_PATH" \
+    "Could not create swap on $DST_PATH"
 
 exec_and_log "chmod a+w $DST_PATH"
 
diff --git a/src/tm_mad/nfs/tm_mv.sh b/src/tm_mad/nfs/tm_mv.sh
index 68902f969b..23483b6655 100755
--- a/src/tm_mad/nfs/tm_mv.sh
+++ b/src/tm_mad/nfs/tm_mv.sh
@@ -43,7 +43,8 @@ else
         log "Will not move, is not saving image"
     else
         log "Moving $SRC_PATH"
-        exec_and_log "mv $SRC_PATH $DST_PATH"
+        exec_and_log "mv $SRC_PATH $DST_PATH" \
+            "Could not move $SRC_PATH to $DST_PATH"
     fi
 fi
 
diff --git a/src/tm_mad/ssh/tm_clone.sh b/src/tm_mad/ssh/tm_clone.sh
index 8507c43e0a..71800d1874 100755
--- a/src/tm_mad/ssh/tm_clone.sh
+++ b/src/tm_mad/ssh/tm_clone.sh
@@ -34,23 +34,26 @@ SRC_HOST=`arg_host $SRC`
 DST_HOST=`arg_host $DST`
 
 
-log "$1 $2"
-log "DST: $DST_PATH"
+log_debug "$1 $2"
+log_debug "DST: $DST_PATH"
 
 DST_DIR=`dirname $DST_PATH`
 
 log "Creating directory $DST_DIR"
-exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
+exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \
+    "Error creating directory $DST_DIR"
 
 case $SRC in
 http://*)
     log "Downloading $SRC"
-    exec_and_log "$SSH $DST_HOST $WGET -O $DST_PATH $SRC"
+    exec_and_log "$SSH $DST_HOST $WGET -O $DST_PATH $SRC" \
+        "Error downloading $SRC"
     ;;
 
 *)
     log "Cloning $SRC"
-    exec_and_log "$SCP $SRC $DST"
+    exec_and_log "$SCP $SRC $DST" \
+        "Error copying $SRC to $DST"
     ;;
 esac
 
diff --git a/src/tm_mad/ssh/tm_context.sh b/src/tm_mad/ssh/tm_context.sh
index ee7fd40603..322ebdaf1b 100755
--- a/src/tm_mad/ssh/tm_context.sh
+++ b/src/tm_mad/ssh/tm_context.sh
@@ -47,21 +47,27 @@ fi
 ISO_DIR="$TMP_DIR/isofiles"
 
 
-exec_and_log "mkdir -p $ISO_DIR"
+exec_and_log "mkdir -p $ISO_DIR" \
+    "Error creating directory $ISO_DIR"
 
 for f in $SRC; do
     case $f in
     http://*)
-        exec_and_log "$WGET -O $ISO_DIR $f"
+        exec_and_log "$WGET -O $ISO_DIR $f" \
+            "Error downloading $f"
         ;;
 
     *)
-        exec_and_log "cp -R $f $ISO_DIR"
+        exec_and_log "cp -R $f $ISO_DIR" \
+            "Error copying $f to $ISO_DIR"
         ;;
     esac
 done
 
-exec_and_log "$MKISOFS -o $TMP_DIR/$DST_FILE -J -R $ISO_DIR"
-exec_and_log "$SCP $TMP_DIR/$DST_FILE $DST"
-exec_and_log "rm -rf $TMP_DIR"
+exec_and_log "$MKISOFS -o $TMP_DIR/$DST_FILE -J -R $ISO_DIR" \
+    "Error creating iso fs"
+exec_and_log "$SCP $TMP_DIR/$DST_FILE $DST" \
+    "Error copying $TMP_DIR/$DST_FILE to $DST"
+exec_and_log "rm -rf $TMP_DIR" \
+    "Error deleting $TMP_DIR"
 
diff --git a/src/tm_mad/ssh/tm_delete.sh b/src/tm_mad/ssh/tm_delete.sh
index f0c7205a43..0824634ebd 100755
--- a/src/tm_mad/ssh/tm_delete.sh
+++ b/src/tm_mad/ssh/tm_delete.sh
@@ -31,4 +31,5 @@ SRC_PATH=`arg_path $SRC`
 SRC_HOST=`arg_host $SRC`
 
 log "Deleting $SRC_PATH"
-exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"
+exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH" \
+    "Error deleting $SRC_PATH"
diff --git a/src/tm_mad/ssh/tm_mkimage.sh b/src/tm_mad/ssh/tm_mkimage.sh
index d092a8b9b2..81ff20f32c 100755
--- a/src/tm_mad/ssh/tm_mkimage.sh
+++ b/src/tm_mad/ssh/tm_mkimage.sh
@@ -32,7 +32,10 @@ DST_PATH=`arg_path $DST`
 DST_HOST=`arg_host $DST`
 DST_DIR=`dirname $DST_PATH`
 
-exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
-exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
-exec_and_log "$SSH $DST_HOST $MKFS -t $FSTYPE -F $DST_PATH"
-exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH"
+exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \
+    "Error creating directory $DST_DIR"
+exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
+    "Could not create image $DST_PATH"
+exec_and_log "$SSH $DST_HOST $MKFS -t $FSTYPE -F $DST_PATH" \
+    "Unable to create filesystem $FSTYPE in $DST_PATH"
+exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH"
\ No newline at end of file
diff --git a/src/tm_mad/ssh/tm_mkswap.sh b/src/tm_mad/ssh/tm_mkswap.sh
index 046a277bbc..60705134aa 100755
--- a/src/tm_mad/ssh/tm_mkswap.sh
+++ b/src/tm_mad/ssh/tm_mkswap.sh
@@ -34,10 +34,12 @@ DST_DIR=`dirname $DST_PATH`
 
 log "Creating ${SIZE}Mb image in $DST_PATH"
 exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
-exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
+exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
+    "Could not create image file $DST_PATH"
 
 log "Initializing swap space"
-exec_and_log "$SSH $DST_HOST $MKSWAP $DST_PATH"
+exec_and_log "$SSH $DST_HOST $MKSWAP $DST_PATH" \
+    "Could not create swap on $DST_PATH"
 
 exec_and_log "$SSH $DST_HOST chmod a+w $DST_PATH"
 
diff --git a/src/tm_mad/ssh/tm_mv.sh b/src/tm_mad/ssh/tm_mv.sh
index 6d3ff82065..3f10354e8b 100755
--- a/src/tm_mad/ssh/tm_mv.sh
+++ b/src/tm_mad/ssh/tm_mv.sh
@@ -36,6 +36,8 @@ DST_HOST=`arg_host $DST`
 DST_DIR=`dirname $DST_PATH`
 
 log "Moving $SRC_PATH"
-exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
-exec_and_log "$SCP -r $SRC $DST"
+exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \
+    "Unable to create directory $DST_DIR"
+exec_and_log "$SCP -r $SRC $DST" \
+    "Could not copy $SRC to $DST"
 exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"

From d27bc616b60e4c385cd9d5bbe9e37acd3c67489e Mon Sep 17 00:00:00 2001
From: Javi Fontan <jfontan@fdi.ucm.es>
Date: Wed, 27 Apr 2011 16:53:30 +0200
Subject: [PATCH 5/5] feature #575: added error messages to image mad scripts

---
 src/image_mad/remotes/fs/cp   | 6 ++++--
 src/image_mad/remotes/fs/mkfs | 6 ++++--
 src/image_mad/remotes/fs/mv   | 6 ++++--
 src/image_mad/remotes/fs/rm   | 3 ++-
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/image_mad/remotes/fs/cp b/src/image_mad/remotes/fs/cp
index 2ef4f8a2d8..78d3236276 100755
--- a/src/image_mad/remotes/fs/cp
+++ b/src/image_mad/remotes/fs/cp
@@ -39,12 +39,14 @@ DST=$2
 case $SRC in
 http://*)
     log "Downloading $SRC to the image repository"
-    exec_and_log "$WGET -O $DST $SRC"
+    exec_and_log "$WGET -O $DST $SRC" \
+        "Error downloading $SRC"
     ;;
 
 *)
     log "Copying local image $SRC to the image repository"
-    exec_and_log "cp -f $SRC $DST"
+    exec_and_log "cp -f $SRC $DST" \
+        "Error copying $SRC to $DST"
     ;;
 esac
 
diff --git a/src/image_mad/remotes/fs/mkfs b/src/image_mad/remotes/fs/mkfs
index e57fd2fce5..e6b1949366 100755
--- a/src/image_mad/remotes/fs/mkfs
+++ b/src/image_mad/remotes/fs/mkfs
@@ -37,6 +37,8 @@ DST=$1
 FSTYPE=$2
 SIZE=$3
 
-exec_and_log "$DD if=/dev/zero of=$DST bs=1 count=1 seek=${SIZE}M"
-exec_and_log "$MKFS -t $FSTYPE -F $DST"
+exec_and_log "$DD if=/dev/zero of=$DST bs=1 count=1 seek=${SIZE}M" \
+    "Could not create image $DST"
+exec_and_log "$MKFS -t $FSTYPE -F $DST" \
+    "Unable to create filesystem $FSTYPE in $DST"
 exec_and_log "chmod 0660 $DST"
diff --git a/src/image_mad/remotes/fs/mv b/src/image_mad/remotes/fs/mv
index a1e2eadd3f..74ee2f7199 100755
--- a/src/image_mad/remotes/fs/mv
+++ b/src/image_mad/remotes/fs/mv
@@ -39,12 +39,14 @@ DST=$2
 case $SRC in
 http://*)
     log "Downloading $SRC to the image repository"
-    exec_and_log "$WGET -O $DST $SRC"
+    exec_and_log "$WGET -O $DST $SRC" \
+        "Error downloading $SRC"
     ;;
 
 *)
     log "Moving local image $SRC to the image repository"
-    exec_and_log "mv -f $SRC $DST"
+    exec_and_log "mv -f $SRC $DST" \
+        "Could not move $SRC to $DST"
     ;;
 esac
 
diff --git a/src/image_mad/remotes/fs/rm b/src/image_mad/remotes/fs/rm
index 5526887226..72b66573d2 100755
--- a/src/image_mad/remotes/fs/rm
+++ b/src/image_mad/remotes/fs/rm
@@ -36,5 +36,6 @@ SRC=$1
 
 if [ -e $SRC ] ; then
     log "Removing $SRC from the image repository"
-    exec_and_log "rm $SRC"
+    exec_and_log "rm $SRC" \
+        "Error deleting $SRC"
 fi