Whamcloud - gitweb
b3e5e929f2cd1edd7c627c9813156da7eadbb970
[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 restore_mounts=false
32
33 if is_mounted $MOUNT || is_mounted $MOUNT2; then
34         cleanupall || error "Failed cleanup prior to test execution"
35         restore_mounts=true
36 fi
37
38 cleanup_lnet() {
39         echo "Cleaning up LNet"
40         $LNETCTL lnet unconfigure 2>/dev/null
41         unload_modules
42 }
43
44 restore_modules=false
45 if module_loaded lnet ; then
46         cleanup_lnet || error "Failed to unload modules before test execution"
47         restore_modules=true
48 fi
49
50 cleanup_testsuite() {
51         rm -f $TMP/sanity-dlc*
52         cleanup_netns
53         cleanup_lnet
54         if $restore_mounts; then
55                 setupall || error "Failed to setup Lustre after test execution"
56         elif $restore_modules; then
57                 load_modules ||
58                         error "Couldn't load modules after test execution"
59         fi
60         return 0
61 }
62
63 load_lnet() {
64         load_module ../libcfs/libcfs/libcfs
65         # Prevent local MODOPTS_LIBCFS being passed as part of environment
66         # variable to remote nodes
67         unset MODOPTS_LIBCFS
68
69         set_default_debug
70         load_module ../lnet/lnet/lnet "$@"
71
72         LNDPATH=${LNDPATH:-"../lnet/klnds"}
73         if [ -z "$LNETLND" ]; then
74                 case $NETTYPE in
75                 o2ib*)  LNETLND="o2iblnd/ko2iblnd" ;;
76                 tcp*)   LNETLND="socklnd/ksocklnd" ;;
77                 *)      local lnd="${NETTYPE%%[0-9]}lnd"
78                         [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
79                                 LNETLND="$lnd/k$lnd" ||
80                                 LNETLND="socklnd/ksocklnd"
81                 esac
82         fi
83         load_module ../lnet/klnds/$LNETLND
84 }
85
86 do_lnetctl() {
87         echo "$LNETCTL $@"
88         $LNETCTL "$@"
89 }
90
91 TESTNS='test_ns'
92 FAKE_IF="test1pg"
93 FAKE_IP="10.1.2.3"
94 do_ns() {
95         echo "ip netns exec $TESTNS $@"
96         ip netns exec $TESTNS "$@"
97 }
98
99 setup_netns() {
100         cleanup_netns
101
102         ip netns add $TESTNS
103         ip link add 'test1pl' type veth peer name $FAKE_IF netns $TESTNS
104         ip link set 'test1pl' up
105         do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
106         do_ns ip link set $FAKE_IF up
107 }
108
109 cleanup_netns() {
110         (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
111         if ip link show test1pl >/dev/null 2>&1; then
112                 ip link del test1pl
113         fi
114 }
115
116 cleanupall -f
117
118 setup_netns
119 load_lnet
120
121 test_1() {
122         do_lnetctl lnet configure
123 }
124 run_test 1 "configure lnet with lnetctl"
125
126
127 ### load lnet in default namespace, configure in target namespace
128
129 test_2() {
130         cleanup_lnet || exit 1
131         load_lnet "networks=\"\""
132         do_ns $LNETCTL lnet configure --all || exit 1
133         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
134 }
135 run_test 2 "load lnet w/o module option, configure in a non-default namespace"
136
137 test_3() {
138         cleanup_lnet || exit 1
139         load_lnet "networks=tcp($FAKE_IF)"
140         do_ns $LNETCTL lnet configure --all || exit 1
141         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
142 }
143 run_test 3 "load lnet using networks module options in a non-default namespace"
144
145 test_4() {
146         cleanup_lnet || exit 1
147         load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
148         do_ns $LNETCTL lnet configure --all || exit 1
149         $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
150 }
151 run_test 4 "load lnet using ip2nets in a non-default namespace"
152
153
154 ### Add the interfaces in the target namespace
155
156 test_5() {
157         cleanup_lnet || exit 1
158         load_lnet
159         do_lnetctl lnet configure || exit 1
160         do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
161 }
162 run_test 5 "add a network using an interface in the non-default namespace"
163
164 complete $SECONDS
165
166 cleanup_testsuite
167 exit_status