Revision ee083475

View differences:

src/tm_mad/common/context
38 38

  
39 39
. $TMCOMMON
40 40

  
41
function exec_and_set_error
42
{
43
    message=$2
44

  
45
    EXEC_LOG_ERR=`$1 2>&1 1>/dev/null`
46
    EXEC_LOG_RC=$?
47

  
48
    if [ $EXEC_LOG_RC -ne 0 ]; then
49
        log_error "Command \"$1\" failed: $EXEC_LOG_ERR"
50

  
51
        if [ -n "$2" ]; then
52
            export ERROR="$2"
53
        else
54
            export ERROR="Error executing $1: $EXEC_LOG_ERR"
55
        fi
56
    fi
57
}
58

  
59
function exit_error
60
{
61
    error_message "$ERROR"
62
    rm -rf $ISO_DIR > /dev/null 2>&1
63
    exit -1
64
}
65

  
66 41
#-------------------------------------------------------------------------------
67 42
# Set dst path and dirs
68 43
#-------------------------------------------------------------------------------
......
81 56
ISO_DIR="$DS_DIR/.isofiles/$VM_ID"
82 57
ISO_FILE="$ISO_DIR/$VM_ID.iso"
83 58

  
84
exec_and_set_error "mkdir -p $ISO_DIR" "Could not create tmp dir to make context dev"
85
[ -n "$ERROR" ] && exit_error
59
exec_and_log "mkdir -p $ISO_DIR" "Could not create tmp dir to make context dev"
86 60

  
87 61
for f in $SRC; do
88 62
    case $f in
89 63
    http://*)
90
        exec_and_set_error "$WGET -P $ISO_DIR $f" "Error downloading $f"
64
        exec_and_log "$WGET -P $ISO_DIR $f" "Error downloading $f"
91 65
        ;;
92 66
    *)
93
        exec_and_set_error "cp -R $f $ISO_DIR" "Error copying $f to $ISO_DIR"
67
        exec_and_log "cp -R $f $ISO_DIR" "Error copying $f to $ISO_DIR"
94 68
        ;;
95 69
    esac
96

  
97
    [ -n "$ERROR" ] && exit_error
98 70
done
99 71

  
100
exec_and_set_error "$MKISOFS -o $ISO_FILE -J -R $ISO_DIR" "Error creating iso fs"
101
[ -n "$ERROR" ] && exit_error
72
exec_and_log "$MKISOFS -o $ISO_FILE -J -R $ISO_DIR" "Error creating iso fs"
102 73

  
103
exec_and_set_error "$SCP $ISO_FILE $DST" "Error copying context ISO to $DST"
104
[ -n "$ERROR" ] && exit_error
74
exec_and_log "$SCP $ISO_FILE $DST" "Error copying context ISO to $DST"
105 75

  
106 76
# Creates symbolic link to add a .iso suffix, needed for VMware CDROMs
107 77
ssh_exec_and_log $DST_HOST "$LN -s $DST_PATH $DST_PATH.iso" "Error creating ISO symbolic link"

Also available in: Unified diff