/
test.sh
executable file
·354 lines (320 loc) · 9.06 KB
/
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/bin/bash
OVERC=/opt/overc-system-agent/overc
OVERC_SERVER=/opt/overc-system-agent/run_server.py
SVR_PORT=12345
OVERC_DOM0=/etc/overc/container/dom0
# test url for send_image
url=http://openlinux.windriver.com/overc/images/genericx86-64/cube-desktop-genericx86-64.tar.bz2
count_snapshots() {
local container=$1
local found_snapshot=0
local snapshot_cnt=0
while read i; do
if [ $found_snapshot -eq 0 ]; then
if `echo $i | grep "List snapshots on container:" 1>/dev/null 2>&1`; then
found_snapshot=1
fi
else
if `echo $i | grep " -> " 1>/dev/null 2>&1`; then
snapshot_cnt=$(expr $snapshot_cnt + 1)
fi
fi
done < <($OVERC container list_snapshots $container dom0)
return $snapshot_cnt
}
test_container_status() {
local container=$1
local expected_status=$2
$OVERC_DOM0 -A -n $container
status=$?
if [ $status -ne $expected_status ]; then
echo "Error! $container container should be active"
echo "Expected value $expected_status, got $status"
exit 1
fi
}
# start up REST server
$OVERC_SERVER -p $SVR_PORT &
svr_pid=$!
echo "REST server started at pid: $svr_pid"
#################################################
# test status
# on bootup, dom0, dom1 and cube-desktop containers should be active
#################################################
test_container_status dom0 3
test_container_status dom1 3
test_container_status cube-desktop 3
test_container_status invalid_container 0
#################################################
# test start/stop
#################################################
echo "Test: Trying to start a container that's already active"
$OVERC container start cube-desktop dom0
status=$?
if [ $status -ne 1 ]; then
echo "Error! Starting an active container should fail"
echo "Expected value 1, got $status"
exit 1
else
echo "OK: failed"
fi
echo "Test: Trying to stop a container that's active"
$OVERC container stop cube-desktop dom0
status=$?
if [ $status -ne 0 ]; then
echo "Error! Stopping an active container should succeed"
echo "Expected value 0, got $status"
exit 1
else
echo "OK: succeeded"
fi
echo "Test: Trying to start a container that's inactive"
$OVERC container start cube-desktop dom0
status=$?
if [ $status -ne 0 ]; then
echo "Error! Starting an inactive container should succeed"
echo "Expected value 0, got $status"
exit 1
else
echo "OK: succeeded"
fi
#################################################
# update and sync testing
#################################################
echo "Test: Update image"
$OVERC container update dom0
status=$?
if [ $status -ne 0 ]; then
echo "Error! Failed to perform update on system images"
echo "Expected value 0, got $status"
exit 1
else
echo "OK: succeeded"
fi
echo "Test: send_image image on url $url"
$OVERC container send_image $url dom0
status=$?
if [ $status -ne 0 ]; then
echo "Error! Failed to perform send_image on system images"
echo "using url: $url"
echo "Expected value 0, got $status"
exit 1
else
echo "OK: succeeded"
fi
#################################################
# test activate rollback on cube-desktop
#################################################
echo "Test: Setting up file marker before activate/rollback test"
touch /essential/var/lib/lxc/cube-desktop/rootfs/root/test
count_snapshots cube-desktop
orig_num_snapshot=$?
echo "Test: activate container"
$OVERC container activate cube-desktop dom0 -f
status=$?
if [ $status -ne 0 ]; then
echo "Error! Failed to activate container"
echo "Expected value 0, got $status"
exit 1
else
echo "OK: succeeded"
fi
echo "Test: Looking for file marker after activate"
if [ -e /essential/var/lib/lxc/cube-desktop/rootfs/root/test ]; then
echo "Error! File /essential/var/lib/lxc/cube-desktop/rootfs/root/test should not exist!"
exit 1
else
echo "OK: file marker doesn't exist"
fi
echo "Test: counting snapshots after activate"
expected_num_snapshot=$(expr $orig_num_snapshot + 1)
count_snapshots cube-desktop
num_snapshot=$?
if [ $num_snapshot -ne $expected_num_snapshot ]; then
echo "Error! Number of snapshots should be $expected_num_snapshot [got $num_snapshot]"
exit 1
else
echo "OK: $num_snapshot snapshot"
fi
echo "Test: container should be active after active, stopping container"
$OVERC container stop cube-desktop dom0
status=$?
if [ $status -ne 0 ]; then
echo "Error! Stopping an active container should succeed"
echo "Expected value 0, got $status"
exit 1
else
echo "OK: succeeded"
fi
echo "Test: rollback container"
$OVERC container rollback cube-desktop dom0
status=$?
if [ $status -ne 0 ]; then
echo "Error! Failed to perform container rollback"
echo "Expected value 0, got $status"
exit 1
else
echo "OK: succeeded"
fi
echo "Test: counting snapshots after rollback"
count_snapshots cube-desktop
num_snapshot=$?
if [ $num_snapshot -ne $orig_num_snapshot ]; then
echo "Error! Number of snapshots should be $orig_num_snapshot [got $num_snapshot]"
exit 1
else
echo "OK: $num_snapshot snapshot"
fi
$OVERC container start cube-desktop dom0
status=$?
if [ $status -ne 0 ]; then
echo "Error! Starting an inactive container should succeed"
echo "Expected value 0, got $status"
exit 1
fi
echo "Test: Looking for file marker after rollback"
if [ ! -e /essential/var/lib/lxc/cube-desktop/rootfs/root/test ]; then
echo "Error! File /essential/var/lib/lxc/cube-desktop/rootfs/root/test should exist!"
exit 1
else
echo "OK: file marker found"
fi
rm /essential/var/lib/lxc/cube-desktop/rootfs/root/test
#
#################################################
# test operations on dom0
#################################################
echo "Test: Attempting to stop on container dom0"
$OVERC container stop dom0 dom0
status=$?
if [ $status -ne 1 ]; then
echo "Error! Stopping dom0 container should fail"
echo "Expected value 1, got $status"
exit 1
else
echo "OK: failed as expected"
fi
count_snapshots dom0
orig_num_snapshot=$?
echo "Test: Attempting to start on container dom0"
$OVERC container start dom0 dom0
status=$?
if [ $status -ne 1 ]; then
echo "Error! Starting dom0 container should fail"
echo "Expected value 1, got $status"
exit 1
else
echo "OK: failed as expected"
fi
echo "Test: Setting up file marker before activate/rollback test"
touch /root/test
echo "Test: activate container dom0"
$OVERC container activate dom0 dom0
status=$?
if [ $status -ne 0 ]; then
echo "Error! Failed to activate container"
echo "Expected value 0, got $status"
exit 1
else
echo "OK: succeeded"
fi
echo "Test: Looking for file marker after activate"
if [ ! -e /root/test ]; then
echo "Error! /root/test should exist"
exit 1
else
echo "OK: file marker persists on current running system"
fi
if [ -e /essential/var/lib/lxc/dom0/rootfs/root/test ]; then
echo "Error! /essential/var/lib/lxc/dom0/rootfs/root/test should not exist"
exit 1
else
echo "OK: file marker doesn't exist from /essential/var/lib/lxc/dom0/rootfs"
fi
echo "Test: counting snapshots after activate container dom0"
expected_num_snapshot=$(expr $orig_num_snapshot + 1)
count_snapshots dom0
num_snapshot=$?
if [ $num_snapshot -ne $expected_num_snapshot ]; then
echo "Error! Number of snapshots should be $expected_num_snapshot [got $num_snapshot]"
exit 1
else
echo "OK: $num_snapshot snapshot"
fi
echo "Test: rollback container dom0"
$OVERC container rollback dom0 dom0
status=$?
if [ $status -ne 0 ]; then
echo "Error! Failed to perform container rollback"
echo "Expected value 0, got $status"
exit 1
else
echo "OK: succeeded"
fi
echo "Test: Looking for file marker after rollback"
if [ ! -e /root/test ]; then
echo "Error! /root/test should exist"
exit 1
else
echo "OK: file marker persists on current running system"
fi
if [ ! -e /essential/var/lib/lxc/dom0/rootfs/root/test ]; then
echo "Error! /essential/var/lib/lxc/dom0/rootfs/root/test should exist"
exit 1
else
echo "OK: file marker exists from /essential/var/lib/lxc/dom0/rootfs"
fi
rm /root/test
echo "Test: counting snapshots after rollback container dom0"
count_snapshots dom0
num_snapshot=$?
if [ $num_snapshot -ne $orig_num_snapshot ]; then
echo "Error! Number of snapshots should be $orig_num_snapshot [got $num_snapshot]"
exit 1
else
echo "OK: $num_snapshot snapshot"
fi
#################################################
# test from REST
#################################################
echo "Test: Talking to REST server"
R=`printf "GET /container/list?template=dom0\r\n\r\n" | nc localhost $SVR_PORT`
if `echo $R|grep "List container" 1>/dev/null 2>&1`; then
echo "REST server: got container list"
else
echo "Error! Failed to list containers from REST server"
kill -9 $svr_pid
exit 1
fi
kill -9 $svr_pid
#################################################
# test packages updates
#################################################
echo "Test: updating package database"
$OVERC host update
status=$?
if [ $status -ne 0 ]; then
echo "Error! Failed to update package database"
exit 1
else
echo "OK: succeeded"
fi
echo "Test: upgrade newer"
$OVERC host newer
status=$?
if [ $status -ne 0 ]; then
echo "Error! Failed to check for new packages"
exit 1
else
echo "OK: succeeded"
fi
echo "Test: upgrade packages"
$OVERC host upgrade
status=$?
if [ $status -ne 0 ]; then
echo "Error! Failed to upgrade packages"
exit 1
else
echo "OK: succeeded"
fi
exit 0