Steve McIntyre | 4c2c601 | 2015-01-26 16:17:38 +0000 | [diff] [blame] | 1 | # |
| 2 | # test-common |
| 3 | # |
| 4 | # Common set of definitions and functions to help with driving VLANd |
| 5 | # in testing |
| 6 | |
Steve McIntyre | 4c2c601 | 2015-01-26 16:17:38 +0000 | [diff] [blame] | 7 | TOPDIR=$(dirname $0)/.. |
Steve McIntyre | a31981e | 2015-07-10 16:24:59 +0100 | [diff] [blame] | 8 | |
| 9 | # Default settings |
| 10 | if [ "$VERBOSE"x = ""x ] ; then |
| 11 | VERBOSE=0 |
| 12 | fi |
| 13 | if [ "$HOSTS"x = ""x ] ; then |
| 14 | HOSTS="panda01 panda02 panda03 arndale01 arndale02 arndale03 arndale04 imx5301 imx5302 imx5303" |
| 15 | fi |
| 16 | if [ "$SWITCHES"x = ""x ] ; then |
| 17 | SWITCHES="vlandswitch01 vlandswitch02 vlandswitch03 vlandswitch04 vlandswitch05" |
| 18 | fi |
| 19 | |
Steve McIntyre | 4c2c601 | 2015-01-26 16:17:38 +0000 | [diff] [blame] | 20 | |
Steve McIntyre | bbe4ae3 | 2015-02-12 08:57:28 +0000 | [diff] [blame] | 21 | # Topology definitions - how are the test machines connected? |
| 22 | panda01_SWITCH_PORT="vlandswitch01:Gi1/0/2" |
| 23 | panda02_SWITCH_PORT="vlandswitch02:fa25" |
| 24 | panda03_SWITCH_PORT="vlandswitch03:gi25" |
| 25 | arndale01_SWITCH_PORT="vlandswitch01:Gi1/0/3" |
| 26 | arndale02_SWITCH_PORT="vlandswitch02:fa2" |
| 27 | arndale03_SWITCH_PORT="vlandswitch03:gi2" |
Steve McIntyre | cda3ef9 | 2015-07-10 14:43:38 +0100 | [diff] [blame] | 28 | arndale04_SWITCH_PORT="vlandswitch04:Gi1/0/3" |
| 29 | imx5301_SWITCH_PORT="vlandswitch05:1/0/21" |
| 30 | imx5302_SWITCH_PORT="vlandswitch05:1/0/22" |
| 31 | imx5303_SWITCH_PORT="vlandswitch04:Gi1/0/2" |
Steve McIntyre | bbe4ae3 | 2015-02-12 08:57:28 +0000 | [diff] [blame] | 32 | |
Steve McIntyre | edf32d2 | 2015-07-17 15:19:03 +0100 | [diff] [blame] | 33 | # Function for output; write text to terminal and to our logfile, with |
| 34 | # timestamp for sorting. |
| 35 | log () { |
Steve McIntyre | 716519e | 2015-07-17 15:21:01 +0100 | [diff] [blame^] | 36 | DATE=$(date -u +%F/%H:%M:%S.%N) |
Steve McIntyre | edf32d2 | 2015-07-17 15:19:03 +0100 | [diff] [blame] | 37 | if [ "${LOGFILE}"x = ""x ] ; then |
| 38 | LOGFILE=$0.log |
| 39 | fi |
| 40 | echo "${DATE}: $@" >&2 # Use stderr so we don't confuse anybody |
| 41 | # reading our output |
| 42 | echo " ${DATE}: $@" >> ${LOGFILE} |
| 43 | } |
| 44 | |
Steve McIntyre | bbe4ae3 | 2015-02-12 08:57:28 +0000 | [diff] [blame] | 45 | vecho () { |
| 46 | if [ $VERBOSE -gt 0 ] ; then |
Steve McIntyre | edf32d2 | 2015-07-17 15:19:03 +0100 | [diff] [blame] | 47 | log "$@" |
Steve McIntyre | bbe4ae3 | 2015-02-12 08:57:28 +0000 | [diff] [blame] | 48 | fi |
| 49 | } |
Steve McIntyre | 4c2c601 | 2015-01-26 16:17:38 +0000 | [diff] [blame] | 50 | |
Steve McIntyre | edf32d2 | 2015-07-17 15:19:03 +0100 | [diff] [blame] | 51 | vvecho () { |
| 52 | if [ $VERBOSE -gt 1 ] ; then |
| 53 | log "$@" |
| 54 | fi |
| 55 | } |
| 56 | |
| 57 | # Run a vland admin command, and optionally log both the full text of |
| 58 | # the command and its output |
| 59 | run_admin_command () { |
| 60 | ADMIN="python $TOPDIR/admin.py" |
| 61 | vvecho "Running \"$ADMIN $@\"" |
| 62 | RESULT=$($ADMIN $@) |
| 63 | vvecho " Result is \"$RESULT\"" |
| 64 | echo $RESULT |
| 65 | } |
| 66 | |
Steve McIntyre | 4c2c601 | 2015-01-26 16:17:38 +0000 | [diff] [blame] | 67 | # Startup check |
Steve McIntyre | edf32d2 | 2015-07-17 15:19:03 +0100 | [diff] [blame] | 68 | run_admin_command --status |
Steve McIntyre | 4c2c601 | 2015-01-26 16:17:38 +0000 | [diff] [blame] | 69 | |
| 70 | # Preload some data - what are the switch IDs and port IDs of the |
| 71 | # various things in our test setup? |
Steve McIntyre | a31981e | 2015-07-10 16:24:59 +0100 | [diff] [blame] | 72 | for SWITCH in $SWITCHES; do |
Steve McIntyre | edf32d2 | 2015-07-17 15:19:03 +0100 | [diff] [blame] | 73 | export ${SWITCH}_ID=$(run_admin_command --lookup_switch_by_name $SWITCH) |
Steve McIntyre | a31981e | 2015-07-10 16:24:59 +0100 | [diff] [blame] | 74 | done |
Steve McIntyre | 4c2c601 | 2015-01-26 16:17:38 +0000 | [diff] [blame] | 75 | |
Steve McIntyre | bbe4ae3 | 2015-02-12 08:57:28 +0000 | [diff] [blame] | 76 | # Generate more detailed data for the hosts by asking VLANd what the |
| 77 | # IDs are for each port, etc. |
| 78 | for host in $HOSTS; do |
| 79 | SWITCH_PORT_VAR=${host}_SWITCH_PORT |
| 80 | SW=${!SWITCH_PORT_VAR%%:*} |
| 81 | SW_VAR=${SW}_ID |
| 82 | SW_ID=${!SW_VAR} |
Steve McIntyre | edf32d2 | 2015-07-17 15:19:03 +0100 | [diff] [blame] | 83 | PORT_NAME=${!SWITCH_PORT_VAR##*:} |
| 84 | PORT_ID=$(run_admin_command --lookup_port_by_switch_and_name $SW_ID $PORT_NAME) |
| 85 | export ${host}_PORT_ID=${PORT_ID} |
| 86 | CURRENT_VLAN_ID=$(run_admin_command --get_port_current_vlan $PORT_ID) |
| 87 | export ${host}_CURRENT_VLANID=$CURRENT_VLAN_ID |
| 88 | CURRENT_VLAN_TAG=$(run_admin_command --show_vlan_tag $CURRENT_VLAN_ID) |
Steve McIntyre | bbe4ae3 | 2015-02-12 08:57:28 +0000 | [diff] [blame] | 89 | export ${host}_CURRENT_VLAN_TAG=$CURRENT_VLAN_TAG |
| 90 | done |
| 91 | |
| 92 | verify_host_is_base () { |
| 93 | HOST=$1 |
| 94 | PORT_ID_VAR=${HOST}_PORT_ID |
| 95 | PORT_ID=${!PORT_ID_VAR} |
Steve McIntyre | edf32d2 | 2015-07-17 15:19:03 +0100 | [diff] [blame] | 96 | CURRENT_VLAN_ID=$(run_admin_command --get_port_current_vlan $PORT_ID) |
| 97 | CURRENT_VLAN_TAG=$(run_admin_command --show_vlan_tag $CURRENT_VLAN_ID) |
| 98 | BASE_VLAN_ID=$(run_admin_command --get_port_base_vlan $PORT_ID) |
| 99 | BASE_VLAN_TAG=$(run_admin_command --show_vlan_tag $BASE_VLAN_ID) |
Steve McIntyre | bbe4ae3 | 2015-02-12 08:57:28 +0000 | [diff] [blame] | 100 | vecho "$HOST" |
| 101 | vecho " is on port ID $PORT_ID" |
| 102 | vecho " which is on VLAN ID $CURRENT_VLAN_ID, tag $CURRENT_VLAN_TAG" |
| 103 | vecho " and should be on base VLAN ID $BASE_VLAN_ID, tag $BASE_VLAN_TAG" |
| 104 | if [ $CURRENT_VLAN_ID == $BASE_VLAN_ID ] ; then |
| 105 | return 0 |
| 106 | else |
| 107 | return 1 |
| 108 | fi |
| 109 | } |
| 110 | |
| 111 | verify_all_hosts_are_base () { |
| 112 | # Check that all the machines are correctly on their base VLANs |
| 113 | for host in $HOSTS; do |
| 114 | verify_host_is_base $host |
| 115 | if [ $? -ne 0 ] ; then |
| 116 | return 1 |
| 117 | fi |
| 118 | done |
| 119 | } |
| 120 | |
| 121 | all_hosts () { |
| 122 | COMMAND="$@" |
| 123 | for HOST in ${HOSTS}; do |
Steve McIntyre | edf32d2 | 2015-07-17 15:19:03 +0100 | [diff] [blame] | 124 | vvecho "Running on ${HOST}:: ${COMMAND}" |
Steve McIntyre | bbe4ae3 | 2015-02-12 08:57:28 +0000 | [diff] [blame] | 125 | ssh linaro@${HOST} "${COMMAND}" |
| 126 | done |
| 127 | } |
| 128 | |
| 129 | start_logging () { |
Steve McIntyre | e284894 | 2015-07-10 16:51:27 +0100 | [diff] [blame] | 130 | all_hosts "echo HOSTS=\\\"$HOSTS\\\" > test-config" |
Steve McIntyre | bbe4ae3 | 2015-02-12 08:57:28 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | stop_logging () { |
Steve McIntyre | a31981e | 2015-07-10 16:24:59 +0100 | [diff] [blame] | 134 | all_hosts "rm -f test-config" |
Steve McIntyre | bbe4ae3 | 2015-02-12 08:57:28 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | grab_logs () { |
| 138 | all_hosts "cat /tmp/ping-log*" |
| 139 | } |
| 140 | |
| 141 | clear_logs () { |
| 142 | all_hosts "rm -f /tmp/ping-log*" |
| 143 | } |