From 62401b72d01894f8b3888cb0e581c041faf66e7f Mon Sep 17 00:00:00 2001 From: Philip Prindeville Date: Fri, 25 Aug 2023 13:39:50 -0600 Subject: [PATCH] Always use variable substition for command Can't do a sudo inside an expect so we run the expect inside the sudo. --- test/lib.sh | 4 ++-- test/test_confirmed_commit.sh | 12 ++++++------ test/test_pagination_config.sh | 4 +++- test/test_pagination_expect.exp | 5 ++++- test/test_pagination_state.sh | 4 +++- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/test/lib.sh b/test/lib.sh index 6d43d2a2..7fa7b758 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -186,7 +186,7 @@ BUSER=clicon : ${clixon_cli:=clixon_cli} -: ${clixon_netconf:=$(which clixon_netconf)} +: ${clixon_netconf:=clixon_netconf} : ${clixon_restconf:=clixon_restconf} @@ -570,7 +570,7 @@ function wait_backend(){ while [[ $reply != *"]]>]]>" | clixon_netconf -qef $cfg 2> /dev/null) + reply=$(echo "]]>]]>" | $clixon_netconf -qef $cfg 2> /dev/null) # echo "reply:$reply" let i++; # echo "wait_backend $i" diff --git a/test/test_confirmed_commit.sh b/test/test_confirmed_commit.sh index 4bf0d878..f0a4a785 100755 --- a/test/test_confirmed_commit.sh +++ b/test/test_confirmed_commit.sh @@ -329,7 +329,7 @@ reset tmppipe=$(mktemp -u) mkfifo -m 600 "$tmppipe" -cat << EOF | clixon_cli -f $cfg >> /dev/null & +cat << EOF | $clixon_cli -f $cfg >> /dev/null & set table parameter eth0 commit confirmed 60 shell echo >> $tmppipe @@ -349,7 +349,7 @@ rm $tmppipe new "14. cli persistent confirmed-commit" reset -cat << EOF | clixon_cli -f $cfg >> /dev/null +cat << EOF | $clixon_cli -f $cfg >> /dev/null set table parameter eth0 commit confirmed persist a quit @@ -357,7 +357,7 @@ EOF assert_config_equals "running" "$CONFIGB" -cat << EOF | clixon_cli -f $cfg >> /dev/null +cat << EOF | $clixon_cli -f $cfg >> /dev/null set table parameter eth1 commit persist-id a confirmed persist ab quit @@ -384,7 +384,7 @@ expectpart "$($clixon_cli -lo -1 -f $cfg commit persist-id ab cancel)" 255 "no c new "18. cli persistent confirmed-commit with timeout" reset -cat << EOF | clixon_cli -f $cfg >> /dev/null +cat << EOF | $clixon_cli -f $cfg >> /dev/null set table parameter eth0 commit confirmed persist abcd 3 EOF @@ -396,13 +396,13 @@ assert_config_equals "running" "" new "19. cli persistent confirmed-commit with reset timeout" reset -cat << EOF | clixon_cli -f $cfg >> /dev/null +cat << EOF | $clixon_cli -f $cfg >> /dev/null set table parameter eth0 commit confirmed persist abcd 5 EOF assert_config_equals "running" "$CONFIGB" -cat << EOF | clixon_cli -f $cfg >> /dev/null +cat << EOF | $clixon_cli -f $cfg >> /dev/null set table parameter eth1 commit persist-id abcd confirmed persist abcdef 10 EOF diff --git a/test/test_pagination_config.sh b/test/test_pagination_config.sh index 05d56999..46a1413f 100755 --- a/test/test_pagination_config.sh +++ b/test/test_pagination_config.sh @@ -160,7 +160,9 @@ wait_backend xpath="/es:members/es:member[es:member-id=\'bob\']/es:favorites/es:uint64-numbers" new "cli show pagination config using expect" -expect ./test_pagination_expect.exp "$cfg" "$xpath" "uint64-numbers 18" "uint64-numbers 19" +sudo="sudo -g ${CLICON_USER}" ## cheat +clixon_cli_="${clixon_cli##$sudo }" +clixon_cli="$clixon_cli_" $sudo --preserve-env=clixon_cli expect ./test_pagination_expect.exp "$cfg" "$xpath" "uint64-numbers 18" "uint64-numbers 19" if [ $? -ne 0 ]; then err1 "Failed: CLI show paginate config scroll using expect" fi diff --git a/test/test_pagination_expect.exp b/test/test_pagination_expect.exp index 23c8de9d..ee7e3374 100755 --- a/test/test_pagination_expect.exp +++ b/test/test_pagination_expect.exp @@ -14,6 +14,9 @@ set stty_init "rows 20 cols 128" send_user "\nTest State paginate cli scrolling\n" +# grab $clixon_cli from environment +set clixon_cli $::env(clixon_cli) + set cfg [lindex $argv 0] set xpath [lindex $argv 1] set line1 [lindex $argv 2] @@ -21,7 +24,7 @@ set line2 [lindex $argv 3] set timeout 15 -spawn clixon_cli -f $cfg +spawn $clixon_cli -f $cfg send "show pagination xpath $xpath cli\n" diff --git a/test/test_pagination_state.sh b/test/test_pagination_state.sh index 16d22b71..10f63e8a 100755 --- a/test/test_pagination_state.sh +++ b/test/test_pagination_state.sh @@ -164,7 +164,9 @@ if [ -n "$(type expect 2> /dev/null)" ]; then testrun_start "/es:audit-logs/es:audit-log" new "CLI scroll test using expect" - expect ./test_pagination_expect.exp "$cfg" "$xpath" bob3 bob4 + sudo="sudo -g ${CLICON_USER}" ## cheat + clixon_cli_="${clixon_cli##$sudo }" + clixon_cli="$clixon_cli_" $sudo --preserve-env=clixon_cli expect ./test_pagination_expect.exp "$cfg" "$xpath" bob3 bob4 if [ $? -ne 0 ]; then err1 "Failed: CLI show paginate state scroll using expect" fi