tests/libvm: Support SSH_CONFIG env var

When juggling multiple test VMs for different purposes, it's useful to
be able to easily e.g. `make vmcheck` a specific one by overriding the
ssh-config file to use, rather than editing the latter each time.

Closes: #1324
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2018-04-03 13:48:58 -04:00 committed by Atomic Bot
parent bd2920ad01
commit 3a1fd2c139

View File

@ -21,14 +21,15 @@
vm_setup() { vm_setup() {
export VM=${VM:-vmcheck} export VM=${VM:-vmcheck}
export SSH_CONFIG=${SSH_CONFIG:-${topsrcdir}/ssh-config}
SSHOPTS="-o User=root -o ControlMaster=auto \ SSHOPTS="-o User=root -o ControlMaster=auto \
-o ControlPath=/var/tmp/ssh-$VM-$(date +%s%N).sock \ -o ControlPath=/var/tmp/ssh-$VM-$(date +%s%N).sock \
-o ControlPersist=yes" -o ControlPersist=yes"
# If we're provided with an ssh-config, make sure we tell # If we're provided with an ssh-config, make sure we tell
# ssh to pick it up. # ssh to pick it up.
if [ -f "${topsrcdir}/ssh-config" ]; then if [ -f "${SSH_CONFIG}" ]; then
SSHOPTS="${SSHOPTS} -F ${topsrcdir}/ssh-config" SSHOPTS="${SSHOPTS} -F ${SSH_CONFIG}"
fi fi
export SSHOPTS export SSHOPTS
@ -60,8 +61,8 @@ EOF
# rsync wrapper that sets up authentication # rsync wrapper that sets up authentication
vm_raw_rsync() { vm_raw_rsync() {
local rsyncopts="ssh -o User=root" local rsyncopts="ssh -o User=root"
if [ -f ${topsrcdir}/ssh-config ]; then if [ -f "${SSH_CONFIG}" ]; then
rsyncopts="$rsyncopts -F '${topsrcdir}/ssh-config'" rsyncopts="$rsyncopts -F '${SSH_CONFIG}'"
fi fi
rsync -az --no-owner --no-group -e "$rsyncopts" "$@" rsync -az --no-owner --no-group -e "$rsyncopts" "$@"
} }
@ -81,8 +82,8 @@ vm_cmd_as() {
local user=$1; shift local user=$1; shift
# don't reuse root's ControlPath # don't reuse root's ControlPath
local sshopts="-o User=$user" local sshopts="-o User=$user"
if [ -f "${topsrcdir}/ssh-config" ]; then if [ -f "${SSH_CONFIG}" ]; then
sshopts="$sshopts -F ${topsrcdir}/ssh-config" sshopts="$sshopts -F ${SSH_CONFIG}"
fi fi
ssh $sshopts $VM "$@" ssh $sshopts $VM "$@"
} }