forked from mozilla-services/socorro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rabbitmq-integration-test.sh
executable file
·226 lines (190 loc) · 6.08 KB
/
rabbitmq-integration-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
# integration test for Socorro, using rabbitmq
#
# bring up components, submit test crash, ensure that it shows up in
# reports tables.
#
# This uses the same setup as http://socorro.readthedocs.org/en/latest/installation.html
if [ "$#" != "1" ] || [ "$1" != "--destroy" ]
then
echo "WARNING - this script will destroy the local socorro install."
echo "The default database and config files will be overwritten."
echo "You must pass the --destroy flag to continue."
exit 1
fi
if [ -z "$DB_HOST" ]
then
DB_HOST="localhost"
fi
if [ -z "$DB_USER" ]
then
DB_USER="breakpad_rw"
fi
if [ -z "$DB_PASSWORD" ]
then
DB_PASSWORD="aPassword"
fi
if [ -z "$RABBITMQ_HOST" ]
then
RABBITMQ_HOST="localhost"
fi
if [ -z "$RABBITMQ_USERNAME" ]
then
RABBITMQ_USERNAME="guest"
fi
if [ -z "$RABBITMQ_PASSWORD" ]
then
RABBITMQ_PASSWORD="guest"
fi
if [ -z "$RABBITMQ_VHOST" ]
then
RABBITMQ_VHOST="/"
fi
function cleanup() {
echo "INFO: Purging rabbitmq queue"
python scripts/test_rabbitmq.py --test_rabbitmq.purge='socorro.normal' --test_rabbitmq.rabbitmq_host=$RABBITMQ_HOST --test_rabbitmq.rabbitmq_user=$RABBITMQ_USERNAME --test_rabbitmq.rabbitmq_password=$RABBITMQ_PASSWORD --test_rabbitmq.rabbitmq_vhost=$RABBITMQ_VHOST > /dev/null 2>&1
echo "INFO: cleaning up crash storage directories"
rm -rf ./primaryCrashStore/ ./processedCrashStore/
rm -rf ./crashes/
echo "INFO: Terminating background jobs"
for p in collector processor middleware
do
# destroy any running processes started by this shell
kill `jobs -p`
# destroy anything trying to write to the log files too
fuser -k ${p}.log > /dev/null 2>&1
done
return 0
}
trap 'cleanup' INT
function fatal() {
exit_code=$1
message=$2
echo "ERROR: $message"
cleanup
exit $exit_code
}
echo -n "INFO: setting up environment..."
make virtualenv > setup.log 2>&1
if [ $? != 0 ]
then
fatal 1 "could not set up virtualenv"
fi
. socorro-virtualenv/bin/activate >> setup.log 2>&1
if [ $? != 0 ]
then
fatal 1 "could activate virtualenv"
fi
export PYTHONPATH=.
echo " Done."
echo -n "INFO: setting up database..."
python socorro/external/postgresql/setupdb_app.py --database_username=$DB_USER --database_password=$DB_PASSWORD --database_name=breakpad --database_hostname=$DB_HOST --dropdb --force --fakedata --fakedata_days=1 > setupdb.log 2>&1
if [ $? != 0 ]
then
fatal 1 "setupdb_app.py failed, check setupdb.log"
fi
popd >> setupdb.log 2>&1
python socorro/cron/crontabber.py --database.database_host=$DB_HOST --database.database_user=$DB_USER --database.database_password=$DB_PASSWORD --job=weekly-reports-partitions --force >> setupdb.log 2>&1
if [ $? != 0 ]
then
fatal 1 "crontabber weekly-reports-partitions failed, check setupdb.log"
fi
echo " Done."
echo -n "INFO: configuring backend jobs..."
for p in rabbitmq-collector rabbitmq-processor rabbitmq-middleware
do
cp config/${p}.ini-dist config/${p}.ini
if [ $? != 0 ]
then
fatal 1 "copying default config for $p failed"
fi
# ensure no running processes
fuser -k ${p}.log > /dev/null 2>&1
done
echo " Done."
echo -n "INFO: starting up collector, processor and middleware..."
python socorro/collector/collector_app.py --admin.conf=./config/rabbitmq-collector.ini --storage.storage1.host=$RABBITMQ_HOST --storage.storage1.rabbitmq_user=$RABBITMQ_USERNAME --storage.storage1.rabbitmq_password=$RABBITMQ_PASSWORD --storage.storage1.virtual_host=$RABBITMQ_VHOST > collector.log 2>&1 &
python socorro/processor/processor_app.py --admin.conf=./config/rabbitmq-processor.ini --processor.database_host=$DB_HOST --new_crash_source.host=$RABBITMQ_HOST --new_crash_source.rabbitmq_user=$RABBITMQ_USERNAME --new_crash_source.rabbitmq_password=$RABBITMQ_PASSWORD --new_crash_source.virtual_host=$RABBITMQ_VHOST --destination.storage1.database_host=$DB_HOST --registrar.database_host=$DB_HOST > processor.log 2>&1 &
sleep 1
python socorro/middleware/middleware_app.py --admin.conf=./config/rabbitmq-middleware.ini --database.database_host=$DB_HOST --database.database_user=$DB_USER --database.database_password=$DB_PASSWORD > middleware.log 2>&1 &
echo " Done."
function retry() {
name=$1
search=$2
count=0
while true
do
grep "$search" ${name}.log > /dev/null
if [ $? != 0 ]
then
echo "INFO: waiting for $name..."
if [ $count == 30 ]
then
cat $name.log
fatal 1 "$name timeout"
fi
else
grep 'ERROR' ${name}.log
if [ $? != 1 ]
then
fatal 1 "errors found in $name.log"
fi
echo "INFO: $name test passed"
break
fi
sleep 5
count=$((count+1))
done
}
# wait for collector to startup
retry 'collector' 'running standalone at 127.0.0.1:8882'
echo -n 'INFO: submitting test crash...'
# submit test crash
python socorro/collector/submitter_app.py -u http://localhost:8882/submit -s testcrash/ -n 1 > submitter.log 2>&1
if [ $? != 0 ]
then
fatal 1 "submitter failed, check submitter.log"
fi
echo " Done."
CRASHID=`grep 'CrashID' submitter.log | awk -FCrashID=bp- '{print $2}'`
if [ -z "$CRASHID" ]
then
cat submitter.log
fatal 1 "no crash ID found in submitter log"
fi
echo "INFO: collector received crash ID: $CRASHID"
# make sure crashes are picked up, and no errors are logged
retry 'collector' "$CRASHID"
retry 'processor' "$CRASHID"
# check that mware has raw crash
curl -s -D middleware_headers.log "http://localhost:8883/crash_data/datatype/raw/uuid/${CRASHID}" > /dev/null
if [ $? != 0 ]
then
fatal 1 "curl call to middleware for raw crash failed"
fi
grep '200 OK' middleware_headers.log > /dev/null
if [ $? != 0 ]
then
fatal 1 "middleware test failed, no raw data for crash ID $CRASHID"
fi
# check that mware has processed crash in postgres
count=0
while true
do
curl -s "http://localhost:8883/crash/uuid/${CRASHID}" | grep '"total": 1' > /dev/null
if [ $? != 0 ]
then
echo "INFO: waiting for middleware..."
if [ $count == 30 ]
then
fatal 1 "middleware test failed, crash ID $CRASHID not found"
fi
else
break
fi
sleep 5
count=$((count+1))
done
# check that mware logs the request for the crash, and logs no errors
retry 'middleware' "$CRASHID"
cleanup