blob: 2d43e36d212f423e08a6053b8c83c7ec90d3cafb [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
cgeoffroy0412c622017-04-11 10:58:53 +020024 local RES=0
25 timeout -k 3s ${T} ${SUBF} "${1}" || RES=$?
cgeoffroy349dc0b2017-03-15 16:24:58 +010026 rm -f ${SUBF}
cgeoffroy0412c622017-04-11 10:58:53 +020027 if [ ! "$RES" = "0" ]; then
28 sync
cgeoffroy5ca7aae2017-04-11 11:20:23 +020029 echo -e "\n\n\n(Debug) Error while waiting for a pattern to appear in screenlog.0\n\n\n"
cgeoffroy0412c622017-04-11 10:58:53 +020030 strings screenlog.0
31 fi
cgeoffroy349dc0b2017-03-15 16:24:58 +010032 return ${RES}
cgeoffroy549e20f2017-03-03 16:10:40 +010033}
34
35Cmd() {
36 # Send a command to the screen session, aka into the containernet prompt
37 screen -S sonemu -X stuff "${1}^M"
38}
39
40
41if ! screen --version | grep 'Screen version'; then
42 # Install screen and do an initial cleanup
43 sudo apt-get update -qq -y
44 sudo apt-get install -y screen
45 screen --version | grep 'Screen version'
46fi
cgeoffroyae307a92017-03-17 10:48:26 +010047if ! timeout --version; then
48 # Install coreutils for the timeout command
49 sudo apt-get update -qq -y
50 sudo apt-get install -y coreutils
51 timeout --version
52fi
cgeoffroy549e20f2017-03-03 16:10:40 +010053# Initial cleanup
cgeoffroy7511f6d2017-03-17 11:22:47 +010054pkill -f 'SCREEN -L -S sonemu' || true
cgeoffroy549e20f2017-03-03 16:10:40 +010055screen -wipe || true
56rm -f screenlog.0
57
58
59# Start containernet with a topology
cgeoffroy4b9ba682017-03-17 12:51:18 +010060screen -L -S sonemu -d -m sudo python src/emuvim/examples/simple_topology.py
cgeoffroy549e20f2017-03-03 16:10:40 +010061# Setup screen for immediate flusing
62screen -S sonemu -X logfile flush 0
63# Wait for the cli to start
cgeoffroy736c4aa2017-03-17 11:48:15 +010064W '^*** Starting CLI:' 60s
cgeoffroy549e20f2017-03-03 16:10:40 +010065# Print nodes
66Cmd 'nodes'
67# Start vnf1
68son-emu-cli compute start -d datacenter1 -n vnf1 && sleep 1s
69# Start vnf2
70son-emu-cli compute start -d datacenter1 -n vnf2 && sleep 1s
71# List compute nodes
72son-emu-cli compute list && sleep 1s
cgeoffroy6f86be72017-03-17 13:26:50 +010073sync # avoid text overlapping
cgeoffroy1d6978b2017-04-11 11:05:56 +020074# Gather some infos
cgeoffroy75591cd2017-04-11 11:21:27 +020075Cmd 'sh sync'
76Cmd 'sh echo "... starting various checks"'
cgeoffroy1d6978b2017-04-11 11:05:56 +020077sync # avoid text overlapping
cgeoffroy014a10a2017-04-11 17:16:49 +020078Cmd 'vnf1 ifconfig && echo -e "\\n... checked vnf1"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010079W "^... checked vnf1"
cgeoffroy014a10a2017-04-11 17:16:49 +020080Cmd 'vnf2 ifconfig && echo -e "\\n... checked vnf2"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010081W "^... checked vnf2"
cgeoffroy549e20f2017-03-03 16:10:40 +010082# Try to ping vnfs
cgeoffroy014a10a2017-04-11 17:16:49 +020083Cmd 'vnf1 ping -c 2 vnf2 && echo -e "\\n... checked ping"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010084W "^... checked ping" 20s
cgeoffroy549e20f2017-03-03 16:10:40 +010085Cmd 'quit'
86# Wait for sonemu to end
cgeoffroy1d6978b2017-04-11 11:05:56 +020087W '*** Done'
cgeoffroy549e20f2017-03-03 16:10:40 +010088
cgeoffroy349dc0b2017-03-15 16:24:58 +010089echo -e '\n\n******************* Result ******************\n\n'
cgeoffroy549e20f2017-03-03 16:10:40 +010090strings screenlog.0
91echo -e '\n\n*********************************************\n\n'
92
93
94# Check the ping result
95if grep ', 2 received' screenlog.0; then
96 echo 'No problems detected'
97 exit 0
98else
99 echo 'Ping is broken !'
100 exit 1
101fi