blob: 0c5c32be695e6f67f37767e85a2521cda17b27e8 [file] [log] [blame]
cgeoffroy549e20f2017-03-03 16:10:40 +01001#!/bin/bash
2export DOCKER_HOST="unix:///var/run/docker.sock"
3
4set -e
5set -x
6
7W() {
cgeoffroy349dc0b2017-03-15 16:24:58 +01008 # Wait until a line appears in the screen session.
9 # It starts from the beginning of the log and exits after the first match.
10 local T=${2:-20s}
11 #timeout -k 3s ${T} stdbuf -o0 grep -q -m 1 "^${1}" <(tail -F -n+0 screenlog.0)
12 # (HACK) As Jenkins blocks subshell, we must use an intermediate script
13 local SUBF=$(mktemp)
14 chmod +x ${SUBF}
15 cat > ${SUBF} <<- EOF
16 #!/bin/bash -e
17 while true; do
18 if strings screenlog.0 | grep -m 1 "\${1}"; then
19 exit 0
20 fi
21 sleep 0.5s
22 done
23 EOF
24 timeout -k 3s ${T} ${SUBF} "${1}"
25 local RES=$?
26 rm -f ${SUBF}
27 return ${RES}
cgeoffroy549e20f2017-03-03 16:10:40 +010028}
29
30Cmd() {
31 # Send a command to the screen session, aka into the containernet prompt
32 screen -S sonemu -X stuff "${1}^M"
33}
34
35
36if ! screen --version | grep 'Screen version'; then
37 # Install screen and do an initial cleanup
38 sudo apt-get update -qq -y
39 sudo apt-get install -y screen
40 screen --version | grep 'Screen version'
41fi
cgeoffroyae307a92017-03-17 10:48:26 +010042if ! timeout --version; then
43 # Install coreutils for the timeout command
44 sudo apt-get update -qq -y
45 sudo apt-get install -y coreutils
46 timeout --version
47fi
cgeoffroy549e20f2017-03-03 16:10:40 +010048# Initial cleanup
cgeoffroy7511f6d2017-03-17 11:22:47 +010049pkill -f 'SCREEN -L -S sonemu' || true
cgeoffroy549e20f2017-03-03 16:10:40 +010050screen -wipe || true
51rm -f screenlog.0
52
53
54# Start containernet with a topology
cgeoffroy4b9ba682017-03-17 12:51:18 +010055screen -L -S sonemu -d -m sudo python src/emuvim/examples/simple_topology.py
cgeoffroy549e20f2017-03-03 16:10:40 +010056# Setup screen for immediate flusing
57screen -S sonemu -X logfile flush 0
58# Wait for the cli to start
cgeoffroy736c4aa2017-03-17 11:48:15 +010059W '^*** Starting CLI:' 60s
cgeoffroy549e20f2017-03-03 16:10:40 +010060# Print nodes
61Cmd 'nodes'
62# Start vnf1
63son-emu-cli compute start -d datacenter1 -n vnf1 && sleep 1s
64# Start vnf2
65son-emu-cli compute start -d datacenter1 -n vnf2 && sleep 1s
66# List compute nodes
67son-emu-cli compute list && sleep 1s
68# Gather some infos
69Cmd 'sh echo "... starting various checks"'
cgeoffroy6f86be72017-03-17 13:26:50 +010070sync # avoid text overlapping
cgeoffroy549e20f2017-03-03 16:10:40 +010071Cmd 'vnf1 ifconfig && echo "... checked vnf1"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010072W "^... checked vnf1"
cgeoffroy549e20f2017-03-03 16:10:40 +010073Cmd 'vnf2 ifconfig && echo "... checked vnf2"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010074W "^... checked vnf2"
cgeoffroy549e20f2017-03-03 16:10:40 +010075# Try to ping vnfs
cgeoffroy2530a1a2017-03-23 15:36:56 +010076Cmd 'vnf1 ping -c 2 vnf2 && echo "... checked ping"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010077W "^... checked ping" 20s
cgeoffroy549e20f2017-03-03 16:10:40 +010078Cmd 'quit'
79# Wait for sonemu to end
cgeoffroy349dc0b2017-03-15 16:24:58 +010080W '^*** Done'
cgeoffroy549e20f2017-03-03 16:10:40 +010081
cgeoffroy349dc0b2017-03-15 16:24:58 +010082echo -e '\n\n******************* Result ******************\n\n'
cgeoffroy549e20f2017-03-03 16:10:40 +010083strings screenlog.0
84echo -e '\n\n*********************************************\n\n'
85
86
87# Check the ping result
88if grep ', 2 received' screenlog.0; then
89 echo 'No problems detected'
90 exit 0
91else
92 echo 'Ping is broken !'
93 exit 1
94fi