blob: f1a50048a0c2dc1204f67a1c81027133be643c30 [file] [log] [blame]
Chetan Gaonkerc0566b52016-03-09 11:31:51 -08001#!/usr/bin/env bash
2
3function show_help {
Chetan Gaonker7997bb42016-03-28 09:46:15 -07004 echo "Usage: ${0#*/} -h | this help -n <onos_ip> -O | use olt config | -r <radius_ip> -o <onos cnt image> -a < onos app file> -d <radius cnt image> -t <test type> -c | cleanup test containers -C <cleanup container list> -k | kill the test container -b <test cnt image> | build test container docker image"
Chetan Gaonkerc0566b52016-03-09 11:31:51 -08005 exit 1
6}
7
8function cnt_ipaddr {
9 local image="${1}"
10 local cnt=`docker ps |grep "${image}" |awk '{print $1}'`
11 local ipaddr
12 ipaddr=`docker inspect -f '{{.NetworkSettings.IPAddress}}' $cnt`
13 echo $ipaddr
14}
15
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -070016function onos_start {
17 local image="${1}"
18 local port_str=""
19 for p in 8181 8101 9876 6653 6633; do
20 port_str="$port_str -p $p:$p/tcp"
21 done
Chetan Gaonkerfa3fb5f2016-03-23 15:03:24 -070022 ONOS_APPS="drivers,openflow,proxyarp,aaa,igmp"
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -070023 local cnt=`docker run -itd $port_str -e ONOS_APPS=${ONOS_APPS} $image /bin/bash`
24 local ipaddr
25 ipaddr=`docker inspect -f '{{.NetworkSettings.IPAddress}}' $cnt`
26 echo $ipaddr
27}
28
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080029test_type=dhcp
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -070030onos_cnt_image=onosproject/onos
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080031radius_cnt_image=radius-server:dev
32onos_ip=
33radius_ip=
34OPTIND=1
35nose_cnt_image="onos:nosetest"
36cleanup=0
37kill_test_cnt=0
38build_cnt_image=
39cleanup_cnt_list=
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -070040app_version=1.0-SNAPSHOT
41onos_app_file=$PWD/../apps/ciena-cordigmp-$app_version.oar
Chetan Gaonker7997bb42016-03-28 09:46:15 -070042olt_config=0
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080043
Chetan Gaonker7997bb42016-03-28 09:46:15 -070044while getopts "h?a:n:r:o:d:t:cC:kOb:" opt; do
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080045 case "$opt" in
46 h|\?)
47 show_help
48 exit 1
49 ;;
Chetan Gaonker7997bb42016-03-28 09:46:15 -070050 O)
51 olt_config=1
52 ;;
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080053 t)
54 test_type=$OPTARG
55 ;;
56 n)
57 onos_ip=$OPTARG
58 ;;
59 r)
60 radius_ip=$OPTARG
61 ;;
62 o)
63 onos_cnt_image=$OPTARG
64 ;;
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -070065 d)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080066 radius_cnt_image=$OPTARG
67 ;;
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -070068 a)
69 onos_app_file=$OPTARG
70 ;;
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080071 c)
72 cleanup=1
73 ;;
74 C)
75 cleanup=1
76 cleanup_cnt_list=$OPTARG
77 ;;
78 k)
79 kill_test_cnt=1
80 ;;
81 b)
82 build_cnt_image=$OPTARG
83 ;;
84 esac
85done
86
87shift $(($OPTIND-1))
88
89if [ $# -gt 0 ]; then
90 echo "Invalid args"
91 show_help
92fi
93
94if [ $cleanup -eq 1 ]; then
95 if [ x"$cleanup_cnt_list" != "x" ]; then
96 IFS='-' read -r -a cleanup_list <<<"${cleanup_cnt_list}"
97 for container in "${cleanup_list[@]}"; do
98 cnt_id=`docker ps | grep "${container}" | awk '{print $1}'`
99 echo "Killing container $cnt_id"
100 docker kill $cnt_id
101 done
102 exit 0
103 fi
104 for container in `docker ps | grep "${nose_cnt_image}" | awk '{print $1}'`; do
105 echo "Killing test container $container"
106 docker kill $container
107 done
108 exit 0
109fi
110
111if [ x"$onos_ip" = "x" ]; then
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -0700112 ##First try fetching the existing ip for onos container
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800113 onos_ip=$(cnt_ipaddr $onos_cnt_image)
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -0700114 ##If we find no onos running, then spawn the container if we can
115 if [ x"$onos_ip" = "x" ]; then
116 ##If the container image is from onosproject, we can try starting it
117 if [[ "$onos_cnt_image" =~ "onosproject/" ]]; then
118 echo "Starting ONOS container $onos_cnt_image"
119 onos_ip=$(onos_start $onos_cnt_image)
120 echo "Waiting 60 seconds for ONOS to fully boot up"
121 sleep 60
122 fi
123 fi
124fi
125
126if [ x"$onos_ip" = "x" ]; then
127 echo "ONOS not running or container name is invalid"
128 exit 127
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800129fi
130
131if [ x"$radius_ip" = "x" ]; then
132 radius_ip=$(cnt_ipaddr $radius_cnt_image)
133fi
134
135echo "Onos IP $onos_ip, Radius IP $radius_ip, Test type $test_type"
136sed "s,%%CONTROLLER%%,$onos_ip,g" of-bridge-template.sh > $HOME/nose_exp/of-bridge.sh
137
138if [ x"$build_cnt_image" != "x" ]; then
139 echo "Building test container docker image $build_cnt_image"
140 (cd test_docker && docker build -t $build_cnt_image . )
141 sleep 2
142 echo "Done building docker image $build_cnt_image"
143 nose_cnt_image=$build_cnt_image
144fi
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -0700145
146function install_onos_app {
147 local app=$1
148 local onos_url="http://$onos_ip:8181/onos/v1/applications"
149 local curl="curl -sS --user karaf:karaf"
150 $curl -X POST -HContent-Type:application/octet-stream $onos_url?activate=true --data-binary @$app
151}
152
153echo "Installing and activating onos app $onos_app_file"
154
155install_onos_app $onos_app_file
156
Chetan Gaonker7997bb42016-03-28 09:46:15 -0700157if [ $olt_config -eq 1 ]; then
158 olt_conf_loc="$PWD/olt_config.json"
159 olt_conf_test_loc="/root/test"${olt_conf_loc#$HOME\/nose_exp}
160 olt_env="OLT_CONFIG=$olt_conf_test_loc"
161 echo -e "\nTest running on OLT switch with olt env ${olt_env}"
162else
163 olt_env="OLT_CONFIG="
164 echo -e "\nTest running on OVS"
165fi
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800166echo "Starting test container $nose_cnt_image"
Chetan Gaonker7997bb42016-03-28 09:46:15 -0700167test_cnt=`docker run -itd --privileged -v $HOME/nose_exp:/root/test -v /lib/modules:/lib/modules -e ONOS_CONTROLLER_IP=$onos_ip -e ONOS_AAA_IP=$radius_ip -e ${olt_env} $nose_cnt_image /bin/bash`
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800168echo "Setting up test container $test_cnt"
169docker exec $test_cnt pip install monotonic
170echo "Starting up the OVS switch on the test container $test_cnt"
171docker exec $test_cnt /root/test/of-bridge.sh br0
172status=0
173while [ $status -ne 0 ]; do
174 echo "Waiting for the switch to get connected to controller"
175 docker exec $test_cnt ovs-ofctl dump-flows br0 | grep "type=0x8942"
176 status=$?
177 sleep 1
178done
Chetan Gaonker5fc0cc92016-03-15 16:39:50 -0700179sleep 5
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800180
181IFS='-' read -r -a tests <<<"${test_type}"
182for t in "${tests[@]}"; do
183 test_method="${t#*:}"
184 test="${t%%:*}"
185 case "$test" in
186 tls)
187 test_file="$test"AuthTest.py
188 ;;
189 *)
190 test_file="$test"Test.py
191 ;;
192 esac
193 if [ "$test_method" != "$t" ]; then
194 test_case="$test_file":"${test_method}"
195 else
196 test_case="$test_file"
197 fi
198 echo "Running test $test, test case $test_case"
199 docker exec $test_cnt nosetests -v /root/test/git/cord-tester/src/test/$test/"${test_case}"
200 echo "Test $t exited with status $?"
201done
202
203echo "Done running tests."
204
205if [ $kill_test_cnt -eq 1 ]; then
206 echo "Killing test container $test_cnt"
207 docker kill $test_cnt
208fi
209