mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-22 22:21:10 +02:00
Command-line override of default SSH connection timeout/attempts.
The previous implementation fixed a number of SSH connection options, including the connect request timeout (-o ConnectTimeout) and connection attempts (-o ConnectionAttempts). These values are unreasonably high when developing tests that do not require SSH at all. * Add two command-line arguments for these options. * Substitute the use of a fixed environment variable (SSH_CONNECT_SETTINGS) for a function call, which can populate SSH options based on command-line argument values. Callers can still fix the settings to their liking by assigning a value to SSH_CONNECT_SETTINGS. * Defaults kept the same. BUG=None TEST=Dependent scripts (like run_remote_tests.sh) running properly and responding to timeout/reattempt value changes. Change-Id: I23805b78ffa6ffc743c0ddae98334eee26bd1e5e Reviewed-on: https://gerrit.chromium.org/gerrit/31608 Reviewed-by: Mike Frysinger <vapier@chromium.org> Reviewed-by: Chris Sosa <sosa@chromium.org> Commit-Ready: Gilad Arnold <garnold@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org>
This commit is contained in:
parent
eb7ccc33b3
commit
2ff2f11d8c
@ -12,14 +12,33 @@ DEFINE_string private_key "$DEFAULT_PRIVATE_KEY" \
|
||||
"Private key of root account on remote host"
|
||||
DEFINE_integer ssh_port 22 \
|
||||
"SSH port of the remote machine running Chromium OS instance"
|
||||
DEFINE_integer ssh_connect_timeout 30 \
|
||||
"SSH connect timeout in seconds"
|
||||
DEFINE_integer ssh_connection_attempts 4 \
|
||||
"SSH connection attempts"
|
||||
|
||||
SSH_CONNECT_SETTINGS="-o Protocol=2 -o ConnectTimeout=30 \
|
||||
-o ConnectionAttempts=4 -o ServerAliveInterval=10 \
|
||||
-o ServerAliveCountMax=3 -o StrictHostKeyChecking=no"
|
||||
ssh_connect_settings() {
|
||||
if [[ -n "$SSH_CONNECT_SETTINGS" ]]; then
|
||||
# If connection settings were fixed in an environment variable, just return
|
||||
# those values.
|
||||
echo -n "$SSH_CONNECT_SETTINGS"
|
||||
else
|
||||
# Otherwise, return the default (or user overridden) settings.
|
||||
local settings=(
|
||||
"Protocol=2"
|
||||
"ConnectTimeout=${FLAGS_ssh_connect_timeout}"
|
||||
"ConnectionAttempts=${FLAGS_ssh_connection_attempts}"
|
||||
"ServerAliveInterval=10"
|
||||
"ServerAliveCountMax=3"
|
||||
"StrictHostKeyChecking=no"
|
||||
)
|
||||
printf -- '-o %s ' "${settings[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Copies $1 to $2 on remote host
|
||||
remote_cp_to() {
|
||||
REMOTE_OUT=$(scp -P ${FLAGS_ssh_port} $SSH_CONNECT_SETTINGS \
|
||||
REMOTE_OUT=$(scp -P ${FLAGS_ssh_port} $(ssh_connect_settings) \
|
||||
-o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY $1 \
|
||||
root@$FLAGS_remote:$2)
|
||||
return ${PIPESTATUS[0]}
|
||||
@ -28,13 +47,13 @@ remote_cp_to() {
|
||||
# Copies a list of remote files specified in file $1 to local location
|
||||
# $2. Directory paths in $1 are collapsed into $2.
|
||||
remote_rsync_from() {
|
||||
rsync -e "ssh -p ${FLAGS_ssh_port} $SSH_CONNECT_SETTINGS \
|
||||
rsync -e "ssh -p ${FLAGS_ssh_port} $(ssh_connect_settings) \
|
||||
-o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY" \
|
||||
--no-R --files-from=$1 root@${FLAGS_remote}:/ $2
|
||||
}
|
||||
|
||||
_remote_sh() {
|
||||
REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} $SSH_CONNECT_SETTINGS \
|
||||
REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} $(ssh_connect_settings) \
|
||||
-o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY \
|
||||
root@$FLAGS_remote "$@")
|
||||
return ${PIPESTATUS[0]}
|
||||
@ -54,7 +73,7 @@ remote_sh() {
|
||||
}
|
||||
|
||||
remote_sh_raw() {
|
||||
ssh -p ${FLAGS_ssh_port} $SSH_CONNECT_SETTINGS \
|
||||
ssh -p ${FLAGS_ssh_port} $(ssh_connect_settings) \
|
||||
-o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY \
|
||||
$EXTRA_REMOTE_SH_ARGS root@$FLAGS_remote "$@"
|
||||
return $?
|
||||
@ -123,7 +142,7 @@ _check_if_rebooted() {
|
||||
SSH_CONNECT_SETTINGS="$(sed \
|
||||
-e 's/\(ConnectTimeout\)=[0-9]*/\1=2/' \
|
||||
-e 's/\(ConnectionAttempts\)=[0-9]*/\1=2/' \
|
||||
<<<"${SSH_CONNECT_SETTINGS}")"
|
||||
<<<"$(ssh_connect_settings)")"
|
||||
remote_sh_allow_changed_host_key -q -- '[ ! -e /tmp/awaiting_reboot ]'
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user