root / snf-tools / conf / snf-burnin-run.sh @ f2e00c1f
History | View | Annotate | Download (3.5 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 |
"name:Image name (reg expr)" "name:Flavor name (reg expr)" |
14 |
|
15 |
"burnin2" "token to be used" |
16 |
"name:Image name (reg expr)" "name:Flavor name (reg expr)" |
17 |
|
18 |
"burnin3" "token to be used" |
19 |
"name:Image name (reg expr)" "name:Flavor name (reg expr)" |
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 |
|
39 |
# ---------------------------------------- |
40 |
# Burnin executable and log files |
41 |
Burnin="snf-burnin" |
42 |
# Log Folder will be $LOGFOLDER/$ALIAS for each burnin instance |
43 |
LOGFOLDER="/var/log/burnin/" |
44 |
# Lock file (we don't want two instances of this script) |
45 |
LOCKFILE="/tmp/burnin.lockfile" |
46 |
|
47 |
|
48 |
# -------------------------------------------------------------------- |
49 |
# Script functions |
50 |
|
51 |
run_burnin() { |
52 |
local alias="$1" |
53 |
local token="$2" |
54 |
local image="$3" |
55 |
local flavor="$4" |
56 |
local success_subject="$TAG ($alias) $SUCCESS_SUBJECT" |
57 |
local failure_subject="$TAG ($alias) $FAILURE_SUBJECT" |
58 |
local logfolder="$LOGFOLDER/$alias" |
59 |
local error_summary |
60 |
local stale_subject |
61 |
|
62 |
# Check for stale servers/networks |
63 |
$Burnin --token="$token" --auth-url="$AUTH_URL" --show-stale --quiet |
64 |
if [ $? -eq 0 ]; then |
65 |
# No stale servers/networks found. Run burnin |
66 |
results=$($Burnin \ |
67 |
--token="$token" \ |
68 |
--auth-url="$AUTH_URL" \ |
69 |
--images="$image" \ |
70 |
--flavors="$flavor" \ |
71 |
--log-folder="$logfolder" \ |
72 |
--final-report-only \ |
73 |
2>&1) |
74 |
|
75 |
if [ $? -ne 0 ]; then |
76 |
# Burnin failed |
77 |
# Send email |
78 |
error_summary=$(echo "$results" | \ |
79 |
sed -n 's/ \* Failed: \(.*\)/\1/p') |
80 |
echo "$results" | /usr/bin/mailx -E \ |
81 |
-s "$failure_subject: $error_summary" $RECIPIENTS |
82 |
# else |
83 |
# echo "$results" | /usr/bin/mailx -E \ |
84 |
# -s "$success_subject" $RECIPIENTS |
85 |
fi |
86 |
else |
87 |
# Burnin found stale servers/networks. Try to clean them |
88 |
results=$($Burnin --token="$token" --auth-url="$AUTH_URL" \ |
89 |
--delete-stale --log-folder="$logfolder" --final-report-only 2>&1) |
90 |
if [ $? -ne 0 ]; then |
91 |
stale_subject="$failure_subject: Couldn't delete stale servers/networks" |
92 |
else |
93 |
stale_subject="$success_subject: Stale servers/networks deleted" |
94 |
fi |
95 |
|
96 |
# Send mail |
97 |
echo "$results" | /usr/bin/mailx -E \ |
98 |
-s "$stale_subject" $RECIPIENTS |
99 |
fi |
100 |
} |
101 |
|
102 |
|
103 |
# -------------------------------------------------------------------- |
104 |
# For each user run burnin function |
105 |
|
106 |
( |
107 |
flock -xn 200 || exit 1 |
108 |
|
109 |
set "${USERS[@]}" |
110 |
|
111 |
while [ -n "$1" ]; do |
112 |
run_burnin "$1" "$2" "$3" "$4" & |
113 |
shift 4 |
114 |
done |
115 |
|
116 |
wait |
117 |
) 200>$LOCKFILE |