Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | function show_help { |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 4 | 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 Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 5 | exit 1 |
| 6 | } |
| 7 | |
| 8 | function 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 Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 16 | function 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 Gaonker | fa3fb5f | 2016-03-23 15:03:24 -0700 | [diff] [blame] | 22 | ONOS_APPS="drivers,openflow,proxyarp,aaa,igmp" |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 23 | 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 Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 29 | test_type=dhcp |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 30 | onos_cnt_image=onosproject/onos |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 31 | radius_cnt_image=radius-server:dev |
| 32 | onos_ip= |
| 33 | radius_ip= |
| 34 | OPTIND=1 |
| 35 | nose_cnt_image="onos:nosetest" |
| 36 | cleanup=0 |
| 37 | kill_test_cnt=0 |
| 38 | build_cnt_image= |
| 39 | cleanup_cnt_list= |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 40 | app_version=1.0-SNAPSHOT |
| 41 | onos_app_file=$PWD/../apps/ciena-cordigmp-$app_version.oar |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 42 | |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 43 | while getopts "h?a:n:r:o:d:t:cC:kb:" opt; do |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 44 | 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 Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 61 | d) |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 62 | radius_cnt_image=$OPTARG |
| 63 | ;; |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 64 | a) |
| 65 | onos_app_file=$OPTARG |
| 66 | ;; |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 67 | 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 |
| 81 | done |
| 82 | |
| 83 | shift $(($OPTIND-1)) |
| 84 | |
| 85 | if [ $# -gt 0 ]; then |
| 86 | echo "Invalid args" |
| 87 | show_help |
| 88 | fi |
| 89 | |
| 90 | if [ $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 |
| 105 | fi |
| 106 | |
| 107 | if [ x"$onos_ip" = "x" ]; then |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 108 | ##First try fetching the existing ip for onos container |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 109 | onos_ip=$(cnt_ipaddr $onos_cnt_image) |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 110 | ##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 |
| 120 | fi |
| 121 | |
| 122 | if [ x"$onos_ip" = "x" ]; then |
| 123 | echo "ONOS not running or container name is invalid" |
| 124 | exit 127 |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 125 | fi |
| 126 | |
| 127 | if [ x"$radius_ip" = "x" ]; then |
| 128 | radius_ip=$(cnt_ipaddr $radius_cnt_image) |
| 129 | fi |
| 130 | |
| 131 | echo "Onos IP $onos_ip, Radius IP $radius_ip, Test type $test_type" |
| 132 | sed "s,%%CONTROLLER%%,$onos_ip,g" of-bridge-template.sh > $HOME/nose_exp/of-bridge.sh |
| 133 | |
| 134 | if [ 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 |
| 140 | fi |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 141 | |
| 142 | function 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 | |
| 149 | echo "Installing and activating onos app $onos_app_file" |
| 150 | |
| 151 | install_onos_app $onos_app_file |
| 152 | |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 153 | echo "Starting test container $nose_cnt_image" |
| 154 | |
| 155 | test_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` |
| 156 | echo "Setting up test container $test_cnt" |
| 157 | docker exec $test_cnt pip install monotonic |
| 158 | echo "Starting up the OVS switch on the test container $test_cnt" |
| 159 | docker exec $test_cnt /root/test/of-bridge.sh br0 |
| 160 | status=0 |
| 161 | while [ $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 |
| 166 | done |
Chetan Gaonker | 5fc0cc9 | 2016-03-15 16:39:50 -0700 | [diff] [blame] | 167 | sleep 5 |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 168 | |
| 169 | IFS='-' read -r -a tests <<<"${test_type}" |
| 170 | for 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 $?" |
| 189 | done |
| 190 | |
| 191 | echo "Done running tests." |
| 192 | |
| 193 | if [ $kill_test_cnt -eq 1 ]; then |
| 194 | echo "Killing test container $test_cnt" |
| 195 | docker kill $test_cnt |
| 196 | fi |
| 197 | |