Statistics
| Branch: | Tag: | Revision:

root / snf-tools / conf / snf-burnin-run.sh @ 6d8fb26a

History | View | Annotate | Download (4.9 kB)

1
#!/bin/bash
2

    
3

    
4
# --------------------------------------------------------------------
5
# Configure script parameters
6

    
7
# ----------------------------------------
8
# Here we define the tokens for each user burnin will
9
# test along with an alias for each token.
10
# For each user define an ALIAS, his TOKEN, an IMAGEID and a FLAVOR.
11
USERS=(\
12
    "burnin1" "token to be used" \
13
    "image id to be used" "flavor id to be used" \
14

    
15
    "burnin2" "token to be used" \
16
    "image id to be used" "flavor id to be used" \
17

    
18
    "burnin3" "token to be used" \
19
    "image id to be used" "flavor id to be used" \
20
  )
21

    
22
# ----------------------------------------
23
# Here we define the email parameters
24
# Email Tag
25
TAG="[synnefo.org-burnin]"
26
# Email Recipients
27
RECIPIENTS="burnin@synnefo.org"
28
# Subject for a successful burnin run
29
# (will be "$TAG ($ALIAS) $SUCCESS_SUBJECT" for each burnin instance)
30
SUCCESS_SUBJECT="Burnin Succeeded"
31
# Subject for a failed burnin run
32
# (will be "$TAG ($ALIAS) $FAILURE_SUBJECT" for each burnin instance)
33
FAILURE_SUBJECT="Burnin Failed"
34

    
35
# ----------------------------------------
36
# Some burnin parameters
37
AUTH_URL="https://accounts.synnefo.org/identity/v2.0/"
38
SYSTEM_IMAGES_USER="uuid-of-owner-of-system-images"
39
TIMEOUT=240
40

    
41
# ----------------------------------------
42
# Burnin executable and log files
43
Burnin="snf-burnin"
44
# Log Folder will be $LOGFOLDER/$ALIAS for each burnin instance
45
LOGFOLDER="/var/log/burnin_results/"
46
# Output file will be $OUTPUTFOLDER/burnin-$ALIAS.out for each burnin instance
47
OUTPUTFOLDER="/tmp"
48
# Lock file (we don't want two instances of this script)
49
LOCKFILE="/tmp/burnin.lockfile"
50

    
51

    
52
# --------------------------------------------------------------------
53
# Script functions
54

    
55
run_burnin() {
56
    local alias="$1"
57
    local token="$2"
58
    local image="$3"
59
    local flavor="$4"
60
    local success_subject="$TAG ($alias) $SUCCESS_SUBJECT"
61
    local failure_subject="$TAG ($alias) $FAILURE_SUBJECT"
62
    local logfolder="$LOGFOLDER/$alias"
63
    local outputfile="$OUTPUTFOLDER/burnin-$alias.out"
64
    local failed=false
65
    local error_summary
66
    local stale_subject
67

    
68
    # Save date-stamp to output
69
    date > $outputfile
70
    echo -e \
71
        "\n\n===== Burnin Output ========================================" \
72
        >> $outputfile
73

    
74
    # Check for stale servers/networks
75
    $Burnin --token="$token" --auth-url="$AUTH_URL" --show-stale 2>&1 | \
76
        grep "test" >> $outputfile 2>&1
77
    if [ $? -ne 0 ]; then
78
        # No stale servers/networks found. Run burnin
79
        $Burnin --token="$token" \
80
                --action-timeout="$TIMEOUT" \
81
                --image-id="$image" \
82
                --log-folder="$logfolder" \
83
                --auth-url="$AUTH_URL" \
84
                --force-flavor="$flavor" \
85
                --system-images-user="$SYSTEM_IMAGES_USER" \
86
                --nofailfast \
87
            &>> $outputfile
88

    
89
        echo -e \
90
            "\n\n===== Burnin Logs ==========================================" \
91
            >> $outputfile
92

    
93
        # Search log files for errors
94
        for file in `ls -1d $logfolder/* | tail -1`/*/detail* ; do
95
            if egrep "(ERROR)|(FAILED)" $file > /dev/null; then
96
                failed=true
97
                echo "FILENAME: $file" >> $outputfile
98
                echo "ERROR: " >> $outputfile
99
                cat "$file" >> $outputfile
100
            fi
101
        done
102

    
103
        # Clean output file from escape characters
104
        sed -ri "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" $outputfile
105

    
106
        # Send emails
107
        if $failed; then
108
            error_summary="`cat $outputfile | \
109
                egrep "ERROR: test_|FAIL: test_" | \
110
                awk '{ print $2 }' | grep -v "^$" | \
111
                sed -e 's/_/ /g' | cut -d" " -f3- | \
112
                tr '\n' ',' | sed -e 's/,$//g' | \
113
                sed -e 's/,/,  /g'`"
114
            cat $outputfile | /usr/bin/mailx -E \
115
                -s "$failure_subject: $error_summary" $RECIPIENTS
116
#        else
117
#            cat $outputfile | /usr/bin/mailx -E \
118
#                -s "$success_subject" $RECIPIENTS
119
        fi
120
    else
121
        # Burnin found stale servers/networks. Try to clean them
122
        $Burnin --token="$token" --auth-url="$AUTH_URL" --delete-stale \
123
            >> $outputfile 2>&1
124
        if [ $? -ne 0 ]; then
125
            stale_subject="$failure_subject: Couldn't delete stale servers/networks"
126
        else
127
            stale_subject="$success_subject: Stale servers/networks deleted"
128
        fi
129

    
130
        # Clean output file from escape characters
131
        sed -ri "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" $outputfile
132

    
133
        # Send mail
134
        cat $outputfile | /usr/bin/mailx -E \
135
            -s "$stale_subject" $RECIPIENTS
136
    fi
137
}
138

    
139

    
140
# --------------------------------------------------------------------
141
# For each user run burnin function
142

    
143
(
144
    flock -xn 200 || exit 1
145

    
146
    set ${USERS[@]}
147

    
148
    while [ -n "$1" ]; do
149
        run_burnin "$1" "$2" "$3" "$4" &
150
        shift 4
151
    done
152

    
153
    wait
154
) 200>$LOCKFILE