aboutsummaryrefslogtreecommitdiff
path: root/test/test-common
blob: fd38421a0512174f362380a46b5e1309a61f55fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#
# test-common
#
# Common set of definitions and functions to help with driving VLANd
# in testing

TOPDIR=$(dirname $0)/..
ADMIN="python $TOPDIR/admin.py"
HOSTS="panda01 panda02 panda03 arndale01 arndale02 arndale03 imx5301 imx5302 imx5303"

# 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?
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}
}