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

packer: Add errors to Prepare

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