From e5cdafa70b5e05e0670797e620e9d3e7e4244037 Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Wed, 16 Feb 2022 11:54:26 -0600 Subject: [PATCH] LU-15559 tests: add do_node_vp() and do_facet_vp() 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 Change-Id: Ic491b0148e6ef11ecd0b3ccce983afcf4d1300e5 Reviewed-on: https://review.whamcloud.com/46535 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Jian Yu Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/tests/sanityn.sh | 28 ++++++++++++++++++++++ lustre/tests/test-framework.sh | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/lustre/tests/sanityn.sh b/lustre/tests/sanityn.sh index 160a234..d2d458b 100755 --- a/lustre/tests/sanityn.sh +++ b/lustre/tests/sanityn.sh @@ -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" diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 9406876..6438aec 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -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 -- 1.8.3.1