Commit 0a6d8ed7 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Add errors to Prepare

parent 09f5cd50
...@@ -13,13 +13,13 @@ type cmdProvisioner struct { ...@@ -13,13 +13,13 @@ type cmdProvisioner struct {
client *client client *client
} }
func (c *cmdProvisioner) Prepare(configs ...interface{}) { func (c *cmdProvisioner) Prepare(configs ...interface{}) error {
defer func() { defer func() {
r := recover() r := recover()
c.checkExit(r, nil) c.checkExit(r, nil)
}() }()
c.p.Prepare(configs...) return c.p.Prepare(configs...)
} }
func (c *cmdProvisioner) Provision(ui packer.Ui, comm packer.Communicator) { func (c *cmdProvisioner) Provision(ui packer.Ui, comm packer.Communicator) {
......
...@@ -9,7 +9,9 @@ import ( ...@@ -9,7 +9,9 @@ import (
type helperProvisioner byte type helperProvisioner byte
func (helperProvisioner) Prepare(...interface{}) {} func (helperProvisioner) Prepare(...interface{}) error {
return nil
}
func (helperProvisioner) Provision(packer.Ui, packer.Communicator) {} func (helperProvisioner) Provision(packer.Ui, packer.Communicator) {}
......
...@@ -6,7 +6,7 @@ type Provisioner interface { ...@@ -6,7 +6,7 @@ type Provisioner interface {
// Prepare is called with a set of configurations to setup the // Prepare is called with a set of configurations to setup the
// internal state of the provisioner. The multiple configurations // internal state of the provisioner. The multiple configurations
// should be merged in some sane way. // should be merged in some sane way.
Prepare(...interface{}) Prepare(...interface{}) error
// Provision is called to actually provision the machine. A UI is // Provision is called to actually provision the machine. A UI is
// given to communicate with the user, and a communicator is given that // given to communicate with the user, and a communicator is given that
......
...@@ -8,9 +8,10 @@ type TestProvisioner struct { ...@@ -8,9 +8,10 @@ type TestProvisioner struct {
provCalled bool provCalled bool
} }
func (t *TestProvisioner) Prepare(configs ...interface{}) { func (t *TestProvisioner) Prepare(configs ...interface{}) error {
t.prepCalled = true t.prepCalled = true
t.prepConfigs = configs t.prepConfigs = configs
return nil
} }
func (t *TestProvisioner) Provision(Ui, Communicator) { func (t *TestProvisioner) Provision(Ui, Communicator) {
......
...@@ -28,9 +28,13 @@ type ProvisionerProvisionArgs struct { ...@@ -28,9 +28,13 @@ type ProvisionerProvisionArgs struct {
func Provisioner(client *rpc.Client) *provisioner { func Provisioner(client *rpc.Client) *provisioner {
return &provisioner{client} return &provisioner{client}
} }
func (p *provisioner) Prepare(configs ...interface{}) { func (p *provisioner) Prepare(configs ...interface{}) (err error) {
args := &ProvisionerPrepareArgs{configs} args := &ProvisionerPrepareArgs{configs}
p.client.Call("Provisioner.Prepare", args, new(interface{})) if cerr := p.client.Call("Provisioner.Prepare", args, &err); cerr != nil {
err = cerr
}
return
} }
func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) { func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
...@@ -43,8 +47,8 @@ func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) { ...@@ -43,8 +47,8 @@ func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
p.client.Call("Provisioner.Provision", args, new(interface{})) p.client.Call("Provisioner.Provision", args, new(interface{}))
} }
func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *interface{}) error { func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *error) error {
p.p.Prepare(args.Configs...) *reply = p.p.Prepare(args.Configs...)
return nil return nil
} }
......
...@@ -15,9 +15,10 @@ type testProvisioner struct { ...@@ -15,9 +15,10 @@ type testProvisioner struct {
provUi packer.Ui provUi packer.Ui
} }
func (p *testProvisioner) Prepare(configs ...interface{}) { func (p *testProvisioner) Prepare(configs ...interface{}) error {
p.prepareCalled = true p.prepareCalled = true
p.prepareConfigs = configs p.prepareConfigs = configs
return nil
} }
func (p *testProvisioner) Provision(ui packer.Ui, comm packer.Communicator) { func (p *testProvisioner) Provision(ui packer.Ui, comm packer.Communicator) {
......
...@@ -29,15 +29,19 @@ type Provisioner struct { ...@@ -29,15 +29,19 @@ type Provisioner struct {
config config config config
} }
func (p *Provisioner) Prepare(raws ...interface{}) { func (p *Provisioner) Prepare(raws ...interface{}) error {
// TODO: errors // TODO: errors
for _, raw := range raws { for _, raw := range raws {
_ = mapstructure.Decode(raw, &p.config) if err := mapstructure.Decode(raw, &p.config); err != nil {
return err
}
} }
if p.config.RemotePath == "" { if p.config.RemotePath == "" {
p.config.RemotePath = DefaultRemotePath p.config.RemotePath = DefaultRemotePath
} }
return nil
} }
func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) { func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) {
......
...@@ -17,7 +17,10 @@ func TestProvisionerPrepare_Defaults(t *testing.T) { ...@@ -17,7 +17,10 @@ func TestProvisionerPrepare_Defaults(t *testing.T) {
raw := map[string]interface{}{} raw := map[string]interface{}{}
p := &Provisioner{} p := &Provisioner{}
p.Prepare(raw, nil) err := p.Prepare(raw)
if err != nil {
t.Fatalf("err: %s", err)
}
if p.config.RemotePath != DefaultRemotePath { if p.config.RemotePath != DefaultRemotePath {
t.Errorf("unexpected remote path: %s", p.config.RemotePath) t.Errorf("unexpected remote path: %s", p.config.RemotePath)
......
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