Merge pull request #201 from cgeoffroy/pr/add_ci_tests
[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 local T=${2:-10s}
10 timeout -k 3s ${T} grep -q "^${1}" <(tail -f screenlog.0)
11 }
12
13 Cmd() {
14 # Send a command to the screen session, aka into the containernet prompt
15 screen -S sonemu -X stuff "${1}^M"
16 }
17
18
19 if ! screen --version | grep 'Screen version'; then
20 # Install screen and do an initial cleanup
21 sudo apt-get update -qq -y
22 sudo apt-get install -y screen
23 screen --version | grep 'Screen version'
24 fi
25 # Initial cleanup
26 pkill 'screen' || true
27 screen -wipe || true
28 rm -f screenlog.0
29
30
31 # Start containernet with a topology
32 screen -L -S sonemu -d -m python src/emuvim/examples/simple_topology.py
33 # Setup screen for immediate flusing
34 screen -S sonemu -X logfile flush 0
35 # Wait for the cli to start
36 W '*** Starting CLI:'
37 # Print nodes
38 Cmd 'nodes'
39 # Start vnf1
40 son-emu-cli compute start -d datacenter1 -n vnf1 && sleep 1s
41 # Start vnf2
42 son-emu-cli compute start -d datacenter1 -n vnf2 && sleep 1s
43 # List compute nodes
44 son-emu-cli compute list && sleep 1s
45 # Gather some infos
46 Cmd 'sh echo "... starting various checks"'
47 Cmd 'vnf1 ifconfig && echo "... checked vnf1"'
48 W "... checked vnf1"
49 Cmd 'vnf2 ifconfig && echo "... checked vnf2"'
50 W "... checked vnf2"
51 # Try to ping vnfs
52 Cmd 'vnf1 ping -c 2 vnf2 || echo "... checked ping"'
53 W "... checked ping" 20s
54 Cmd 'quit'
55 # Wait for sonemu to end
56 W '*** Done'
57
58 echo -e '\n\n************i****** Result ******************\n\n'
59 strings screenlog.0
60 echo -e '\n\n*********************************************\n\n'
61
62
63 # Check the ping result
64 if grep ', 2 received' screenlog.0; then
65 echo 'No problems detected'
66 exit 0
67 else
68 echo 'Ping is broken !'
69 exit 1
70 fi
71
72
73 # Cleanup
74 rm -f screenlog.0