Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | function show_help { |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 4 | 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 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 | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 42 | olt_config=0 |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 43 | |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 44 | while getopts "h?a:n:r:o:d:t:cC:kOb:" opt; do |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 45 | case "$opt" in |
| 46 | h|\?) |
| 47 | show_help |
| 48 | exit 1 |
| 49 | ;; |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 50 | O) |
| 51 | olt_config=1 |
| 52 | ;; |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 53 | 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 Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 65 | d) |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 66 | radius_cnt_image=$OPTARG |
| 67 | ;; |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 68 | a) |
| 69 | onos_app_file=$OPTARG |
| 70 | ;; |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 71 | 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 |
| 85 | done |
| 86 | |
| 87 | shift $(($OPTIND-1)) |
| 88 | |
| 89 | if [ $# -gt 0 ]; then |
| 90 | echo "Invalid args" |
| 91 | show_help |
| 92 | fi |
| 93 | |
| 94 | if [ $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 |
| 109 | fi |
| 110 | |
| 111 | if [ x"$onos_ip" = "x" ]; then |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 112 | ##First try fetching the existing ip for onos container |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 113 | onos_ip=$(cnt_ipaddr $onos_cnt_image) |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 114 | ##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 |
| 124 | fi |
| 125 | |
| 126 | if [ x"$onos_ip" = "x" ]; then |
| 127 | echo "ONOS not running or container name is invalid" |
| 128 | exit 127 |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 129 | fi |
| 130 | |
| 131 | if [ x"$radius_ip" = "x" ]; then |
| 132 | radius_ip=$(cnt_ipaddr $radius_cnt_image) |
| 133 | fi |
| 134 | |
| 135 | echo "Onos IP $onos_ip, Radius IP $radius_ip, Test type $test_type" |
| 136 | sed "s,%%CONTROLLER%%,$onos_ip,g" of-bridge-template.sh > $HOME/nose_exp/of-bridge.sh |
| 137 | |
| 138 | if [ 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 |
| 144 | fi |
Chetan Gaonker | 5e46d7e | 2016-03-21 13:50:24 -0700 | [diff] [blame] | 145 | |
| 146 | function 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 | |
| 153 | echo "Installing and activating onos app $onos_app_file" |
| 154 | |
| 155 | install_onos_app $onos_app_file |
| 156 | |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 157 | if [ $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}" |
| 162 | else |
| 163 | olt_env="OLT_CONFIG=" |
| 164 | echo -e "\nTest running on OVS" |
| 165 | fi |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 166 | echo "Starting test container $nose_cnt_image" |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 167 | 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 -e ${olt_env} $nose_cnt_image /bin/bash` |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 168 | echo "Setting up test container $test_cnt" |
| 169 | docker exec $test_cnt pip install monotonic |
| 170 | echo "Starting up the OVS switch on the test container $test_cnt" |
| 171 | docker exec $test_cnt /root/test/of-bridge.sh br0 |
| 172 | status=0 |
| 173 | while [ $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 |
| 178 | done |
Chetan Gaonker | 5fc0cc9 | 2016-03-15 16:39:50 -0700 | [diff] [blame] | 179 | sleep 5 |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 180 | |
| 181 | IFS='-' read -r -a tests <<<"${test_type}" |
| 182 | for 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 $?" |
| 201 | done |
| 202 | |
| 203 | echo "Done running tests." |
| 204 | |
| 205 | if [ $kill_test_cnt -eq 1 ]; then |
| 206 | echo "Killing test container $test_cnt" |
| 207 | docker kill $test_cnt |
| 208 | fi |
| 209 | |