summaryrefslogtreecommitdiffstats
path: root/tests/templates/names_template
blob: 6181bfaaaa1a2c7b74da72d84fb7cce82b909d61 (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
# NAME is optional. Testing with native 1.2 superblock.
function names_create() {
	local DEVNAME=$1
	local NAME=$2
	local NEG_TEST=$3

	if [[ -z "$NAME" ]]; then
		mdadm -CR "$DEVNAME" -l0 -n 1 $dev0 --force
	else
		mdadm -CR "$DEVNAME" --name="$NAME" --metadata=1.2 -l0 -n 1 $dev0 --force
	fi

	if [[ "$NEG_TEST" == "true" ]]; then
		[[ "$?" == "0" ]] && return 0
		echo "Negative verification failed"
		exit 1
	fi

	if [[ "$?" != "0" ]]; then
		echo "Cannot create device."
		exit 1
	fi
}

# Three properties to check:
# - devnode name
# - link in /dev/md/ (MD_DEVNAME property from --detail --export)
# - name in metadata (MD_NAME property from --detail --export)- that works only with 1.2 sb.
function names_verify() {
	local DEVNODE_NAME="$1"
	local WANTED_LINK="$2"
	local WANTED_NAME="$3"

	local RES="$(mdadm -D --export $DEVNODE_NAME | grep MD_DEVNAME)"
	if [[ "$?" != "0" ]]; then
		echo "Cannot get details for $DEVNODE_NAME - unexpected devnode."
		exit 1
	fi

	if [[ "$WANTED_LINK" != "empty" ]]; then
		local EXPECTED="MD_DEVNAME=$WANTED_LINK"
	fi

	if [[ "$RES" != "$EXPECTED" ]]; then
		echo "$RES doesn't match $EXPECTED."
		exit 1
	fi

	local RES="$(mdadm -D --export $DEVNODE_NAME | grep MD_NAME)"
	if [[ "$?" != "0" ]]; then
		echo "Cannot get metadata from $dev0."
		exit 1
	fi

	local EXPECTED="MD_NAME=$(hostname):$WANTED_NAME"
	if [[ "$RES" != "$EXPECTED" ]]; then
		echo "$RES doesn't match $EXPECTED."
		exit 1
	fi
}

# Generate ARRAYLINE for tested array.
names_make_conf() {
	local UUID="$1"
	local WANTED_DEVNAME="$2"
	local WANTED_NAME="$3"
	local CONF="$4"

	local LINE="ARRAY metadata=1.2 UUID=$UUID"

	if [[ "$WANTED_DEVNAME" != "empty" ]]; then
		LINE="$LINE $WANTED_DEVNAME"
	fi

	if [[ "$WANTED_NAME" != "empty" ]]; then
		LINE="$LINE name=$WANTED_NAME"
	fi

	echo $LINE > $CONF
}