From 80960d7a64409bce357baaae43d66e22c7ece79f Mon Sep 17 00:00:00 2001 From: Sylvia Moss Date: Mon, 10 Aug 2020 18:16:19 +0200 Subject: [PATCH] Fix vsphere boot command and check for context cancelation when waiting for ip (#9739) --- builder/vsphere/common/step_boot_command.go | 7 ++++++- builder/vsphere/common/step_wait_for_ip.go | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/builder/vsphere/common/step_boot_command.go b/builder/vsphere/common/step_boot_command.go index c9cc2845b..4ad4a760c 100644 --- a/builder/vsphere/common/step_boot_command.go +++ b/builder/vsphere/common/step_boot_command.go @@ -87,11 +87,16 @@ func (s *StepBootCommand) Run(ctx context.Context, state multistep.StateBag) mul keyShift = down } + shift := down + if keyShift { + shift = keyShift + } + _, err := vm.TypeOnKeyboard(driver.KeyInput{ Scancode: code, Ctrl: keyCtrl, Alt: keyAlt, - Shift: keyShift, + Shift: shift, }) if err != nil { return fmt.Errorf("error typing a boot command (code, down) `%d, %t`: %w", code, down, err) diff --git a/builder/vsphere/common/step_wait_for_ip.go b/builder/vsphere/common/step_wait_for_ip.go index 3c05916b3..7ade58c8f 100644 --- a/builder/vsphere/common/step_wait_for_ip.go +++ b/builder/vsphere/common/step_wait_for_ip.go @@ -140,6 +140,14 @@ loop: if err != nil { return "", err } + + // Check for ctx cancellation to avoid printing any IP logs at the timeout + select { + case <-ctx.Done(): + return "", fmt.Errorf("IP wait cancelled") + default: + } + if prevIp == "" || prevIp != ip { if prevIp == "" { log.Printf("VM IP aquired: %s", ip)