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