diff --git a/packer/plugin/server.go b/packer/plugin/server.go index a3dbc7b24..a36f8beda 100644 --- a/packer/plugin/server.go +++ b/packer/plugin/server.go @@ -33,7 +33,7 @@ const MagicCookieValue = "d602bf8f470bc67ca7faa0386276bbdd4330efaf76d1a219cb4d69 // The APIVersion is outputted along with the RPC address. The plugin // client validates this API version and will show an error if it doesn't // know how to speak it. -const APIVersion = "2" +const APIVersion = "3" // Server waits for a connection to this plugin and returns a Packer // RPC server that you can use to register components and serve them. diff --git a/packer/rpc/builder.go b/packer/rpc/builder.go index 986e218a2..5e3f429b5 100644 --- a/packer/rpc/builder.go +++ b/packer/rpc/builder.go @@ -26,7 +26,7 @@ type BuilderPrepareArgs struct { type BuilderPrepareResponse struct { Warnings []string - Error error + Error *BasicError } func (b *builder) Prepare(config ...interface{}) ([]string, error) { @@ -35,8 +35,12 @@ func (b *builder) Prepare(config ...interface{}) ([]string, error) { if cerr != nil { return nil, cerr } + var err error = nil + if resp.Error != nil { + err = resp.Error + } - return resp.Warnings, resp.Error + return resp.Warnings, err } func (b *builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { @@ -72,13 +76,9 @@ func (b *builder) Cancel() { func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *BuilderPrepareResponse) error { warnings, err := b.builder.Prepare(args.Configs...) - if err != nil { - err = NewBasicError(err) - } - *reply = BuilderPrepareResponse{ Warnings: warnings, - Error: err, + Error: NewBasicError(err), } return nil } diff --git a/packer/rpc/builder_test.go b/packer/rpc/builder_test.go index 37e8041bb..51dbf7044 100644 --- a/packer/rpc/builder_test.go +++ b/packer/rpc/builder_test.go @@ -30,8 +30,9 @@ func TestBuilderPrepare(t *testing.T) { t.Fatal("should be called") } - if !reflect.DeepEqual(b.PrepareConfig, []interface{}{42}) { - t.Fatalf("bad: %#v", b.PrepareConfig) + expected := []interface{}{int64(42)} + if !reflect.DeepEqual(b.PrepareConfig, expected) { + t.Fatalf("bad: %#v != %#v", b.PrepareConfig, expected) } } diff --git a/packer/rpc/client.go b/packer/rpc/client.go index 0fce79bf8..0cc8fc869 100644 --- a/packer/rpc/client.go +++ b/packer/rpc/client.go @@ -2,6 +2,7 @@ package rpc import ( "github.com/mitchellh/packer/packer" + "github.com/ugorji/go/codec" "io" "log" "net/rpc" @@ -32,9 +33,12 @@ func newClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) { return nil, err } + var h codec.MsgpackHandle + clientCodec := codec.GoRpc.ClientCodec(clientConn, &h) + return &Client{ mux: mux, - client: rpc.NewClient(clientConn), + client: rpc.NewClientWithCodec(clientCodec), closeMux: false, }, nil } diff --git a/packer/rpc/error.go b/packer/rpc/error.go index a5880fbac..c3ab7b1a4 100644 --- a/packer/rpc/error.go +++ b/packer/rpc/error.go @@ -9,6 +9,10 @@ type BasicError struct { } func NewBasicError(err error) *BasicError { + if err == nil { + return nil + } + return &BasicError{err.Error()} } diff --git a/packer/rpc/post_processor_test.go b/packer/rpc/post_processor_test.go index dabd8c03a..d9ea9c86f 100644 --- a/packer/rpc/post_processor_test.go +++ b/packer/rpc/post_processor_test.go @@ -54,7 +54,8 @@ func TestPostProcessorRPC(t *testing.T) { t.Fatal("config should be called") } - if !reflect.DeepEqual(p.configVal, []interface{}{42}) { + expected := []interface{}{int64(42)} + if !reflect.DeepEqual(p.configVal, expected) { t.Fatalf("unknown config value: %#v", p.configVal) } diff --git a/packer/rpc/provisioner_test.go b/packer/rpc/provisioner_test.go index a17e0694c..421990ffd 100644 --- a/packer/rpc/provisioner_test.go +++ b/packer/rpc/provisioner_test.go @@ -23,7 +23,8 @@ func TestProvisionerRPC(t *testing.T) { if !p.PrepCalled { t.Fatal("should be called") } - if !reflect.DeepEqual(p.PrepConfigs, []interface{}{42}) { + expected := []interface{}{int64(42)} + if !reflect.DeepEqual(p.PrepConfigs, expected) { t.Fatalf("bad: %#v", p.PrepConfigs) } diff --git a/packer/rpc/server.go b/packer/rpc/server.go index 5e4b5006b..df50f48ad 100644 --- a/packer/rpc/server.go +++ b/packer/rpc/server.go @@ -3,6 +3,7 @@ package rpc import ( "fmt" "github.com/mitchellh/packer/packer" + "github.com/ugorji/go/codec" "io" "log" "net/rpc" @@ -145,7 +146,9 @@ func (s *Server) Serve() { return } - s.server.ServeConn(stream) + var h codec.MsgpackHandle + rpcCodec := codec.GoRpc.ServerCodec(stream, &h) + s.server.ServeCodec(rpcCodec) } // registerComponent registers a single Packer RPC component onto