Blame SOURCES/0047-tests-add-test-for-names.patch

c0f891
From b7671c82010ffc04dfaecff2dd19ef8b2283e2b6 Mon Sep 17 00:00:00 2001
c0f891
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
c0f891
Date: Tue, 19 Jul 2022 14:48:21 +0200
37f2b0
Subject: [PATCH 47/83] tests: add test for names
c0f891
c0f891
Current behavior is not documented and tested. This test is a base for
c0f891
future improvements. It is enough to test it only with native metadata,
c0f891
because it is generic code. Generated properties are passed to metadata
c0f891
handler.
c0f891
c0f891
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
c0f891
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
c0f891
---
c0f891
 tests/00createnames | 93 +++++++++++++++++++++++++++++++++++++++++++++
c0f891
 1 file changed, 93 insertions(+)
c0f891
 create mode 100644 tests/00createnames
c0f891
c0f891
diff --git a/tests/00createnames b/tests/00createnames
c0f891
new file mode 100644
c0f891
index 00000000..64b81b92
c0f891
--- /dev/null
c0f891
+++ b/tests/00createnames
c0f891
@@ -0,0 +1,93 @@
c0f891
+set -x -e
c0f891
+
c0f891
+# Test how <devname> and --name= are handled for create mode.
c0f891
+# We need to check three properties, generated from those parameters:
c0f891
+# - devnode name
c0f891
+# - link in /dev/md/ (MD_DEVNAME property from --detail --export)
c0f891
+# - name in metadata (MD_NAME property from --examine --export)
c0f891
+
c0f891
+function _verify() {
c0f891
+  local DEVNODE_NAME="$1"
c0f891
+  local WANTED_LINK="$2"
c0f891
+  local WANTED_NAME="$3"
c0f891
+
c0f891
+  local RES="$(mdadm -D --export $DEVNODE_NAME | grep MD_DEVNAME)"
c0f891
+  if [[ "$?" != "0" ]]; then
c0f891
+    echo "Cannot get details for $DEVNODE_NAME - unexpected devnode."
c0f891
+    exit 1
c0f891
+  fi
c0f891
+
c0f891
+  if [[ "$WANTED_LINK" != "empty" ]]; then
c0f891
+    local EXPECTED="MD_DEVNAME=$WANTED_LINK"
c0f891
+      if [[ "$RES" != "$EXPECTED" ]]; then
c0f891
+        echo "$RES doesn't match $EXPECTED."
c0f891
+        exit 1
c0f891
+      fi
c0f891
+  fi
c0f891
+
c0f891
+
c0f891
+  local RES="$(mdadm -E --export $dev0 | grep MD_NAME)"
c0f891
+  if [[ "$?" != "0" ]]; then
c0f891
+    echo "Cannot get metadata from $dev0."
c0f891
+    exit 1
c0f891
+  fi
c0f891
+
c0f891
+  local EXPECTED="MD_NAME=$(hostname):$WANTED_NAME"
c0f891
+  if [[ "$RES" != "$EXPECTED" ]]; then
c0f891
+    echo "$RES doesn't match $EXPECTED."
c0f891
+    exit 1
c0f891
+  fi
c0f891
+}
c0f891
+
c0f891
+function _create() {
c0f891
+  local DEVNAME=$1
c0f891
+  local NAME=$2
c0f891
+
c0f891
+  if [[ -z "$NAME" ]]; then
c0f891
+    mdadm -CR "$DEVNAME" -l0 -n 1 $dev0 --force
c0f891
+  else
c0f891
+    mdadm -CR "$DEVNAME" --name="$NAME" -l0 -n 1 $dev0 --force
c0f891
+  fi
c0f891
+
c0f891
+  if [[ "$?" != "0" ]]; then
c0f891
+    echo "Cannot create device."
c0f891
+    exit 1
c0f891
+  fi
c0f891
+}
c0f891
+
c0f891
+# The most trivial case.
c0f891
+_create "/dev/md/name"
c0f891
+_verify "/dev/md127" "name" "name"
c0f891
+mdadm -S "/dev/md127"
c0f891
+
c0f891
+_create "name"
c0f891
+_verify "/dev/md127" "name" "name"
c0f891
+mdadm -S "/dev/md127"
c0f891
+
c0f891
+# Use 'mdX' as name.
c0f891
+_create "/dev/md/md0"
c0f891
+_verify "/dev/md127" "md0" "md0"
c0f891
+mdadm -S "/dev/md127"
c0f891
+
c0f891
+_create "md0"
c0f891
+_verify "/dev/md127" "md0" "md0"
c0f891
+mdadm -S "/dev/md127"
c0f891
+
c0f891
+# <devnode> is used to create MD_DEVNAME but, name is used to create MD_NAME.
c0f891
+_create "/dev/md/devnode" "name"
c0f891
+_verify "/dev/md127" "devnode" "name"
c0f891
+mdadm -S "/dev/md127"
c0f891
+
c0f891
+_create "devnode" "name"
c0f891
+_verify "/dev/md127" "devnode" "name"
c0f891
+mdadm -S "/dev/md127"
c0f891
+
c0f891
+# Devnode points to /dev/ directory. MD_DEVNAME doesn't exist.
c0f891
+_create "/dev/md0"
c0f891
+_verify "/dev/md0" "empty" "0"
c0f891
+mdadm -S "/dev/md0"
c0f891
+
c0f891
+# Devnode points to /dev/ directory and name is set.
c0f891
+_create "/dev/md0" "name"
c0f891
+_verify "/dev/md0" "empty" "name"
c0f891
+mdadm -S "/dev/md0"
c0f891
-- 
37f2b0
2.38.1
c0f891