Commit da4dfbcd authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/digitalocean: Properly return errors

parent 868bb9c6
...@@ -184,6 +184,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -184,6 +184,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
b.runner.Run(state) b.runner.Run(state)
// If there was an error, return that
if rawErr, ok := state["error"]; ok {
return nil, rawErr.(error)
}
if _, ok := state["snapshot_name"]; !ok { if _, ok := state["snapshot_name"]; !ok {
log.Println("Failed to find snapshot_name in state. Bug?") log.Println("Failed to find snapshot_name in state. Bug?")
return nil, nil return nil, nil
......
...@@ -2,6 +2,7 @@ package digitalocean ...@@ -2,6 +2,7 @@ package digitalocean
import ( import (
gossh "code.google.com/p/go.crypto/ssh" gossh "code.google.com/p/go.crypto/ssh"
"errors"
"fmt" "fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/communicator/ssh" "github.com/mitchellh/packer/communicator/ssh"
...@@ -26,7 +27,9 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) multistep.StepAction ...@@ -26,7 +27,9 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) multistep.StepAction
keyring := &ssh.SimpleKeychain{} keyring := &ssh.SimpleKeychain{}
err := keyring.AddPEMKey(privateKey) err := keyring.AddPEMKey(privateKey)
if err != nil { if err != nil {
ui.Say(fmt.Sprintf("Error setting up SSH config: %s", err)) err := fmt.Errorf("Error setting up SSH config: %s", err)
state["error"] = err
ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
...@@ -87,7 +90,9 @@ ConnectWaitLoop: ...@@ -87,7 +90,9 @@ ConnectWaitLoop:
// We connected. Just break the loop. // We connected. Just break the loop.
break ConnectWaitLoop break ConnectWaitLoop
case <-timeout: case <-timeout:
ui.Error("Timeout while waiting to connect to SSH.") err := errors.New("Timeout waiting for SSH to become available.")
state["error"] = err
ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
if _, ok := state[multistep.StateCancelled]; ok { if _, ok := state[multistep.StateCancelled]; ok {
...@@ -103,7 +108,9 @@ ConnectWaitLoop: ...@@ -103,7 +108,9 @@ ConnectWaitLoop:
} }
if err != nil { if err != nil {
ui.Error(fmt.Sprintf("Error connecting to SSH: %s", err)) err := fmt.Errorf("Error connecting to SSH: %s", err)
state["error"] = err
ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
......
...@@ -27,8 +27,9 @@ func (s *stepCreateDroplet) Run(state map[string]interface{}) multistep.StepActi ...@@ -27,8 +27,9 @@ func (s *stepCreateDroplet) Run(state map[string]interface{}) multistep.StepActi
// Create the droplet based on configuration // Create the droplet based on configuration
dropletId, err := client.CreateDroplet(name, c.SizeID, c.ImageID, c.RegionID, sshKeyId) dropletId, err := client.CreateDroplet(name, c.SizeID, c.ImageID, c.RegionID, sshKeyId)
if err != nil { if err != nil {
err := fmt.Errorf("Error creating droplet: %s", err)
state["error"] = err
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
......
...@@ -46,8 +46,9 @@ func (s *stepCreateSSHKey) Run(state map[string]interface{}) multistep.StepActio ...@@ -46,8 +46,9 @@ func (s *stepCreateSSHKey) Run(state map[string]interface{}) multistep.StepActio
// Create the key! // Create the key!
keyId, err := client.CreateKey(name, pub_sshformat) keyId, err := client.CreateKey(name, pub_sshformat)
if err != nil { if err != nil {
err := fmt.Errorf("Error creating temporary SSH key: %s", err)
state["error"] = err
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
......
package digitalocean package digitalocean
import ( import (
"fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
) )
...@@ -15,16 +16,18 @@ func (s *stepDropletInfo) Run(state map[string]interface{}) multistep.StepAction ...@@ -15,16 +16,18 @@ func (s *stepDropletInfo) Run(state map[string]interface{}) multistep.StepAction
ui.Say("Waiting for droplet to become active...") ui.Say("Waiting for droplet to become active...")
err := waitForDropletState("active", dropletId, client) err := waitForDropletState("active", dropletId, client)
if err != nil { if err != nil {
err := fmt.Errorf("Error waiting for droplet to become active: %s", err)
state["error"] = err
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
// Set the IP on the state for later // Set the IP on the state for later
ip, _, err := client.DropletStatus(dropletId) ip, _, err := client.DropletStatus(dropletId)
if err != nil { if err != nil {
err := fmt.Errorf("Error retrieving droplet ID: %s", err)
state["error"] = err
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
......
package digitalocean package digitalocean
import ( import (
"fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
...@@ -25,6 +26,8 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction { ...@@ -25,6 +26,8 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction {
err := client.PowerOffDroplet(dropletId) err := client.PowerOffDroplet(dropletId)
if err != nil { if err != nil {
err := fmt.Errorf("Error powering off droplet: %s", err)
state["error"] = err
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
...@@ -32,8 +35,9 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction { ...@@ -32,8 +35,9 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction {
ui.Say("Waiting for droplet to power off...") ui.Say("Waiting for droplet to power off...")
err = waitForDropletState("off", dropletId, client) err = waitForDropletState("off", dropletId, client)
if err != nil { if err != nil {
err := fmt.Errorf("Error waiting for droplet to become 'off': %s", err)
state["error"] = err
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
......
package digitalocean package digitalocean
import ( import (
"errors"
"fmt" "fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
...@@ -18,6 +19,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction { ...@@ -18,6 +19,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
ui.Say(fmt.Sprintf("Creating snapshot: %v", c.SnapshotName)) ui.Say(fmt.Sprintf("Creating snapshot: %v", c.SnapshotName))
err := client.CreateSnapshot(dropletId, c.SnapshotName) err := client.CreateSnapshot(dropletId, c.SnapshotName)
if err != nil { if err != nil {
err := fmt.Errorf("Error creating snapshot: %s", err)
state["error"] = err
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
...@@ -25,6 +28,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction { ...@@ -25,6 +28,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
ui.Say("Waiting for snapshot to complete...") ui.Say("Waiting for snapshot to complete...")
err = waitForDropletState("active", dropletId, client) err = waitForDropletState("active", dropletId, client)
if err != nil { if err != nil {
err := fmt.Errorf("Error waiting for snapshot to complete: %s", err)
state["error"] = err
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
...@@ -32,6 +37,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction { ...@@ -32,6 +37,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
log.Printf("Looking up snapshot ID for snapshot: %s", c.SnapshotName) log.Printf("Looking up snapshot ID for snapshot: %s", c.SnapshotName)
images, err := client.Images() images, err := client.Images()
if err != nil { if err != nil {
err := fmt.Errorf("Error looking up snapshot ID: %s", err)
state["error"] = err
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
...@@ -45,7 +52,9 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction { ...@@ -45,7 +52,9 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
} }
if imageId == 0 { if imageId == 0 {
ui.Error("Couldn't find snapshot to get the image ID. Bug?") err := errors.New("Couldn't find snapshot to get the image ID. Bug?")
state["error"] = err
ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment