From: James Simmons Date: Tue, 11 Jul 2023 17:28:13 +0000 (-0400) Subject: LU-16663 tests: use python to compare YAML files X-Git-Tag: 2.15.57~20 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F07%2F51507%2F6;p=fs%2Flustre-release.git 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 --- 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)" +}