blob: c1f3aab115f0cbd63b030e7283ef0b0c7fb005a1 [file] [log] [blame]
You Wang782ff332017-02-21 17:13:04 -08001#!/bin/bash
2# This script automates DELTA tests (All-In-One Single Machine mode). It
3# installs DELTA and all dependencies; brings up VMs and configures the
4# network; triggers tests using a python script (run-DELTA.py); cleans
5# up the environment after tests are done.
6# Note: run-DELTA.py and this script should be put in the same folder
7
8set -e
9
10DELTA_PATH=/home/sdn
11
12# Install DELTA and dependencies
13function init_delta() {
14 echo "*** Initialize DELTA ***"
15 if [ ! -d "$DELTA_DIR" ]
16 then
17 echo "Downloading DELTA..."
18 (cd $DELTA_PATH && git clone https://github.com/OpenNetworkingFoundation/DELTA.git)
19 cd $DELTA_DIR
20 echo "Installing DELTA dependencies..."
21 ./tools/dev/delta-setup/delta-setup-devenv-ubuntu
22 echo "Building DELTA..."
23 source ./tools/dev/delta-setup/bash_profile
24 mvn clean install
25 echo "Installing virtualbox and vagrant..."
26 ./tools/dev/delta-setup/delta-setup-vms-ubuntu
27 # TODO: change ./tools/config/manager.cfg
28 cd -
29 fi
30}
31
32# Bring up VMs and config network
33function setup_vm() {
34 echo "*** Setting up VMs ***"
35 echo "Bringing up VMs..."
36 cd $DELTA_DIR"/tools/dev/vagrant/"
37 vagrant up >/dev/null 2>&1
38 echo "Checking if all VMs are up..."
39 vagrant status | grep controller | grep running
40 vagrant status | grep channel | grep running
41 vagrant status | grep mininet | grep running
42 echo "Setting up NAT network..."
43 VBoxManage natnetwork add --netname NatNetwork --network 10.0.2.0/24 --enable --dhcp on
44 VBoxManage controlvm $(VBoxManage list vms | grep mininet | awk '{print $1}' | sed 's/"//g') nic1 natnetwork NatNetwork
45 VBoxManage controlvm $(VBoxManage list vms | grep mininet | awk '{print $1}' | sed 's/"//g') nicpromisc1 allow-all
46 source ../delta-setup/bash_profile
47 if [[ $INIT_VM -eq 1 ]]
48 then
49 INIT_VM=0
50 echo "Setting up passwordless login..."
51 for vm in $DELTA_APP $DELTA_CHANNEL $DELTA_HOST
52 do
53 IFS=@ read name ip <<< $vm
54 ssh-keygen -f "$HOME/.ssh/known_hosts" -R $ip
55 cat ~/.ssh/id_rsa.pub | sshpass -p "vagrant" ssh -o StrictHostKeyChecking=no $vm 'cat >> .ssh/authorized_keys'
56 done
57 echo "Setting up DELTA_APP VM..."
58 ssh $DELTA_APP "sudo echo 'export JAVA_HOME=/usr/lib/jvm/java-8-oracle' | sudo tee --append /etc/environment;\
59 sudo echo 'export ONOS_APPS=drivers,openflow,proxyarp,mobility,fwd' | sudo tee --append /etc/environment"
60 echo "Copying files to VMs..."
61 ../onos-setup/onos-1.6.0-scp
62 ../delta-setup/delta-agents-scp
63 fi
64 echo "Setting up ONOS..."
65 ssh $DELTA_APP "echo 'Downloading ONOS nightly build...';\
66 set -e;\
67 wget -c http://downloads.onosproject.org/nightly/$NIGHTLY_FILE_NAME.tar.gz >/dev/null 2>&1;\
68 tar xzf $NIGHTLY_FILE_NAME.tar.gz;\
69 rm $NIGHTLY_FILE_NAME.tar.gz;\
70 if [ -d onos ]; then rm -r onos; fi;\
71 mv onos-*-SNAPSHOT onos;\
72 cp delta-agent-app-onos-1.6-1.0-SNAPSHOT.jar onos/apache-karaf-*/deploy/"
73 cd -
74}
75
76# Run DELTA tests
77function run_test() {
78 echo "*** Run tests ***"
79 cd $DELTA_DIR
80 source ./tools/dev/delta-setup/bash_profile
81 cd -
82 ./run-DELTA.py $DELTA_DIR
83}
84
85# Clean up
86function teardown_vm() {
87 echo "*** Tearing down VMs ***"
88 echo "Killing DELTA..."
89 sudo kill -9 $(ps -ef | grep delta-manager | grep -v grep | awk '{print $2}')
90 echo "Deleting NAT network..."
91 VBoxManage controlvm $(VBoxManage list vms | grep mininet | awk '{print $1}' | sed 's/"//g') nic1 nat || echo "nic1 of mininet VM not reset"
92 VBoxManage natnetwork remove --netname NatNetwork || echo "NAT network not removed"
93 echo "Bringing down VMs..."
94 cd $DELTA_DIR"/tools/dev/vagrant/"
95 if [[ $INIT_VM -eq 1 ]]
96 then
97 vagrant destroy -f
98 echo "Checking if all VMs are gone..."
99 vagrant status | grep controller | grep "not created"
100 vagrant status | grep channel | grep "not created"
101 vagrant status | grep mininet | grep "not created"
102 else
103 vagrant halt
104 echo "Checking if all VMs are down..."
105 vagrant status | grep controller | grep poweroff
106 vagrant status | grep channel | grep poweroff
107 vagrant status | grep mininet | grep poweroff
108 fi
109 cd -
110}
111
112INIT_DELTA=0
113INIT_VM=0
114NIGHTLY_FILE_NAME="onos-1.10.0.20170223-NIGHTLY"
115
116while getopts "hdvo:p:" opt; do
117 case ${opt} in
118 h )
119 echo "Usage:"
120 echo "-h show this help message"
121 echo "-d initialize DELTA repo, build and configure DELTA"
122 echo "-v destroy and reinstall vagrant VMs"
123 echo "-o <name> specify name of ONOS nightly build file"
124 echo "-p <path> specify path of DELTA"
125 exit 0
126 ;;
127 d ) INIT_DELTA=1
128 ;;
129 v ) INIT_VM=1
130 ;;
131 o ) NIGHTLY_FILE_NAME=$OPTARG
132 ;;
133 p ) DELTA_PATH=$OPTARG
134 ;;
135 \? ) echo "Invalid option: -$OPTARG"
136 exit 1
137 ;;
138 esac
139done
140
141DELTA_DIR=$DELTA_PATH"/DELTA"
142
143teardown_vm
144
145if [[ $INIT_DELTA -eq 1 ]]
146then
147 init_delta
148fi
149
150setup_vm
151
152run_test
153
154teardown_vm
155
156echo "Done"
157exit 0