cros_vm_lib: Allow custom private key for ssh_ping
Since CL:286935, test ssh keys can be generated at build time, instead of
copying the static 'testing_rsa'. cros_vm_lib, especially its call to
'ssh_ping', needs to be extended to take a private key as an argument.
BUG=brillo:1200
TEST=Trybot run with rambi-pre-cq, and a trybot run with a build that has the
USE flag 'generated_key' enabled, i.e., a generated private key instead of the
default key will be used for ssh.
CQ-DEPEND=CL:296832
Change-Id: I04e60367f9799d02877377e39ad675af358322c4
Reviewed-on: https://chromium-review.googlesource.com/296723
Commit-Ready: Daniel Wang <wonderfly@google.com>
Tested-by: Daniel Wang <wonderfly@google.com>
Reviewed-by: Simran Basi <sbasi@chromium.org>
diff --git a/lib/cros_vm_lib.sh b/lib/cros_vm_lib.sh
index 8a67179..6e28543 100644
--- a/lib/cros_vm_lib.sh
+++ b/lib/cros_vm_lib.sh
@@ -4,6 +4,9 @@
#
# Common vm functions for use in crosutils.
+DEFAULT_PRIVATE_KEY="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts/\
+ssh_keys/testing_rsa"
+
DEFINE_string kvm_pid "" \
"Use this pid file. If it exists and is set, use the vm specified by pid."
DEFINE_boolean copy ${FLAGS_FALSE} "Copy the image file before starting the VM."
@@ -14,6 +17,8 @@
"This option is used for testing Google Compute Engine-compatible images."
DEFINE_boolean snapshot ${FLAGS_FALSE} "Don't commit changes to image."
DEFINE_integer ssh_port 9222 "Port to tunnel ssh traffic over."
+DEFINE_string ssh_private_key "${DEFAULT_PRIVATE_KEY}" \
+ "Path to the private key to use to ssh into test image as the root user."
DEFINE_string vnc "" "VNC Server to display to instead of SDL "\
"(e.g. pass ':1' to listen on 0.0.0.0:5901)."
@@ -241,9 +246,9 @@
fi
"${cmd}" \
--ssh_port=${FLAGS_ssh_port} \
+ --private_key=${FLAGS_ssh_private_key} \
--remote=127.0.0.1 >&2
}
-
# Tries to ssh into live image $1 times. After first failure, a try involves
# shutting down and restarting kvm.
retry_until_ssh() {
@@ -265,6 +270,7 @@
stop_kvm() {
if [ "${FLAGS_persist}" -eq "${FLAGS_TRUE}" ]; then
echo "Persist requested. Use --ssh_port ${FLAGS_ssh_port} " \
+ "--ssh_private_key ${FLAGS_ssh_private_key} " \
"--kvm_pid ${KVM_PID_FILE} to re-connect to it." >&2
else
echo "Stopping the KVM instance" >&2