blob: be69d3f0e2b32a831f745b42ecd343af0d4e5187 [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
42# Initial cleanup
43pkill 'screen' || true
44screen -wipe || true
45rm -f screenlog.0
46
47
48# Start containernet with a topology
49screen -L -S sonemu -d -m python src/emuvim/examples/simple_topology.py
50# Setup screen for immediate flusing
51screen -S sonemu -X logfile flush 0
52# Wait for the cli to start
cgeoffroy349dc0b2017-03-15 16:24:58 +010053W '^*** Starting CLI:'
cgeoffroy549e20f2017-03-03 16:10:40 +010054# Print nodes
55Cmd 'nodes'
56# Start vnf1
57son-emu-cli compute start -d datacenter1 -n vnf1 && sleep 1s
58# Start vnf2
59son-emu-cli compute start -d datacenter1 -n vnf2 && sleep 1s
60# List compute nodes
61son-emu-cli compute list && sleep 1s
62# Gather some infos
63Cmd 'sh echo "... starting various checks"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010064sync # avoid test overlapping
cgeoffroy549e20f2017-03-03 16:10:40 +010065Cmd 'vnf1 ifconfig && echo "... checked vnf1"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010066W "^... checked vnf1"
cgeoffroy549e20f2017-03-03 16:10:40 +010067Cmd 'vnf2 ifconfig && echo "... checked vnf2"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010068W "^... checked vnf2"
cgeoffroy549e20f2017-03-03 16:10:40 +010069# Try to ping vnfs
70Cmd 'vnf1 ping -c 2 vnf2 || echo "... checked ping"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010071W "^... checked ping" 20s
cgeoffroy549e20f2017-03-03 16:10:40 +010072Cmd 'quit'
73# Wait for sonemu to end
cgeoffroy349dc0b2017-03-15 16:24:58 +010074W '^*** Done'
cgeoffroy549e20f2017-03-03 16:10:40 +010075
cgeoffroy349dc0b2017-03-15 16:24:58 +010076echo -e '\n\n******************* Result ******************\n\n'
cgeoffroy549e20f2017-03-03 16:10:40 +010077strings screenlog.0
78echo -e '\n\n*********************************************\n\n'
79
80
81# Check the ping result
82if grep ', 2 received' screenlog.0; then
83 echo 'No problems detected'
84 exit 0
85else
86 echo 'Ping is broken !'
87 exit 1
88fi