From 1ea6aa842e622311406ab7a4c4acf136df6e609a Mon Sep 17 00:00:00 2001 From: James Simmons Date: Tue, 11 Jul 2023 13:28:13 -0400 Subject: [PATCH] LU-16663 tests: use python to compare YAML files For the sanity-lnet test we often compare different YAML files. This is done with diff which is the wrong tool since two YAML files that are the same can have different indentations. The libyaml maintainer states using python tools for this is the proper supported way to do this. Test-Parameters: trivial testlist=sanity-lnet Change-Id: Ie0ef623e8ec729aaad862fc3f33eb0a3b4172fad Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51507 Reviewed-by: Timothy Day Reviewed-by: Feng Lei Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lustre/tests/sanity-lnet.sh | 6 +++++- lustre/tests/test-framework.sh | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lustre/tests/sanity-lnet.sh b/lustre/tests/sanity-lnet.sh index acaf44b..37db599 100755 --- a/lustre/tests/sanity-lnet.sh +++ b/lustre/tests/sanity-lnet.sh @@ -145,7 +145,11 @@ compare_yaml_files() { local rc=0 ! [[ -e $expected ]] && echo "$expected not found" && return 1 ! [[ -e $actual ]] && echo "$actual not found" && return 1 - diff -upN ${actual} ${expected} || rc=$? + if [ verify_yaml_available ]; then + verify_compare_yaml $actual $expected || rc=$? + else + diff -upN ${actual} ${expected} || rc=$? + fi echo "Expected:" cat $expected echo "Actual:" diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 2e937e7..d68eb37 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -11303,3 +11303,7 @@ verify_yaml_available() { verify_yaml() { python3 -c "import sys, yaml; obj = yaml.safe_load(sys.stdin)" } + +verify_compare_yaml() { + python3 -c "import sys, yaml; f=open(\"$1\", \"r\"); obj1 = yaml.safe_load(f); f=open(\"$2\", \"r\"); obj2 = yaml.safe_load(f); sys.exit(obj1 != obj2)" +} -- 1.8.3.1