]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - tests/templates/names_template
tests: create names_template
[thirdparty/mdadm.git] / tests / templates / names_template
diff --git a/tests/templates/names_template b/tests/templates/names_template
new file mode 100644 (file)
index 0000000..9f09be9
--- /dev/null
@@ -0,0 +1,53 @@
+# NAME is optional. Testing with native 1.2 superblock.
+function names_create() {
+       local DEVNAME=$1
+       local NAME=$2
+
+       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 [[ "$?" != "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
+}