diff options
author | Steve McIntyre <steve.mcintyre@linaro.org> | 2015-02-12 08:57:28 +0000 |
---|---|---|
committer | Steve McIntyre <steve.mcintyre@linaro.org> | 2015-02-12 08:57:28 +0000 |
commit | bbe4ae31f999cc7d83ce2e67b6224f551eecbf49 (patch) | |
tree | f2fde27acc2c8b49b1c6daf76d70fae6f3a219eb | |
parent | a67473a8f95b19bbee8e986ed7c48f058597737e (diff) |
Common test code infrastructure
Change-Id: I614d4cbf82c5be6c5b22d59ccad569861e945036
-rwxr-xr-x | test/test-common | 124 |
1 files changed, 100 insertions, 24 deletions
diff --git a/test/test-common b/test/test-common index f85661c..fd38421 100755 --- a/test/test-common +++ b/test/test-common @@ -4,36 +4,112 @@ # Common set of definitions and functions to help with driving VLANd # in testing -echo $0 TOPDIR=$(dirname $0)/.. ADMIN="python $TOPDIR/admin.py" +HOSTS="panda01 panda02 panda03 arndale01 arndale02 arndale03 imx5301 imx5302 imx5303" -# Topology definitions -PAN1_SWITCH_PORT="Gi1/0/2" -PAN2_SWITCH_PORT="fa25" -PAN3_SWITCH_PORT="gi25" -ARN1_SWITCH_PORT="Gi1/0/3" -ARN2_SWITCH_PORT="fa2" -ARN3_SWITCH_PORT="gi2" -IMX1_SWITCH_PORT="Gi1/0/4" -IMX1_SWITCH_PORT="fa26" -IMX1_SWITCH_PORT="gi26" +# Topology definitions - how are the test machines connected? +panda01_SWITCH_PORT="vlandswitch01:Gi1/0/2" +panda02_SWITCH_PORT="vlandswitch02:fa25" +panda03_SWITCH_PORT="vlandswitch03:gi25" +arndale01_SWITCH_PORT="vlandswitch01:Gi1/0/3" +arndale02_SWITCH_PORT="vlandswitch02:fa2" +arndale03_SWITCH_PORT="vlandswitch03:gi2" +imx5301_SWITCH_PORT="vlandswitch01:Gi1/0/4" +imx5302_SWITCH_PORT="vlandswitch02:fa26" +imx5303_SWITCH_PORT="vlandswitch03:gi26" + +# Default debug level +VERBOSE=0 + +vecho () { + if [ $VERBOSE -gt 0 ] ; then + echo "$@" + fi +} # Startup check $ADMIN --status # Preload some data - what are the switch IDs and port IDs of the # various things in our test setup? -SW1_ID=$($ADMIN --lookup_switch_by_name vlandswitch01) -SW2_ID=$($ADMIN --lookup_switch_by_name vlandswitch02) -SW3_ID=$($ADMIN --lookup_switch_by_name vlandswitch03) - -PAN1_PORT_ID=$($ADMIN --lookup_port_by_switch_and_name $SW1_ID $PAN1_SWITCH_PORT) -PAN2_PORT_ID=$($ADMIN --lookup_port_by_switch_and_name $SW2_ID $PAN2_SWITCH_PORT) -PAN2_PORT_ID=$($ADMIN --lookup_port_by_switch_and_name $SW3_ID $PAN3_SWITCH_PORT) -ARN1_PORT_ID=$($ADMIN --lookup_port_by_switch_and_name $SW1_ID $ARN1_SWITCH_PORT) -ARN2_PORT_ID=$($ADMIN --lookup_port_by_switch_and_name $SW2_ID $ARN2_SWITCH_PORT) -ARN3_PORT_ID=$($ADMIN --lookup_port_by_switch_and_name $SW2_ID $ARN3_SWITCH_PORT) -IMX1_PORT_ID=$($ADMIN --lookup_port_by_switch_and_name $SW1_ID $IMX1_SWITCH_PORT) -IMX2_PORT_ID=$($ADMIN --lookup_port_by_switch_and_name $SW2_ID $IMX3_SWITCH_PORT) -IMX3_PORT_ID=$($ADMIN --lookup_port_by_switch_and_name $SW2_ID $IMX3_SWITCH_PORT) +vlandswitch01_ID=$($ADMIN --lookup_switch_by_name vlandswitch01) +vlandswitch02_ID=$($ADMIN --lookup_switch_by_name vlandswitch02) +vlandswitch03_ID=$($ADMIN --lookup_switch_by_name vlandswitch03) + +# Generate more detailed data for the hosts by asking VLANd what the +# IDs are for each port, etc. +for host in $HOSTS; do + SWITCH_PORT_VAR=${host}_SWITCH_PORT + SW=${!SWITCH_PORT_VAR%%:*} + SW_VAR=${SW}_ID + SW_ID=${!SW_VAR} + PORT_NAME=${!SWITCH_PORT_VAR##*:} + PORT_ID=$($ADMIN --lookup_port_by_switch_and_name $SW_ID $PORT_NAME) + export ${host}_PORT_ID=${PORT_ID} + CURRENT_VLAN_ID=$($ADMIN --get_port_current_vlan $PORT_ID) + export ${host}_CURRENT_VLANID=$CURRENT_VLAN_ID + CURRENT_VLAN_TAG=$($ADMIN --show_vlan_tag $CURRENT_VLAN_ID) + export ${host}_CURRENT_VLAN_TAG=$CURRENT_VLAN_TAG +done + +verify_host_is_base () { + HOST=$1 + PORT_ID_VAR=${HOST}_PORT_ID + PORT_ID=${!PORT_ID_VAR} + CURRENT_VLAN_ID=$($ADMIN --get_port_current_vlan $PORT_ID) + CURRENT_VLAN_TAG=$($ADMIN --show_vlan_tag $CURRENT_VLAN_ID) + BASE_VLAN_ID=$($ADMIN --get_port_base_vlan $PORT_ID) + BASE_VLAN_TAG=$($ADMIN --show_vlan_tag $BASE_VLAN_ID) + vecho "$HOST" + vecho " is on port ID $PORT_ID" + vecho " which is on VLAN ID $CURRENT_VLAN_ID, tag $CURRENT_VLAN_TAG" + vecho " and should be on base VLAN ID $BASE_VLAN_ID, tag $BASE_VLAN_TAG" + if [ $CURRENT_VLAN_ID == $BASE_VLAN_ID ] ; then + return 0 + else + return 1 + fi +} + +verify_all_hosts_are_base () { + # Check that all the machines are correctly on their base VLANs + for host in $HOSTS; do + verify_host_is_base $host + if [ $? -ne 0 ] ; then + return 1 + fi + done +} + +all_hosts () { + COMMAND="$@" + for HOST in ${HOSTS}; do + ssh linaro@${HOST} "${COMMAND}" + done +} + +start_logging () { + all_hosts "rm -f disable_test" +} + +stop_logging () { + all_hosts "touch disable_test" +} + +grab_logs () { + all_hosts "cat /tmp/ping-log*" +} + +clear_logs () { + all_hosts "rm -f /tmp/ping-log*" +} + +log () { + DATE=$(date -u +%F:%H:%M) + if [ "${LOGFILE}"x = ""x ] ; then + LOGFILE=$0.log + fi + echo "${DATE}: $@" + echo " ${DATE}: $@" >> ${LOGFILE} +} |