Use config StateTimeout for DigitalOcean unlock and off transitions. (#3444)

Use config StateTimeout for DigitalOcean unlock and off transitions.
When DigitalOcean's API is responding slowly, the hardcoded timeouts are too short.
This commit is contained in:
Toby Jaffey 2016-08-14 20:12:30 +01:00 committed by Rickard von Essen
parent 936aaa0889
commit 37ef03c41c
2 changed files with 4 additions and 4 deletions

View File

@ -3,7 +3,6 @@ package digitalocean
import (
"fmt"
"log"
"time"
"github.com/digitalocean/godo"
"github.com/mitchellh/multistep"
@ -50,7 +49,7 @@ func (s *stepPowerOff) Run(state multistep.StateBag) multistep.StepAction {
}
// Wait for the droplet to become unlocked for future steps
if err := waitForDropletUnlocked(client, dropletId, 4*time.Minute); err != nil {
if err := waitForDropletUnlocked(client, dropletId, c.StateTimeout); err != nil {
// If we get an error the first time, actually report it
err := fmt.Errorf("Error powering off droplet: %s", err)
state.Put("error", err)

View File

@ -14,6 +14,7 @@ type stepShutdown struct{}
func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*godo.Client)
c := state.Get("config").(Config)
ui := state.Get("ui").(packer.Ui)
dropletId := state.Get("droplet_id").(int)
@ -63,7 +64,7 @@ func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
}
}()
err = waitForDropletState("off", dropletId, client, 2*time.Minute)
err = waitForDropletState("off", dropletId, client, c.StateTimeout)
if err != nil {
// If we get an error the first time, actually report it
err := fmt.Errorf("Error shutting down droplet: %s", err)
@ -72,7 +73,7 @@ func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
if err := waitForDropletUnlocked(client, dropletId, 4*time.Minute); err != nil {
if err := waitForDropletUnlocked(client, dropletId, c.StateTimeout); err != nil {
// If we get an error the first time, actually report it
err := fmt.Errorf("Error shutting down droplet: %s", err)
state.Put("error", err)