blob: 0510678d7e6047a89430e7302ecf8212a4b7816e [file] [log] [blame]
Steve McIntyre4c2c6012015-01-26 16:17:38 +00001#
2# test-common
3#
4# Common set of definitions and functions to help with driving VLANd
5# in testing
6
Steve McIntyre4c2c6012015-01-26 16:17:38 +00007TOPDIR=$(dirname $0)/..
Steve McIntyrea31981e2015-07-10 16:24:59 +01008
9# Default settings
10if [ "$VERBOSE"x = ""x ] ; then
11 VERBOSE=0
12fi
13if [ "$HOSTS"x = ""x ] ; then
14 HOSTS="panda01 panda02 panda03 arndale01 arndale02 arndale03 arndale04 imx5301 imx5302 imx5303"
15fi
16if [ "$SWITCHES"x = ""x ] ; then
17 SWITCHES="vlandswitch01 vlandswitch02 vlandswitch03 vlandswitch04 vlandswitch05"
18fi
19
Steve McIntyre4c2c6012015-01-26 16:17:38 +000020
Steve McIntyrebbe4ae32015-02-12 08:57:28 +000021# Topology definitions - how are the test machines connected?
22panda01_SWITCH_PORT="vlandswitch01:Gi1/0/2"
23panda02_SWITCH_PORT="vlandswitch02:fa25"
24panda03_SWITCH_PORT="vlandswitch03:gi25"
25arndale01_SWITCH_PORT="vlandswitch01:Gi1/0/3"
26arndale02_SWITCH_PORT="vlandswitch02:fa2"
27arndale03_SWITCH_PORT="vlandswitch03:gi2"
Steve McIntyrecda3ef92015-07-10 14:43:38 +010028arndale04_SWITCH_PORT="vlandswitch04:Gi1/0/3"
29imx5301_SWITCH_PORT="vlandswitch05:1/0/21"
30imx5302_SWITCH_PORT="vlandswitch05:1/0/22"
31imx5303_SWITCH_PORT="vlandswitch04:Gi1/0/2"
Steve McIntyrebbe4ae32015-02-12 08:57:28 +000032
Steve McIntyreedf32d22015-07-17 15:19:03 +010033# Function for output; write text to terminal and to our logfile, with
34# timestamp for sorting.
35log () {
Steve McIntyre716519e2015-07-17 15:21:01 +010036 DATE=$(date -u +%F/%H:%M:%S.%N)
Steve McIntyreedf32d22015-07-17 15:19:03 +010037 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 McIntyrebbe4ae32015-02-12 08:57:28 +000045vecho () {
46 if [ $VERBOSE -gt 0 ] ; then
Steve McIntyreedf32d22015-07-17 15:19:03 +010047 log "$@"
Steve McIntyrebbe4ae32015-02-12 08:57:28 +000048 fi
49}
Steve McIntyre4c2c6012015-01-26 16:17:38 +000050
Steve McIntyreedf32d22015-07-17 15:19:03 +010051vvecho () {
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
59run_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 McIntyre4c2c6012015-01-26 16:17:38 +000067# Startup check
Steve McIntyreedf32d22015-07-17 15:19:03 +010068run_admin_command --status
Steve McIntyre4c2c6012015-01-26 16:17:38 +000069
70# Preload some data - what are the switch IDs and port IDs of the
71# various things in our test setup?
Steve McIntyrea31981e2015-07-10 16:24:59 +010072for SWITCH in $SWITCHES; do
Steve McIntyreedf32d22015-07-17 15:19:03 +010073 export ${SWITCH}_ID=$(run_admin_command --lookup_switch_by_name $SWITCH)
Steve McIntyrea31981e2015-07-10 16:24:59 +010074done
Steve McIntyre4c2c6012015-01-26 16:17:38 +000075
Steve McIntyrebbe4ae32015-02-12 08:57:28 +000076# Generate more detailed data for the hosts by asking VLANd what the
77# IDs are for each port, etc.
78for 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 McIntyreedf32d22015-07-17 15:19:03 +010083 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 McIntyrebbe4ae32015-02-12 08:57:28 +000089 export ${host}_CURRENT_VLAN_TAG=$CURRENT_VLAN_TAG
90done
91
92verify_host_is_base () {
93 HOST=$1
94 PORT_ID_VAR=${HOST}_PORT_ID
95 PORT_ID=${!PORT_ID_VAR}
Steve McIntyreedf32d22015-07-17 15:19:03 +010096 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 McIntyrebbe4ae32015-02-12 08:57:28 +0000100 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
111verify_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
121all_hosts () {
122 COMMAND="$@"
123 for HOST in ${HOSTS}; do
Steve McIntyreedf32d22015-07-17 15:19:03 +0100124 vvecho "Running on ${HOST}:: ${COMMAND}"
Steve McIntyrebbe4ae32015-02-12 08:57:28 +0000125 ssh linaro@${HOST} "${COMMAND}"
126 done
127}
128
129start_logging () {
Steve McIntyree2848942015-07-10 16:51:27 +0100130 all_hosts "echo HOSTS=\\\"$HOSTS\\\" > test-config"
Steve McIntyrebbe4ae32015-02-12 08:57:28 +0000131}
132
133stop_logging () {
Steve McIntyrea31981e2015-07-10 16:24:59 +0100134 all_hosts "rm -f test-config"
Steve McIntyrebbe4ae32015-02-12 08:57:28 +0000135}
136
137grab_logs () {
138 all_hosts "cat /tmp/ping-log*"
139}
140
141clear_logs () {
142 all_hosts "rm -f /tmp/ping-log*"
143}