Whamcloud - gitweb
LU-16183 test: sanity-hsm/70 should detect python 47/49247/3
authorMinh Diep <mdiep@whamcloud.com>
Mon, 3 Oct 2022 18:22:47 +0000 (11:22 -0700)
committerOleg Drokin <green@whamcloud.com>
Tue, 6 Dec 2022 02:53:33 +0000 (02:53 +0000)
Check for python2 and python3 explicitly, since the
generic python command does not exist in newer distros.

Lustre-change: https://review.whamcloud.com/48737
Lustre-commit: c24a38b583cad8e3a92c1d74e8e56e80f07c67b5

Test-Parameters: env=SLOW=yes,ENABLE_QUOTA=yes \
clientdistro=sles15sp3 testlist=sanity-hsm
Test-Parameters: env=SLOW=yes,ENABLE_QUOTA=yes \
clientdistro=el7.9 testlist=sanity-hsm

Change-Id: I35bbe15fd298341870ad4f1ab5976e82ccc84667
Signed-off-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-by: Charlie Olmstead <charlie@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49247
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity-hsm.sh

index 1830789..521cf45 100755 (executable)
@@ -429,12 +429,20 @@ parse_json_event() {
        local raw_event=$1
 
        # python2.6 in EL6 includes an internal json module
+       local PYTHON='python'
        local json_parser='import json; import fileinput;'
-       json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
+       json_parser+=' print("\n".join(["local %s=\"%s\"" % tuple for tuple in '
        json_parser+='json.loads([line for line in '
-       json_parser+='fileinput.input()][0]).items()])'
+       json_parser+='fileinput.input()][0]).items()]))'
 
-       echo $raw_event | python -c "$json_parser"
+       # check if python/python2/python3 is available
+       if ! which $PYTHON > /dev/null 2>&1 ; then
+               PYTHON='python2'
+               if ! which $PYTHON > /dev/null 2>&1 ; then
+                       PYTHON='python3'
+               fi
+       fi
+       echo $raw_event | $PYTHON -c "$json_parser"
 }
 
 get_agent_by_uuid_mdt() {