blob: 5448a35cc96099022dcb4a8312bf5531c6683c22 [file] [log] [blame]
Chetan Gaonkerc0566b52016-03-09 11:31:51 -08001#!/usr/bin/env bash
2
3function show_help {
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -07004 echo "Usage: ${0#*/} -h | this help -n <onos_ip> -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 Gaonkerc0566b52016-03-09 11:31:51 -080042
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -070043while getopts "h?a:n:r:o:d:t:cC:kb:" opt; do
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080044 case "$opt" in
45 h|\?)
46 show_help
47 exit 1
48 ;;
49 t)
50 test_type=$OPTARG
51 ;;
52 n)
53 onos_ip=$OPTARG
54 ;;
55 r)
56 radius_ip=$OPTARG
57 ;;
58 o)
59 onos_cnt_image=$OPTARG
60 ;;
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -070061 d)
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080062 radius_cnt_image=$OPTARG
63 ;;
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -070064 a)
65 onos_app_file=$OPTARG
66 ;;
Chetan Gaonkerc0566b52016-03-09 11:31:51 -080067 c)
68 cleanup=1
69 ;;
70 C)
71 cleanup=1
72 cleanup_cnt_list=$OPTARG
73 ;;
74 k)
75 kill_test_cnt=1
76 ;;
77 b)
78 build_cnt_image=$OPTARG
79 ;;
80 esac
81done
82
83shift $(($OPTIND-1))
84
85if [ $# -gt 0 ]; then
86 echo "Invalid args"
87 show_help
88fi
89
90if [ $cleanup -eq 1 ]; then
91 if [ x"$cleanup_cnt_list" != "x" ]; then
92 IFS='-' read -r -a cleanup_list <<<"${cleanup_cnt_list}"
93 for container in "${cleanup_list[@]}"; do
94 cnt_id=`docker ps | grep "${container}" | awk '{print $1}'`
95 echo "Killing container $cnt_id"
96 docker kill $cnt_id
97 done
98 exit 0
99 fi
100 for container in `docker ps | grep "${nose_cnt_image}" | awk '{print $1}'`; do
101 echo "Killing test container $container"
102 docker kill $container
103 done
104 exit 0
105fi
106
107if [ x"$onos_ip" = "x" ]; then
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -0700108 ##First try fetching the existing ip for onos container
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800109 onos_ip=$(cnt_ipaddr $onos_cnt_image)
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -0700110 ##If we find no onos running, then spawn the container if we can
111 if [ x"$onos_ip" = "x" ]; then
112 ##If the container image is from onosproject, we can try starting it
113 if [[ "$onos_cnt_image" =~ "onosproject/" ]]; then
114 echo "Starting ONOS container $onos_cnt_image"
115 onos_ip=$(onos_start $onos_cnt_image)
116 echo "Waiting 60 seconds for ONOS to fully boot up"
117 sleep 60
118 fi
119 fi
120fi
121
122if [ x"$onos_ip" = "x" ]; then
123 echo "ONOS not running or container name is invalid"
124 exit 127
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800125fi
126
127if [ x"$radius_ip" = "x" ]; then
128 radius_ip=$(cnt_ipaddr $radius_cnt_image)
129fi
130
131echo "Onos IP $onos_ip, Radius IP $radius_ip, Test type $test_type"
132sed "s,%%CONTROLLER%%,$onos_ip,g" of-bridge-template.sh > $HOME/nose_exp/of-bridge.sh
133
134if [ x"$build_cnt_image" != "x" ]; then
135 echo "Building test container docker image $build_cnt_image"
136 (cd test_docker && docker build -t $build_cnt_image . )
137 sleep 2
138 echo "Done building docker image $build_cnt_image"
139 nose_cnt_image=$build_cnt_image
140fi
Chetan Gaonker5e46d7e2016-03-21 13:50:24 -0700141
142function install_onos_app {
143 local app=$1
144 local onos_url="http://$onos_ip:8181/onos/v1/applications"
145 local curl="curl -sS --user karaf:karaf"
146 $curl -X POST -HContent-Type:application/octet-stream $onos_url?activate=true --data-binary @$app
147}
148
149echo "Installing and activating onos app $onos_app_file"
150
151install_onos_app $onos_app_file
152
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800153echo "Starting test container $nose_cnt_image"
154
155test_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 $nose_cnt_image /bin/bash`
156echo "Setting up test container $test_cnt"
157docker exec $test_cnt pip install monotonic
158echo "Starting up the OVS switch on the test container $test_cnt"
159docker exec $test_cnt /root/test/of-bridge.sh br0
160status=0
161while [ $status -ne 0 ]; do
162 echo "Waiting for the switch to get connected to controller"
163 docker exec $test_cnt ovs-ofctl dump-flows br0 | grep "type=0x8942"
164 status=$?
165 sleep 1
166done
Chetan Gaonker5fc0cc92016-03-15 16:39:50 -0700167sleep 5
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800168
169IFS='-' read -r -a tests <<<"${test_type}"
170for t in "${tests[@]}"; do
171 test_method="${t#*:}"
172 test="${t%%:*}"
173 case "$test" in
174 tls)
175 test_file="$test"AuthTest.py
176 ;;
177 *)
178 test_file="$test"Test.py
179 ;;
180 esac
181 if [ "$test_method" != "$t" ]; then
182 test_case="$test_file":"${test_method}"
183 else
184 test_case="$test_file"
185 fi
186 echo "Running test $test, test case $test_case"
187 docker exec $test_cnt nosetests -v /root/test/git/cord-tester/src/test/$test/"${test_case}"
188 echo "Test $t exited with status $?"
189done
190
191echo "Done running tests."
192
193if [ $kill_test_cnt -eq 1 ]; then
194 echo "Killing test container $test_cnt"
195 docker kill $test_cnt
196fi
197