Whamcloud - gitweb
052c39d8eb4e33d3e7724ee0fea5fb86db39e161
[fs/lustre-release.git] / lustre / tests / sanity-lnet.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test:
11 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
12 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
16
17 . $LUSTRE/tests/test-framework.sh
18 CLEANUP=${CLEANUP:-:}
19 SETUP=${SETUP:-:}
20 init_test_env $@
21 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
22 init_logging
23
24 build_test_filter
25
26 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
27 [ ! -f "$LNETCTL" ] &&
28         export LNETCTL=$(which lnetctl 2> /dev/null)
29 [[ -z $LNETCTL ]] && skip "Need lnetctl"
30
31 load_lnet() {
32         load_module ../libcfs/libcfs/libcfs
33         # Prevent local MODOPTS_LIBCFS being passed as part of environment
34         # variable to remote nodes
35         unset MODOPTS_LIBCFS
36
37         set_default_debug
38         load_module ../lnet/lnet/lnet "$@"
39
40         LNDPATH=${LNDPATH:-"../lnet/klnds"}
41         if [ -z "$LNETLND" ]; then
42                 case $NETTYPE in
43                 o2ib*)  LNETLND="o2iblnd/ko2iblnd" ;;
44                 tcp*)   LNETLND="socklnd/ksocklnd" ;;
45                 *)      local lnd="${NETTYPE%%[0-9]}lnd"
46                         [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
47                                 LNETLND="$lnd/k$lnd" ||
48                                 LNETLND="socklnd/ksocklnd"
49                 esac
50         fi
51         load_module ../lnet/klnds/$LNETLND
52 }
53
54 cleanup_lnet() {
55         $LNETCTL lnet unconfigure 2>/dev/null
56         unload_modules
57 }
58
59 do_lnetctl() {
60         echo "$LNETCTL $@"
61         $LNETCTL "$@"
62 }
63
64 TESTNS='test_ns'
65 FAKE_IF="test1pg"
66 FAKE_IP="10.1.2.3"
67 do_ns() {
68         echo "ip netns exec $TESTNS $@"
69         ip netns exec $TESTNS "$@"
70 }
71
72 setup_netns() {
73         cleanup_netns
74
75         ip netns add $TESTNS
76         ip link add 'test1pl' type veth peer name $FAKE_IF netns $TESTNS
77         ip link set 'test1pl' up
78         do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
79         do_ns ip link set $FAKE_IF up
80 }
81
82 cleanup_netns() {
83         (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
84         if ip link show test1pl >/dev/null 2>&1; then
85                 ip link del test1pl
86         fi
87 }
88
89 cleanupall -f
90
91 setup_netns
92 load_lnet
93
94 test_1() {
95         do_lnetctl lnet configure
96 }
97 run_test 1 "configure lnet with lnetctl"
98
99
100 ### load lnet in default namespace, configure in target namespace
101
102 test_2() {
103         cleanup_lnet || exit 1
104         load_lnet "networks=\"\""
105         do_ns $LNETCTL lnet configure --all || exit 1
106         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
107 }
108 run_test 2 "load lnet w/o module option, configure in a non-default namespace"
109
110 test_3() {
111         cleanup_lnet || exit 1
112         load_lnet "networks=tcp($FAKE_IF)"
113         do_ns $LNETCTL lnet configure --all || exit 1
114         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
115 }
116 run_test 3 "load lnet using networks module options in a non-default namespace"
117
118 test_4() {
119         cleanup_lnet || exit 1
120         load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
121         do_ns $LNETCTL lnet configure --all || exit 1
122         $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
123 }
124 run_test 4 "load lnet using ip2nets in a non-default namespace"
125
126
127 ### Add the interfaces in the target namespace
128
129 test_5() {
130         cleanup_lnet || exit 1
131         load_lnet
132         do_lnetctl lnet configure || exit 1
133         do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
134 }
135 run_test 5 "add a network using an interface in the non-default namespace"
136
137 cleanup_netns
138 cleanup_lnet
139 exit_status