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