blob: ea92d8b5705009125f2153393a0f163174937ead [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)/..
8ADMIN="python $TOPDIR/admin.py"
Steve McIntyrea31981e2015-07-10 16:24:59 +01009
10# Default settings
11if [ "$VERBOSE"x = ""x ] ; then
12 VERBOSE=0
13fi
14if [ "$HOSTS"x = ""x ] ; then
15 HOSTS="panda01 panda02 panda03 arndale01 arndale02 arndale03 arndale04 imx5301 imx5302 imx5303"
16fi
17if [ "$SWITCHES"x = ""x ] ; then
18 SWITCHES="vlandswitch01 vlandswitch02 vlandswitch03 vlandswitch04 vlandswitch05"
19fi
20
Steve McIntyre4c2c6012015-01-26 16:17:38 +000021
Steve McIntyrebbe4ae32015-02-12 08:57:28 +000022# Topology definitions - how are the test machines connected?
23panda01_SWITCH_PORT="vlandswitch01:Gi1/0/2"
24panda02_SWITCH_PORT="vlandswitch02:fa25"
25panda03_SWITCH_PORT="vlandswitch03:gi25"
26arndale01_SWITCH_PORT="vlandswitch01:Gi1/0/3"
27arndale02_SWITCH_PORT="vlandswitch02:fa2"
28arndale03_SWITCH_PORT="vlandswitch03:gi2"
Steve McIntyrecda3ef92015-07-10 14:43:38 +010029arndale04_SWITCH_PORT="vlandswitch04:Gi1/0/3"
30imx5301_SWITCH_PORT="vlandswitch05:1/0/21"
31imx5302_SWITCH_PORT="vlandswitch05:1/0/22"
32imx5303_SWITCH_PORT="vlandswitch04:Gi1/0/2"
Steve McIntyrebbe4ae32015-02-12 08:57:28 +000033
Steve McIntyrebbe4ae32015-02-12 08:57:28 +000034vecho () {
35 if [ $VERBOSE -gt 0 ] ; then
36 echo "$@"
37 fi
38}
Steve McIntyre4c2c6012015-01-26 16:17:38 +000039
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 McIntyrea31981e2015-07-10 16:24:59 +010045for SWITCH in $SWITCHES; do
46 export ${SWITCH}_ID=$($ADMIN --lookup_switch_by_name $SWITCH)
47done
Steve McIntyre4c2c6012015-01-26 16:17:38 +000048
Steve McIntyrebbe4ae32015-02-12 08:57:28 +000049# Generate more detailed data for the hosts by asking VLANd what the
50# IDs are for each port, etc.
51for 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
63done
64
65verify_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
84verify_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
94all_hosts () {
95 COMMAND="$@"
96 for HOST in ${HOSTS}; do
97 ssh linaro@${HOST} "${COMMAND}"
98 done
99}
100
101start_logging () {
Steve McIntyree2848942015-07-10 16:51:27 +0100102 all_hosts "echo HOSTS=\\\"$HOSTS\\\" > test-config"
Steve McIntyrebbe4ae32015-02-12 08:57:28 +0000103}
104
105stop_logging () {
Steve McIntyrea31981e2015-07-10 16:24:59 +0100106 all_hosts "rm -f test-config"
Steve McIntyrebbe4ae32015-02-12 08:57:28 +0000107}
108
109grab_logs () {
110 all_hosts "cat /tmp/ping-log*"
111}
112
113clear_logs () {
114 all_hosts "rm -f /tmp/ping-log*"
115}
116
117log () {
Steve McIntyre7a0a15c2015-07-10 15:36:23 +0100118 DATE=$(date -u +%F:%H:%M:%S)
Steve McIntyrebbe4ae32015-02-12 08:57:28 +0000119 if [ "${LOGFILE}"x = ""x ] ; then
120 LOGFILE=$0.log
121 fi
122 echo "${DATE}: $@"
123 echo " ${DATE}: $@" >> ${LOGFILE}
124}