blob: a6b743ee810a1d6ddbce59be778dc4d22bf84409 [file] [log] [blame]
Chetan Gaonkerc0566b52016-03-09 11:31:51 -08001#!/usr/bin/env bash
2
3function show_help {
4 echo "Usage: ${0#*/} -h | this help -n <onos_ip> -r <radius_ip> -o <onos cnt image> -a <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"
5 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
16test_type=dhcp
17onos_cnt_image=onos:igmp-test
18radius_cnt_image=radius-server:dev
19onos_ip=
20radius_ip=
21OPTIND=1
22nose_cnt_image="onos:nosetest"
23cleanup=0
24kill_test_cnt=0
25build_cnt_image=
26cleanup_cnt_list=
27
28while getopts "h?n:r:o:a:t:cC:kb:" opt; do
29 case "$opt" in
30 h|\?)
31 show_help
32 exit 1
33 ;;
34 t)
35 test_type=$OPTARG
36 ;;
37 n)
38 onos_ip=$OPTARG
39 ;;
40 r)
41 radius_ip=$OPTARG
42 ;;
43 o)
44 onos_cnt_image=$OPTARG
45 ;;
46 a)
47 radius_cnt_image=$OPTARG
48 ;;
49 c)
50 cleanup=1
51 ;;
52 C)
53 cleanup=1
54 cleanup_cnt_list=$OPTARG
55 ;;
56 k)
57 kill_test_cnt=1
58 ;;
59 b)
60 build_cnt_image=$OPTARG
61 ;;
62 esac
63done
64
65shift $(($OPTIND-1))
66
67if [ $# -gt 0 ]; then
68 echo "Invalid args"
69 show_help
70fi
71
72if [ $cleanup -eq 1 ]; then
73 if [ x"$cleanup_cnt_list" != "x" ]; then
74 IFS='-' read -r -a cleanup_list <<<"${cleanup_cnt_list}"
75 for container in "${cleanup_list[@]}"; do
76 cnt_id=`docker ps | grep "${container}" | awk '{print $1}'`
77 echo "Killing container $cnt_id"
78 docker kill $cnt_id
79 done
80 exit 0
81 fi
82 for container in `docker ps | grep "${nose_cnt_image}" | awk '{print $1}'`; do
83 echo "Killing test container $container"
84 docker kill $container
85 done
86 exit 0
87fi
88
89if [ x"$onos_ip" = "x" ]; then
90 onos_ip=$(cnt_ipaddr $onos_cnt_image)
91fi
92
93if [ x"$radius_ip" = "x" ]; then
94 radius_ip=$(cnt_ipaddr $radius_cnt_image)
95fi
96
97echo "Onos IP $onos_ip, Radius IP $radius_ip, Test type $test_type"
98sed "s,%%CONTROLLER%%,$onos_ip,g" of-bridge-template.sh > $HOME/nose_exp/of-bridge.sh
99
100if [ x"$build_cnt_image" != "x" ]; then
101 echo "Building test container docker image $build_cnt_image"
102 (cd test_docker && docker build -t $build_cnt_image . )
103 sleep 2
104 echo "Done building docker image $build_cnt_image"
105 nose_cnt_image=$build_cnt_image
106fi
107echo "Starting test container $nose_cnt_image"
108
109test_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`
110echo "Setting up test container $test_cnt"
111docker exec $test_cnt pip install monotonic
112echo "Starting up the OVS switch on the test container $test_cnt"
113docker exec $test_cnt /root/test/of-bridge.sh br0
114status=0
115while [ $status -ne 0 ]; do
116 echo "Waiting for the switch to get connected to controller"
117 docker exec $test_cnt ovs-ofctl dump-flows br0 | grep "type=0x8942"
118 status=$?
119 sleep 1
120done
Chetan Gaonker5fc0cc92016-03-15 16:39:50 -0700121sleep 5
Chetan Gaonkerc0566b52016-03-09 11:31:51 -0800122
123IFS='-' read -r -a tests <<<"${test_type}"
124for t in "${tests[@]}"; do
125 test_method="${t#*:}"
126 test="${t%%:*}"
127 case "$test" in
128 tls)
129 test_file="$test"AuthTest.py
130 ;;
131 *)
132 test_file="$test"Test.py
133 ;;
134 esac
135 if [ "$test_method" != "$t" ]; then
136 test_case="$test_file":"${test_method}"
137 else
138 test_case="$test_file"
139 fi
140 echo "Running test $test, test case $test_case"
141 docker exec $test_cnt nosetests -v /root/test/git/cord-tester/src/test/$test/"${test_case}"
142 echo "Test $t exited with status $?"
143done
144
145echo "Done running tests."
146
147if [ $kill_test_cnt -eq 1 ]; then
148 echo "Killing test container $test_cnt"
149 docker kill $test_cnt
150fi
151