blob: 027284de0d8149ac71fc7eb9138e8152e1a51b3f [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
cgeoffroy9d9b7792017-03-17 10:51:37 +010017 set -x
cgeoffroy349dc0b2017-03-15 16:24:58 +010018 while true; do
19 if strings screenlog.0 | grep -m 1 "\${1}"; then
20 exit 0
21 fi
22 sleep 0.5s
23 done
24 EOF
cgeoffroy9d9b7792017-03-17 10:51:37 +010025 cat ${SUBF}
cgeoffroy349dc0b2017-03-15 16:24:58 +010026 timeout -k 3s ${T} ${SUBF} "${1}"
27 local RES=$?
28 rm -f ${SUBF}
29 return ${RES}
cgeoffroy549e20f2017-03-03 16:10:40 +010030}
31
32Cmd() {
33 # Send a command to the screen session, aka into the containernet prompt
34 screen -S sonemu -X stuff "${1}^M"
35}
36
37
38if ! screen --version | grep 'Screen version'; then
39 # Install screen and do an initial cleanup
40 sudo apt-get update -qq -y
41 sudo apt-get install -y screen
42 screen --version | grep 'Screen version'
43fi
cgeoffroyae307a92017-03-17 10:48:26 +010044if ! timeout --version; then
45 # Install coreutils for the timeout command
46 sudo apt-get update -qq -y
47 sudo apt-get install -y coreutils
48 timeout --version
49fi
cgeoffroy549e20f2017-03-03 16:10:40 +010050# Initial cleanup
cgeoffroy7511f6d2017-03-17 11:22:47 +010051pkill -f 'SCREEN -L -S sonemu' || true
cgeoffroy549e20f2017-03-03 16:10:40 +010052screen -wipe || true
53rm -f screenlog.0
54
55
56# Start containernet with a topology
57screen -L -S sonemu -d -m python src/emuvim/examples/simple_topology.py
58# Setup screen for immediate flusing
59screen -S sonemu -X logfile flush 0
60# Wait for the cli to start
cgeoffroy736c4aa2017-03-17 11:48:15 +010061W '^*** Starting CLI:' 60s
cgeoffroy549e20f2017-03-03 16:10:40 +010062# Print nodes
63Cmd 'nodes'
64# Start vnf1
65son-emu-cli compute start -d datacenter1 -n vnf1 && sleep 1s
66# Start vnf2
67son-emu-cli compute start -d datacenter1 -n vnf2 && sleep 1s
68# List compute nodes
69son-emu-cli compute list && sleep 1s
70# Gather some infos
71Cmd 'sh echo "... starting various checks"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010072sync # avoid test overlapping
cgeoffroy549e20f2017-03-03 16:10:40 +010073Cmd 'vnf1 ifconfig && echo "... checked vnf1"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010074W "^... checked vnf1"
cgeoffroy549e20f2017-03-03 16:10:40 +010075Cmd 'vnf2 ifconfig && echo "... checked vnf2"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010076W "^... checked vnf2"
cgeoffroy549e20f2017-03-03 16:10:40 +010077# Try to ping vnfs
78Cmd 'vnf1 ping -c 2 vnf2 || echo "... checked ping"'
cgeoffroy349dc0b2017-03-15 16:24:58 +010079W "^... checked ping" 20s
cgeoffroy549e20f2017-03-03 16:10:40 +010080Cmd 'quit'
81# Wait for sonemu to end
cgeoffroy349dc0b2017-03-15 16:24:58 +010082W '^*** Done'
cgeoffroy549e20f2017-03-03 16:10:40 +010083
cgeoffroy349dc0b2017-03-15 16:24:58 +010084echo -e '\n\n******************* Result ******************\n\n'
cgeoffroy549e20f2017-03-03 16:10:40 +010085strings screenlog.0
86echo -e '\n\n*********************************************\n\n'
87
88
89# Check the ping result
90if grep ', 2 received' screenlog.0; then
91 echo 'No problems detected'
92 exit 0
93else
94 echo 'Ping is broken !'
95 exit 1
96fi