Stricter cleanup
[osm/vim-emu.git] / utils / ci / check_manual_usage_example.sh
1 #!/bin/bash
2 export DOCKER_HOST="unix:///var/run/docker.sock"
3
4 set -e
5 set -x
6
7 W() {
8 # 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 local RES=0
25 timeout -k 3s ${T} ${SUBF} "${1}" || RES=$?
26 rm -f ${SUBF}
27 if [ ! "$RES" = "0" ]; then
28 sync
29 echo -e "\n\n\n(Debug) Error while waiting for a pattern to appear in screenlog.0\n\n\n"
30 strings screenlog.0
31 fi
32 return ${RES}
33 }
34
35 Cmd() {
36 # Send a command to the screen session, aka into the containernet prompt
37 screen -S sonemu -X stuff "${1}^M"
38 }
39
40
41 if ! 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'
46 fi
47 if ! 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
52 fi
53 # Initial cleanup
54 pkill --signal KILL -f 'SCREEN -L -S sonemu' || true
55 sleep 1s
56 screen -wipe || true
57 rm -f screenlog.0
58
59
60 # Start containernet with a topology
61 screen -L -S sonemu -d -m sudo python src/emuvim/examples/simple_topology.py
62 # Setup screen for immediate flusing
63 screen -S sonemu -X logfile flush 0
64 # Wait for the cli to start
65 W '^*** Starting CLI:' 60s
66 # Print nodes
67 Cmd 'nodes'
68 # Start vnf1
69 son-emu-cli compute start -d datacenter1 -n vnf1 && sleep 1s
70 # Start vnf2
71 son-emu-cli compute start -d datacenter1 -n vnf2 && sleep 1s
72 # List compute nodes
73 son-emu-cli compute list && sleep 1s
74 sync # avoid text overlapping
75 # Gather some infos
76 Cmd 'sh sync'
77 Cmd 'sh echo "... starting various checks"'
78 sync # avoid text overlapping
79 Cmd 'vnf1 ifconfig && echo -e "\\n... checked vnf1"'
80 W "^... checked vnf1"
81 Cmd 'vnf2 ifconfig && echo -e "\\n... checked vnf2"'
82 W "^... checked vnf2"
83 # Try to ping vnfs
84 Cmd 'vnf1 ping -c 2 vnf2 && echo -e "\\n... checked ping"'
85 W "^... checked ping" 20s
86 Cmd 'quit'
87 # Wait for sonemu to end
88 W '*** Done'
89
90 echo -e '\n\n******************* Result ******************\n\n'
91 strings screenlog.0
92 echo -e '\n\n*********************************************\n\n'
93
94
95 # Check the ping result
96 if grep ', 2 received' screenlog.0; then
97 echo 'No problems detected'
98 exit 0
99 else
100 echo 'Ping is broken !'
101 exit 1
102 fi