Skip to content

Commit 616d9da

Browse files
committed
tests: check for services to be loaded before starting test
this commit introduces support for checking services to be loaded before start the tests. Signed-off-by: Matteo Bertrone <m.bertrone@gmail.com>
1 parent def7cb5 commit 616d9da

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

tests/run-tests-iptables.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
# use a clean instance of polycubed to run each test
44
RELAUNCH_POLYCUBED=true
55

6+
SERVICES_LOAD_TIMEOUT=10
7+
68
# launch polycubed in DEBUG mode
79
DEBUG=false
810

911
# result.json path
1012
RESULT_JSON="result.json"
1113

14+
declare -A services
15+
services[iptables]=pcn-iptables
16+
1217
# cleanup environment before exit
1318
function cleanup {
1419
set +e
@@ -93,6 +98,25 @@ function log_test {
9398
return $status
9499
}
95100

101+
# Check if services are loaded
102+
function services_are_loaded {
103+
echo "load_services:" > load_services
104+
count=0
105+
services_show=$(polycubectl services show)
106+
for i in "${!services[@]}"
107+
do
108+
lines=$(echo $services_show | grep $i | wc -l)
109+
if [ $lines -ne 0 ]
110+
then
111+
echo "$i YES" >> load_services
112+
else
113+
count=$((count + 1))
114+
echo "$i NO" >> load_services
115+
fi
116+
done
117+
echo $count
118+
}
119+
96120
# Check if polycubed rest server is responding
97121
function polycubed_is_responding {
98122
ret=$(polycubectl ? > /dev/null)
@@ -169,6 +193,28 @@ function launch_and_wait_polycubed_is_responding {
169193
break
170194
fi
171195
done
196+
197+
done=0
198+
i=0
199+
while : ; do
200+
sleep 1
201+
loaded=$(services_are_loaded)
202+
if [[ $loaded -eq 0 ]]; then
203+
done=1
204+
fi
205+
206+
i=$((i+1))
207+
if [ "$i" -eq $SERVICES_LOAD_TIMEOUT ]
208+
then
209+
echo "+ERROR+ timeout in checking services loaded $i seconds. try to run test anyway"
210+
cat load_services | grep NO
211+
break
212+
fi
213+
if [ "$done" -ne 0 ]; then
214+
echo "checking services loaded in $i seconds"
215+
break
216+
fi
217+
done
172218
}
173219

174220
# run test ($1:path)

tests/run-tests.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# use a clean instance of polycubed to run each test
44
RELAUNCH_POLYCUBED=true
55

6+
SERVICES_LOAD_TIMEOUT=10
7+
68
# launch polycubed in DEBUG mode
79
DEBUG=false
810

@@ -12,6 +14,18 @@ TEST_BRIDGE_STP=false
1214
# result.json path
1315
RESULT_JSON="result.json"
1416

17+
declare -A services
18+
services[ddosmitigator]=pcn-ddosmitigator
19+
services[firewall]=pcn-firewall
20+
services[helloworld]=pcn-helloworld
21+
services[lbdsr]=pcn-loadbalancer-dsr
22+
services[lbrp]=pcn-loadbalancer-rp
23+
services[nat]=pcn-nat
24+
services[pbforwarder]=pcn-pbforwarder
25+
services[router]=pcn-router
26+
services[simplebridge]=pcn-simplebridge
27+
services[transparenthelloworld]=pcn-transparent-helloworld
28+
1529
# cleanup environment before exit
1630
function cleanup {
1731
set +e
@@ -96,6 +110,25 @@ function log_test {
96110
return $status
97111
}
98112

113+
# Check if services are loaded
114+
function services_are_loaded {
115+
echo "load_services:" > load_services
116+
count=0
117+
services_show=$(polycubectl services show)
118+
for i in "${!services[@]}"
119+
do
120+
lines=$(echo $services_show | grep $i | wc -l)
121+
if [ $lines -ne 0 ]
122+
then
123+
echo "$i YES" >> load_services
124+
else
125+
count=$((count + 1))
126+
echo "$i NO" >> load_services
127+
fi
128+
done
129+
echo $count
130+
}
131+
99132
# Check if polycubed rest server is responding
100133
function polycubed_is_responding {
101134
ret=$(polycubectl ? > /dev/null)
@@ -172,6 +205,28 @@ function launch_and_wait_polycubed_is_responding {
172205
break
173206
fi
174207
done
208+
209+
done=0
210+
i=0
211+
while : ; do
212+
sleep 1
213+
loaded=$(services_are_loaded)
214+
if [[ $loaded -eq 0 ]]; then
215+
done=1
216+
fi
217+
218+
i=$((i+1))
219+
if [ "$i" -eq $SERVICES_LOAD_TIMEOUT ]
220+
then
221+
echo "+ERROR+ timeout in checking services loaded $i seconds. try to run test anyway"
222+
cat load_services | grep NO
223+
break
224+
fi
225+
if [ "$done" -ne 0 ]; then
226+
echo "checking services loaded in $i seconds"
227+
break
228+
fi
229+
done
175230
}
176231

177232
# run test ($1:path)

0 commit comments

Comments
 (0)