diff mbox series

[06/19] mdadm/tests: names_template enhance

Message ID 20240522085056.54818-7-xni@redhat.com (mailing list archive)
State Accepted
Headers show
Series mdadm/tests: enhance/fix regression cases | expand

Commit Message

Xiao Ni May 22, 2024, 8:50 a.m. UTC
For super1, if the length of hostname is >= 32, it doesn't add hostname
in metadata name. Fix this problem by checking the length of hostname.
Because other cases may use need to check this, so do the check in
do_setup.

And this patch adds a check if link /dev/md/name exists.

Signed-off-by: Xiao Ni <xni@redhat.com>
---
 test                           |  5 +++++
 tests/func.sh                  | 13 +++++++++++++
 tests/templates/names_template | 14 ++++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)

Comments

Mariusz Tkaczyk May 23, 2024, 2:37 p.m. UTC | #1
On Wed, 22 May 2024 16:50:43 +0800
Xiao Ni <xni@redhat.com> wrote:

> For super1, if the length of hostname is >= 32, it doesn't add hostname
> in metadata name. Fix this problem by checking the length of hostname.
> Because other cases may use need to check this, so do the check in
> do_setup.
> 
> And this patch adds a check if link /dev/md/name exists.
> 
> Signed-off-by: Xiao Ni <xni@redhat.com>
> ---
LGTM but I cannot apply this due to conflict after omitting 04.

Thanks,
Mariusz
diff mbox series

Patch

diff --git a/test b/test
index 3da53f871122..814ce1992b0c 100755
--- a/test
+++ b/test
@@ -11,6 +11,11 @@  system_speed_limit_min=0
 test_speed_limit_min=100
 test_speed_limit_max=500
 devlist=
+# If super1 metadata name doesn't have the same hostname with machine,
+# it's treated as foreign.
+# For example, /dev/md0 is created, stops it, then assemble it, the
+# device node will be /dev/md127 (127 is choosed by mdadm autumatically)
+is_foreign="no"
 
 savelogs=0
 exitonerror=1
diff --git a/tests/func.sh b/tests/func.sh
index 221cff158f8c..cfe83e552a2a 100644
--- a/tests/func.sh
+++ b/tests/func.sh
@@ -153,6 +153,18 @@  restore_system_speed_limit() {
 	echo $system_speed_limit_max > /proc/sys/dev/raid/speed_limit_max
 }
 
+is_raid_foreign() {
+
+	# If the length of hostname is >= 32, super1 doesn't use
+	# hostname in metadata
+	hostname=$(hostname)
+	if [ `expr length $(hostname)` -lt 32 ]; then
+		is_foreign="no"
+	else
+		is_foreign="yes"
+	fi
+}
+
 do_setup() {
 	trap cleanup 0 1 3 15
 	trap ctrl_c 2
@@ -232,6 +244,7 @@  do_setup() {
 	[ -f /proc/mdstat ] || modprobe md_mod
 	echo 0 > /sys/module/md_mod/parameters/start_ro
 	record_system_speed_limit
+	is_raid_foreign
 }
 
 # check various things
diff --git a/tests/templates/names_template b/tests/templates/names_template
index 1b6cd14bf51d..88ad5b8c6b38 100644
--- a/tests/templates/names_template
+++ b/tests/templates/names_template
@@ -30,6 +30,7 @@  function names_verify() {
 	local DEVNODE_NAME="$1"
 	local WANTED_LINK="$2"
 	local WANTED_NAME="$3"
+	local EXPECTED=""
 
 	local RES="$(mdadm -D --export $DEVNODE_NAME | grep MD_DEVNAME)"
 	if [[ "$?" != "0" ]]; then
@@ -38,7 +39,12 @@  function names_verify() {
 	fi
 
 	if [[ "$WANTED_LINK" != "empty" ]]; then
-		local EXPECTED="MD_DEVNAME=$WANTED_LINK"
+		EXPECTED="MD_DEVNAME=$WANTED_LINK"
+
+		if [ ! -b /dev/md/$WANTED_LINK ]; then
+			echo "/dev/md/$WANTED_LINK doesn't exit"
+			exit 1
+		fi
 	fi
 
 	if [[ "$RES" != "$EXPECTED" ]]; then
@@ -52,7 +58,11 @@  function names_verify() {
 		exit 1
 	fi
 
-	local EXPECTED="MD_NAME=$(hostname):$WANTED_NAME"
+	if [ $is_foreign == "no" ]; then
+		EXPECTED="MD_NAME=$(hostname):$WANTED_NAME"
+	else
+		EXPECTED="MD_NAME=$WANTED_NAME"
+	fi
 	if [[ "$RES" != "$EXPECTED" ]]; then
 		echo "$RES doesn't match $EXPECTED."
 		exit 1