Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | function 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 | |
| 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 | |
| 16 | test_type=dhcp |
| 17 | onos_cnt_image=onos:igmp-test |
| 18 | radius_cnt_image=radius-server:dev |
| 19 | onos_ip= |
| 20 | radius_ip= |
| 21 | OPTIND=1 |
| 22 | nose_cnt_image="onos:nosetest" |
| 23 | cleanup=0 |
| 24 | kill_test_cnt=0 |
| 25 | build_cnt_image= |
| 26 | cleanup_cnt_list= |
| 27 | |
| 28 | while 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 |
| 63 | done |
| 64 | |
| 65 | shift $(($OPTIND-1)) |
| 66 | |
| 67 | if [ $# -gt 0 ]; then |
| 68 | echo "Invalid args" |
| 69 | show_help |
| 70 | fi |
| 71 | |
| 72 | if [ $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 |
| 87 | fi |
| 88 | |
| 89 | if [ x"$onos_ip" = "x" ]; then |
| 90 | onos_ip=$(cnt_ipaddr $onos_cnt_image) |
| 91 | fi |
| 92 | |
| 93 | if [ x"$radius_ip" = "x" ]; then |
| 94 | radius_ip=$(cnt_ipaddr $radius_cnt_image) |
| 95 | fi |
| 96 | |
| 97 | echo "Onos IP $onos_ip, Radius IP $radius_ip, Test type $test_type" |
| 98 | sed "s,%%CONTROLLER%%,$onos_ip,g" of-bridge-template.sh > $HOME/nose_exp/of-bridge.sh |
| 99 | |
| 100 | if [ 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 |
| 106 | fi |
| 107 | echo "Starting test container $nose_cnt_image" |
| 108 | |
| 109 | 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` |
| 110 | echo "Setting up test container $test_cnt" |
| 111 | docker exec $test_cnt pip install monotonic |
| 112 | echo "Starting up the OVS switch on the test container $test_cnt" |
| 113 | docker exec $test_cnt /root/test/of-bridge.sh br0 |
| 114 | status=0 |
| 115 | while [ $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 |
| 120 | done |
Chetan Gaonker | 5fc0cc9 | 2016-03-15 16:39:50 -0700 | [diff] [blame] | 121 | sleep 5 |
Chetan Gaonker | c0566b5 | 2016-03-09 11:31:51 -0800 | [diff] [blame] | 122 | |
| 123 | IFS='-' read -r -a tests <<<"${test_type}" |
| 124 | for 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 $?" |
| 143 | done |
| 144 | |
| 145 | echo "Done running tests." |
| 146 | |
| 147 | if [ $kill_test_cnt -eq 1 ]; then |
| 148 | echo "Killing test container $test_cnt" |
| 149 | docker kill $test_cnt |
| 150 | fi |
| 151 | |