Debian Codegraph @

debian/tests/tgtbasedmpaths

raw
1 #!/bin/sh
2 # autopkgtest check: tgt and open-iscsi based mpath operations
3 # The test is intentionally extra verbose to have rich log and to stress
4 # some of the code paths in and around multipath on top of the actual IO test.
5 # (C) 2016 Canonical Ltd.
6 # Author: Christian Ehrhardt <[email protected]>
7
8 # Tests the creation and usage of a tgt target and lun on localhost
9 set -uxe
10
11 targetname="iqn.2016-11.foo.com:target.iscsi"
12 cwd=$(pwd)
13 testdir="/mnt/tgtmpathtest"
14 localhost="127.0.0.1"
15 portal="${localhost}:3260"
16 maxpaths=4
17 backfn="backingfile"
18 expectwwid="60000000000000000e00000000010001"
19 testdisk="/dev/disk/by-id/wwn-0x${expectwwid}"
20 bglog="$AUTOPKGTEST_ARTIFACTS/test-background.log"
21 fioprep="$AUTOPKGTEST_ARTIFACTS/path-change-prep.fio"
22 fiovrfy="$AUTOPKGTEST_ARTIFACTS/path-change-check.fio"
23
24 # Debian uses upstreams default for find_multipaths.
25 # Provide a WWID entry, so the devices will be managed by multipath(d).
26 mkdir -p /etc/multipath
27 echo "/360000000000000000e00000000010001/" > /etc/multipath/wwids
28
29 # Restart tgtd to make sure modules are all loaded
30 service tgt restart || echo "Failed to restart tgt" >&2
31
32 # prep SINGLE test file
33 truncate --size 100M ${backfn}
34
35 # create target
36 tgtadm --lld iscsi --op new --mode target --tid 1 -T "${targetname}"
37 # allow all to bind the target
38 tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
39 # set backing file
40 tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b "${cwd}/${backfn}"
41
42 # scan for targets (locally)
43 iscsiadm --mode discovery --type sendtargets --portal ${localhost}
44
45 # login
46 echo "login #1"
47 iscsiadm --mode node --targetname "${targetname}" --portal ${portal} --login
48 # duplicate this session (always 1)
49 for i in $(seq 2 ${maxpaths})
50 do
51 echo "extra login #${i}"
52 iscsiadm --mode session -r 1 --op new
53 done
54
55 udevadm settle
56 sleep 5 # sleep a bit to allow device to be created.
57
58 # status summary
59 echo "Status after initial setup"
60 tgtadm --lld iscsi --mode target --op show
61 tgtadm --lld iscsi --op show --mode conn --tid 1
62 iscsiadm --mode session -P 1
63 lsscsi -liv
64 multipath -v3 -ll
65 dmsetup table
66 grep . /etc/multipath/*
67 systemctl status multipathd.service
68 # In certain systems, the socket may be inactive which will be a return code
69 # of 3 from systemctl. This is a fine situation to be in, as long as the rest of
70 # the test passes.
71 ret_code=0
72 systemctl status multipathd.socket || ret_code=$? \
73 && { [ $ret_code -eq 0 ] || [ $ret_code -eq 3 ]; }
74 ls -la /dev/mapper/
75
76 echo "journal"
77 journalctl -b
78
79 echo "Test WWN should now point to DM"
80 readlink "${testdisk}" | grep dm
81
82 # create FS on the mpathed device
83 mkfs.ext4 -F "${testdisk}"
84 udevadm settle
85 sleep 3s
86 mkdir -p ${testdir}
87 mount "${testdisk}" ${testdir}
88
89 # based on /usr/share/doc/fio/examples/surface-scan.fio
90 cat << EOF > ${fioprep}
91 ; writes 512 byte verification blocks until the disk is full,
92 ; then verifies written data
93 [global]
94 directory=${testdir}
95 thread=1
96 bs=64k
97 direct=1
98 ioengine=sync
99 verify=meta
100 verify_pattern=0xaa555aa5
101 verify_interval=512
102
103 [write-phase]
104 filename=datafile.tmp ; or use a full disk, for example /dev/sda
105 rw=write
106 fill_device=1
107 do_verify=0
108 EOF
109
110 cat << EOF > ${fiovrfy}
111 ; verifies written data
112 [global]
113 directory=${testdir}
114 thread=1
115 bs=64k
116 direct=1
117 ioengine=sync
118 verify=meta
119 verify_pattern=0xaa555aa5
120 verify_interval=512
121
122 [verify-phase]
123 stonewall
124 create_serialize=0
125 filename=datafile.tmp
126 rw=read
127 do_verify=1
128 runtime=180
129 time_based
130 EOF
131
132 # IO Bench with verify
133 # prep files
134 fio --max-jobs=4 "${fioprep}"
135
136 # while verify is running unplud/plug paths as well as restart the daemon
137 # Note - we run in a clean env, so we just assume each new session is an increment
138 # Even with other multipath/scsi devices on the system this is true, jutst no
139 # other iscsi logins are allowed - since the test runs under isolation-machine
140 # that should be safe.
141 # That way we can directly call IDs without huge logic on the session IDs
142 echo "Starting the path changes in background"
143 (
144 iscsiadm --mode session
145 sleep 10s
146 date +'MP report (expect 4) %H:%M:%S.%N'
147 multipath -ll
148 date +'UN-plug path 1 %H:%M:%S.%N'
149 iscsiadm --mode session -r 1 -u
150 iscsiadm --mode session
151 sleep 10s
152 date +'MP report (expect 3) %H:%M:%S.%N'
153 multipath -ll
154 date +'UN-plug path 2 %H:%M:%S.%N'
155 iscsiadm --mode session -r 2 -u
156 iscsiadm --mode session
157 sleep 10s
158 date +'MP report (expect 2) %H:%M:%S.%N'
159 multipath -ll
160 date +'UN-plug path 3 %H:%M:%S.%N'
161 iscsiadm --mode session -r 3 -u
162 iscsiadm --mode session
163 sleep 10s
164 date +'MP report (expect 1) %H:%M:%S.%N'
165 multipath -ll
166 date +'Add paths 5/6/7/8 %H:%M:%S.%N'
167 iscsiadm --mode session -r 4 --op new
168 iscsiadm --mode session -r 4 --op new
169 iscsiadm --mode session -r 4 --op new
170 iscsiadm --mode session -r 4 --op new
171 iscsiadm --mode session
172 sleep 10s
173 date +'MP report (expect 5) %H:%M:%S.%N'
174 multipath -ll
175 date +'UN-plug multiple paths 4/7/8 %H:%M:%S.%N'
176 iscsiadm --mode session -r 4 -u
177 iscsiadm --mode session -r 7 -u
178 iscsiadm --mode session -r 8 -u
179 iscsiadm --mode session
180 sleep 10s
181 date +'Restart multipath daemon %H:%M:%S.%N'
182 systemctl restart multipathd
183 sleep 10s
184 date +'Final background report (expect 2) %H:%M:%S.%N'
185 multipath -ll
186 ) > "${bglog}" 2>&1 &
187
188 # test I/O with verification of actual content
189 # on any I/O error or verification of read data it would fail
190 date +'Pre FIO %H:%M:%S.%N'
191 fio --max-jobs=4 "${fiovrfy}"
192 date +'Post FIO %H:%M:%S.%N'
193
194 echo "FIO verify test with changing paths - OK"
195
196 echo "Report log of background activity"
197 cat "${bglog}"
198
199 sync
200 umount "${testdisk}"
201
202 # report stats - might be useful if checked across various tests that misbehave
203 echo "Final stats"
204 iscsiadm --mode session --stats
205 journalctl --no-pager -u multipathd
206
207 echo "Check final path status"
208 multipath -ll
209 # ensure we have one active and one running path
210 diskc=$(multipath -ll | grep --count 'status=')
211 diska=$(multipath -ll | grep --count 'status=active')
212 diske=$(multipath -ll | grep --count 'status=enabled')
213 if [ "${diskc}" -ne "2" -o "${diska}" -ne "1" -o "${diske}" -ne "1" ]; then
214 echo "Error: Not the expected count of active/enabled disks"
215 exit 1
216 else
217 echo "OK"
218 fi
219
220 # logout and target delete should work even after all of this
221 iscsiadm --mode node --targetname "${targetname}" --portal "${portal}" --logout
222 tgtadm --lld iscsi --op delete --mode logicalunit --tid 1 --lun 1