Merge pull request #7553 from hashicorp/fix_7404

[WIP] add 30 minute timeout for destroying a VM
This commit is contained in:
Megan Marsh 2019-05-01 12:13:00 -07:00 committed by GitHub
commit c1d69b1f20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package common
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"time" "time"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
@ -66,12 +67,19 @@ func (s *StepRegister) Cleanup(state multistep.StateBag) {
ui.Error(fmt.Sprintf("Error destroying VM: %s", err)) ui.Error(fmt.Sprintf("Error destroying VM: %s", err))
} }
// Wait for the machine to actually destroy // Wait for the machine to actually destroy
start := time.Now()
for { for {
destroyed, _ := remoteDriver.IsDestroyed() destroyed, err := remoteDriver.IsDestroyed()
if destroyed { if destroyed {
break break
} }
log.Printf("error destroying vm: %s", err)
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
if time.Since(start) >= time.Duration(30*time.Minute) {
ui.Error("Error unregistering VM; timed out. You may " +
"need to manually clean up your machine")
break
}
} }
} }
} }