]> git.ipfire.org Git - thirdparty/mdadm.git/blob - tests/utils
tests: add test that DDF marks missing devices as failed on assembly.
[thirdparty/mdadm.git] / tests / utils
1 # set of functions used to test policy framework with assemble, incremental and Monitor
2
3 set +e
4 #create links to be able to use domains
5 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
6 do
7 eval ln -s \$dev$d /dev/disk/by-path/loop$d
8 eval d$d="loop$d"
9 eval mdadm --zero-superblock \$dev$d
10 done
11
12 devices="/dev/loop[0-9] /dev/loop10 /dev/loop11 /dev/loop12"
13
14 # on failure print out few things before exit
15 # uses testdsc and platform global variables
16 err(){
17 echo >&2 "ERROR: $*"
18 cat $config >&2 || true
19 cat /proc/mdstat >&2
20 [ -z "$testdsc" ] || { echo >&2 $platform: $testdsc "- failed"; }
21 ps -e | grep mdadm >&2 || true
22 if [ $listfailed == "yes" ]; then
23 [ "$verbose" != "yes" ] || echo ---FAILED---
24 flist="$flist \n $platform $testdsc"
25 failed=1
26 else
27 exit 1
28 fi
29 }
30
31 # set test description
32 dsc(){
33 failed=0
34 testdsc="$*"
35 [ "$verbose" != "yes" ] || echo $testdsc
36 }
37
38 killmonitor(){
39 [ -z "$monitorpid" ] || { kill -9 $monitorpid; unset monitorpid; }
40 }
41
42 tidyup(){
43 killmonitor
44 mdadm -Ss || true
45 mdadm -Ss
46 mdadm --zero-superblock $devices || true
47 udevadm settle
48 rm -f $config
49 }
50
51 trap tidyup 0 1 2 3 15
52
53 # create a RAID 1 array or container and subarray(s) on 2 disks
54 # if platform not specified imsm is used
55 # if subsize is given, first subarray is created with given size and second one on remaining space
56 ccv(){
57 # mddevno used to name created array
58 local mddevno="$1"
59 # numbers of devices to be used in array
60 local devno1="$2"
61 local devno2="$3"
62 local platform="$4"
63 local subsize="$5"
64 local onearray="$6"
65 [ -n "$platform" ] || platform="imsm"
66 if [ "$platform" == "imsm" ] || [ "$platform" == "ddf" ]; then
67 eval mdadm -CR /dev/md/con$mddevno -e $platform -n 2 \$dev$devno1 \$dev$devno2
68 udevadm settle
69 [ -z "$subsize" ] || eval mdadm -CR sub$mddevno"_" -l 1 -n 2 /dev/md/con$mddevno -z $subsize
70 [ -n "$onearray" ] || eval mdadm -CR sub$mddevno -l 1 -n 2 /dev/md/con$mddevno
71 else
72 [ -z "$subsize" ] || sizepar="-z $subsize"
73 eval mdadm -CR arr$mddevno -e $platform -l 1 -n 2 \$dev$devno1 \$dev$devno2 $sizepar
74 unset sizepar
75 fi
76 }
77
78 # get container and subarray using given device from mdstat
79 # sets global variables c and v
80 getarray(){
81 local devname=`basename $1`
82 local platformtype=`grep -A 1 $devname /proc/mdstat | awk '/active/ {getline; print $4 }' | awk -F ":" 'END {print $1}'`
83 c=`grep "inactive.*$devname" /proc/mdstat | awk -F " " '{print $1}'`
84 v=`grep " active.*$devname" /proc/mdstat | awk -F " " '{print $1}'`
85 [ "$platformtype" == "external" ] || c=$v
86 }
87
88 # check if given device belongs to any container and subarray
89 # if $2 given then only container checked
90 chkarray(){
91 local devname="$1"
92 local subcheck="$2"
93 getarray $devname
94 [ -n "$c" ] || err "$devname not in any container"
95 [ -n "$subcheck" ] || [ -n "$v" ] || err " $devname not in subarray"
96 }
97
98 # test if two devices in the same container/subarray
99 # $1 $2 - devices
100 # $3 don't check subarrays, only containers
101 tst(){
102 local device1=`basename $1`
103 local device2=`basename $2`
104 local subcheck="$3"
105 chkarray $device1 $subcheck
106 local x="$c"
107 local y="$v"
108 chkarray $device2 $subcheck
109 [ "$c" == "$x" ] || err "$device1 and $device2 not in the same container"
110 [ -n "$subcheck" ] || [ "$v" == "$y" ] || err "$device1 and $device2 not in the same subarray"
111 }
112
113 # same as tst, just use numbers of devices instead of names as parameters
114 dtst(){
115 local devno1="$1"
116 local devno2="$2"
117 local subcheck="$3"
118 eval tst \$dev$devno1 \$dev$devno2 $subcheck
119 }
120
121 # create containers/subarrays, check if created properly,
122 # set global variables c$mddevno v$mddevno, usually c0=md127, v0=md126 , etc.
123 setupdevs(){
124 local mddevno="$1"
125 local devno1="$2"
126 local devno2="$3"
127 local p="$4"
128 local subsize="$5"
129 local onearray="$6"
130 [ -n "$p" ] || p=$platform
131 ccv $mddevno $devno1 $devno2 $p $subsize $onearray
132 dtst $devno1 $devno2
133 eval c$mddevno=\"$c\"
134 eval v$mddevno=\"$v\"
135 }
136
137 # check if given spare in container
138 # usage: chkspare container spare [n] (n if spare shouldn't be in container)
139 chkspare(){
140 local container=`basename $1`
141 local spare=$2
142 local expected=$3
143 getarray $spare
144 [ -n "$expected" ] || expected="y"
145 if [ "$expected" == "y" ]; then
146 [ "$c" == "$container" ] || err "$spare not in container $container"
147 else
148 [ "$c" != "$container" ] || err "$spare in container $container"
149 fi
150 }
151
152 #check if spare was moved from one container to another
153 # args: from_container to_container spare [yn]
154 # n when spare should remain in original container
155 chksparemoved(){
156 sleep $sleeptime
157 from_container="$1"
158 to_container="$2"
159 spare="$3"
160 expected="$4"
161 [ -n "$expected" ] || expected="y"
162 notexpected="n"; [ "$expected" == "y" ] || notexpected="y"
163 chkspare $from_container $spare $notexpected
164 [ $failed -eq 1 ] || chkspare $to_container $spare $expected
165 }
166
167
168 # for domains defined through policy
169 createconfig(){
170 if [ "$1" != "a" ]; then
171 {
172 domain=$1
173 metadata=$2
174 action=$3
175 while [ -n "$4" ]; do
176 echo="policy domain=$domain"
177 [ "$metadata" == "noplatform" ] || echo="$echo metadata=$metadata"
178 echo="$echo path=loop$4"
179 echo="$echo action=$action"
180 echo "$echo"
181 shift
182 done
183 } >> $config
184 else
185 {
186 echo "DEVICES $devlist /dev/md1*"
187 mdadm -Ebs
188 } > $config
189 fi
190 #[ "$verbose" != "yes" ] || cat $config | grep policy || true
191 }