Whamcloud - gitweb
LU-15559 tests: add do_node_vp() and do_facet_vp() 35/46535/4
authorJohn L. Hammond <jhammond@whamcloud.com>
Wed, 16 Feb 2022 17:54:26 +0000 (11:54 -0600)
committerOleg Drokin <green@whamcloud.com>
Sat, 11 Jun 2022 05:35:12 +0000 (05:35 +0000)
Add new test-framework functions (do_node_vp() and do_facet_vp())
which carefully escape and quote command lines for execution on the
local or remote node. Add sanityn test_0 to verify.

Test-Parameters: trivial env=ONLY="0" testlist=sanityn
Signed-off-by: John L. Hammond <jhammond@whamcloud.com>
Change-Id: Ic491b0148e6ef11ecd0b3ccce983afcf4d1300e5
Reviewed-on: https://review.whamcloud.com/46535
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanityn.sh
lustre/tests/test-framework.sh

index 160a234..d2d458b 100755 (executable)
@@ -54,6 +54,34 @@ dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
 
 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
 
+test_0() {
+       local client2=${CLIENT2:-$HOSTNAME}
+       local tmp=$(mktemp)
+
+       printf 'a b\n' > $tmp
+
+       do_node_vp "$HOSTNAME" printf 'a b\n' |
+       diff $tmp - || error "do_node_vp mismatch"
+
+       do_node_vp "$client2" printf 'a b\n' |
+       diff $tmp - || error "do_node_vp mismatch"
+
+       do_facet_vp mds1 printf 'a b\n' |
+       diff $tmp - || error "do_facet_vp mismatch"
+
+       printf '%s' 1 2 3 4 5 6 7 8 \ 9 10 ' ' '"' "'" \! \' \( \) $'\n' > $tmp
+
+       do_node_vp "$HOSTNAME" printf '%s' 1 2 3 4 5 6 7 8 \ 9 10 ' ' '"' "'" \! \' \( \) $'\n' |
+       diff $tmp - || error "do_node_vp mismatch"
+
+       do_node_vp "$client2" printf '%s' 1 2 3 4 5 6 7 8 \ 9 10 ' ' '"' "'" \! \' \( \) $'\n' |
+       diff $tmp - || error "do_node_vp mismatch"
+
+       do_facet_vp mds1 printf '%s' 1 2 3 4 5 6 7 8 \ 9 10 ' ' '"' "'" \! \' \( \) $'\n' |
+       diff $tmp - || error "do_facet_vp mismatch"
+}
+run_test 0 "do_node_vp() and do_facet_vp() do the right thing"
+
 test_1() {
        touch $DIR1/$tfile
        [ -f $DIR2/$tfile ] || error "Check create"
index 9406876..6438aec 100755 (executable)
@@ -4242,6 +4242,36 @@ do_node() {
        return ${PIPESTATUS[0]}
 }
 
+##
+# Execute exact command line on host
+#
+# The \a host may be on a local or remote node, which is determined at
+# the time the command is run. Does careful argument quotation to
+# ensure that the exact command line is executed without any globbing,
+# substitution, or shell interpretation on the remote side. Does not
+# support --verbose or --quiet. Does not include "$host: " prefixes on
+# output. See also do_facet_vp().
+#
+# usage: do_node_vp "$host" "$command" "$arg"...
+do_node_vp() {
+       local host="$1"
+       shift
+
+       if [[ "$host" == "$HOSTNAME" ]]; then
+               sh -c "$(printf -- ' %q' "$@")"
+               return $?
+       fi
+
+       if [[ "${PDSH}" != *pdsh* || "${PDSH}" != *-S* ]]; then
+               echo "cannot run '$*' on host '${host}' with PDSH='${PDSH}'" >&2
+               return 128
+       fi
+
+       # -N Disable hostname: prefix on lines of output.
+
+       $PDSH "${host}" -N "cd $RPWD; PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; export LUSTRE=$RLUSTRE; $(printf -- ' %q' "$@")"
+}
+
 single_local_node () {
        [ "$1" = "$HOSTNAME" ]
 }
@@ -4349,6 +4379,30 @@ do_facet() {
        do_node $verbose $quiet $host "$@"
 }
 
+##
+# Execute exact command line on the host of a facet
+#
+# The \a facet (service) may be on a local or remote node, which is
+# determined at the time the command is run. Does careful argument
+# quotation to ensure that the exact command line is executed without
+# any globbing, substitution, or shell interpretation on the remote
+# side. Does not support --verbose or --quiet. Does not include
+# "$host: " prefixes on output.
+#
+# usage: do_facet_vp "$facet" "$command" "$arg"...
+do_facet_vp() {
+       local facet="$1"
+       local host=$(facet_active_host "$facet")
+       shift
+
+       if [[ -z "$host" ]]; then
+               echo "no host defined for facet ${facet}" >&2
+               exit 1
+       fi
+
+       do_node_vp "$host" "$@"
+}
+
 # Function: do_facet_random_file $FACET $FILE $SIZE
 # Creates FILE with random content on the given FACET of given SIZE