diff --git a/bin/cros_run_vm_test b/bin/cros_run_vm_test index 8c7f68f973..2bcdcf088c 100755 --- a/bin/cros_run_vm_test +++ b/bin/cros_run_vm_test @@ -31,8 +31,6 @@ find_common_sh . "${SCRIPT_ROOT}/lib/cros_vm_constants.sh" || \ die "Unable to load cros_vm_constants.sh" -MAX_RETRIES=3 - get_default_board DEFINE_string board "$DEFAULT_BOARD" \ @@ -88,8 +86,7 @@ done trap stop_kvm EXIT start_kvm "${FLAGS_image_path}" -info "Checking for ssh access to virtual machine." -retry_until_ssh ${MAX_RETRIES} +retry_until_ssh if [ -n "${FLAGS_verify_chrome_version}" ]; then info "Verifying version of Chrome matches what we expect." diff --git a/bin/cros_run_vm_update b/bin/cros_run_vm_update index 04ca97b959..05a1d44afb 100755 --- a/bin/cros_run_vm_update +++ b/bin/cros_run_vm_update @@ -50,6 +50,7 @@ eval set -- "${FLAGS_ARGV}" trap stop_kvm EXIT start_kvm "${FLAGS_vm_image_path}" +retry_until_ssh if [ -n "${FLAGS_update_image_path}" ]; then IMAGE_ARGS="--image=$(readlink -f ${FLAGS_update_image_path})" diff --git a/lib/cros_vm_lib.sh b/lib/cros_vm_lib.sh index 3a50a62705..1246baae39 100644 --- a/lib/cros_vm_lib.sh +++ b/lib/cros_vm_lib.sh @@ -100,10 +100,11 @@ function ssh_ping() { # shutting down and restarting kvm. function retry_until_ssh() { local can_ssh_into=1 + local max_retries=3 local retries=0 ssh_ping && can_ssh_into=0 - while [ ${can_ssh_into} -eq 1 ] && [ ${retries} -lt ${1} ]; do + while [ ${can_ssh_into} -eq 1 ] && [ ${retries} -lt ${max_retries} ]; do echo "Failed to connect to virtual machine, retrying ... " >&2 stop_kvm || echo "Could not stop kvm. Retrying anyway." >&2 start_kvm "${LIVE_VM_IMAGE}"