Merge pull request #4691 from mitchellh/hyper-vshutdown

builder/hyper-v don't wait for shutdown to return.
This commit is contained in:
Matthew Hooker 2017-03-20 15:35:54 -07:00 committed by GitHub
commit 5ed4d84dc1
1 changed files with 6 additions and 11 deletions

View File

@ -4,10 +4,11 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log" "log"
"time" "time"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
) )
// This step shuts down the machine. It first attempts to do so gracefully, // This step shuts down the machine. It first attempts to do so gracefully,
@ -51,14 +52,6 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt return multistep.ActionHalt
} }
// Wait for the command to run so we can print std{err,out}
// We don't care if the command errored, since we'll notice
// if the vm didn't shut down.
cmd.Wait()
log.Printf("Shutdown stdout: %s", stdout.String())
log.Printf("Shutdown stderr: %s", stderr.String())
// Wait for the machine to actually shut down // Wait for the machine to actually shut down
log.Printf("Waiting max %s for shutdown to complete", s.Timeout) log.Printf("Waiting max %s for shutdown to complete", s.Timeout)
shutdownTimer := time.After(s.Timeout) shutdownTimer := time.After(s.Timeout)
@ -70,12 +63,14 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction {
select { select {
case <-shutdownTimer: case <-shutdownTimer:
log.Printf("Shutdown stdout: %s", stdout.String())
log.Printf("Shutdown stderr: %s", stderr.String())
err := errors.New("Timeout while waiting for machine to shut down.") err := errors.New("Timeout while waiting for machine to shut down.")
state.Put("error", err) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
default: default:
time.Sleep(150 * time.Millisecond) time.Sleep(500 * time.Millisecond)
} }
} }
} else { } else {