Skip to content

Commit

Permalink
fixup! tests: revert remote.wait-for changes
Browse files Browse the repository at this point in the history
Signed-off-by: Zeyad Gouda <[email protected]>
  • Loading branch information
ZeyadYasser committed Feb 4, 2025
1 parent 1d1a2df commit 685389a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 40 deletions.
43 changes: 6 additions & 37 deletions tests/lib/external/snapd-testing-tools/remote/remote.wait-for
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -xe
#!/bin/bash -e

# The default values have been selected trying to match with most of
# the wait times in the tests and also trying to follow common sense.
Expand All @@ -17,7 +17,7 @@ show_help() {
echo "usage: remote.wait-for ssh [--wait WAIT] [-n|--attempts ATTEMPTS]"
echo " remote.wait-for no-ssh [--wait WAIT] [-n|--attempts ATTEMPTS]"
echo " remote.wait-for snap-command [--wait WAIT] [-n|--attempts ATTEMPTS]"
echo " remote.wait-for reboot [--wait WAIT] [-n|--attempts ATTEMPTS] [--expect-passphrase PASSPHRASE] [--log-file PATH]"
echo " remote.wait-for reboot [--wait WAIT] [-n|--attempts ATTEMPTS]"
echo " remote.wait-for device-initialized [--wait WAIT] [-n|--attempts ATTEMPTS]"
echo " remote.wait-for refresh [--wait WAIT] [-n|--attempts ATTEMPTS]"
echo ""
Expand Down Expand Up @@ -99,9 +99,7 @@ wait_for_reconnect_ssh() {
wait_for_reboot() {
local attempts=${1:-$DEFAULT_WAIT_FOR_REBOOT_ATTEMPTS}
local wait=${2:-$DEFAULT_WAIT_FOR_REBOOT_WAIT}
local expect_passphrase=${3:-}
local log_file=${4:-}
local initial_boot_id=$5
local initial_boot_id=$3
local last_boot_id

echo "remote.wait-for: waiting for reboot"
Expand All @@ -112,24 +110,6 @@ wait_for_reboot() {
return
fi

if [ -n "$expect_passphrase" ]; then
if [ ! -f "$log_file" ]; then
echo "remote.wait-for --expect-passphrase without passing an existing --log-file"
return 1
fi
while [ "$attempts" -ge 0 ]; do
echo -n '.'
attempts=$(( attempts - 1 ))
# Wait for passphrase prompt from serial log file.
if MATCH "Please enter the passphrase" < ${log_file}; then
# Enter passphrase to continue boot.
echo "$expect_passphrase" | netcat -N localhost 7777
break
fi
sleep "$wait"
done
fi

while [ "$attempts" -ge 0 ]; do
echo -n '.'
attempts=$(( attempts - 1 ))
Expand All @@ -143,10 +123,7 @@ wait_for_reboot() {
done

echo ""
if [ -z "$last_boot_id" ]; then
echo "remote.wait-for: could not get last boot id"
return 1
elif [ "$last_boot_id" != "$initial_boot_id" ]; then
if [ "$last_boot_id" != "$initial_boot_id" ]; then
echo "remote.wait-for: reboot completed"
else
echo "remote.wait-for: boot id did not change"
Expand Down Expand Up @@ -264,7 +241,7 @@ main() {
exit
fi

local action wait attempts expect_passphrase log_file others
local action wait attempts others
case "$1" in
-h|--help)
show_help
Expand Down Expand Up @@ -316,14 +293,6 @@ main() {
attempts=$2
shift 2
;;
--expect-passphrase)
expect_passphrase="$2"
shift 2
;;
--log-file)
log_file="$2"
shift 2
;;
*)
if [ -z "$others" ]; then
others=$1
Expand All @@ -335,7 +304,7 @@ main() {
esac
done

"$action" "$attempts" "$wait" "$expect_passphrase" "$log_file" "$others"
"$action" "$attempts" "$wait" "$others"
}

main "$@"
11 changes: 8 additions & 3 deletions tests/nested/manual/passphrase-support-on-hybrid/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,16 @@ execute: |
remote.exec test -f /run/reboot-required
remote.exec cat /run/reboot-required.pkgs | MATCH "snap:${snap_name}"
local log_file="$NESTED_LOGS_DIR"/serial.log
# Clear old log file to avoid matching passphrase prompt from previous boot.
echo "" > "$log_file"
echo "" > "$NESTED_LOGS_DIR"/serial.log
remote.exec sudo reboot || true
remote.wait-for reboot --wait 1 -n 200 --expect-passphrase "$PASSPHRASE" --log-file "$log_file" "$boot_id"
# Wait for passphrase prompt
retry -n 120 --wait 1 sh -c "MATCH \"Please enter the passphrase\" < ${NESTED_LOGS_DIR}/serial.log"
# Enter passphrase to continue boot
echo "$PASSPHRASE" | netcat -N localhost 7777
remote.wait-for reboot --wait 1 -n 100 "$boot_id"
remote.exec sudo snap watch --last=install
}
# Ensure update-notifier-common is installed so that reboot notification works.
Expand Down

0 comments on commit 685389a

Please sign in to comment.