summaryrefslogtreecommitdiff
path: root/tests/test_common.sh
blob: f42a26a5440bea8ab42c34b361c29ca454e1cd40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh

run_ssh() {
	test -n "${SSH_KEYPATH:-}" && set -- -i "$SSH_KEYPATH" "$@"
	test -n "${SSH_PORT:-}" && set -- -p "$SSH_PORT" "$@"
	ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -l root "$@"
}

wait_ssh() {
	wait_ssh_timeout=5
	wait_ssh_ts=$(sleepenh 0 || [ $? -eq 1 ])
	for _ in $(seq 30); do
		run_ssh -o ConnectTimeout="$wait_ssh_timeout" "$@" echo success && return 0
		wait_ssh_ts=$(sleepenh "$wait_ssh_ts" "$wait_ssh_timeout" || [ $? -eq 1 ])
	done
	echo "timeout reached" >&2
	return 1
}