Whamcloud - gitweb
LU-16663 tests: use python to compare YAML files 07/51507/6
authorJames Simmons <jsimmons@infradead.org>
Tue, 11 Jul 2023 17:28:13 +0000 (13:28 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 27 Jul 2023 07:20:19 +0000 (07:20 +0000)
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 <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51507
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Feng Lei <flei@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/tests/sanity-lnet.sh
lustre/tests/test-framework.sh

index acaf44b..37db599 100755 (executable)
@@ -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:"
index 2e937e7..d68eb37 100755 (executable)
@@ -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)"
+}