packer/rpc: complete command
This commit is contained in:
parent
a8b056e939
commit
8d4ba1fc2b
|
@ -20,8 +20,8 @@ type CommandServer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommandRunArgs struct {
|
type CommandRunArgs struct {
|
||||||
RPCAddress string
|
|
||||||
Args []string
|
Args []string
|
||||||
|
StreamId uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommandSynopsisArgs byte
|
type CommandSynopsisArgs byte
|
||||||
|
@ -40,11 +40,15 @@ func (c *command) Help() (result string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *command) Run(env packer.Environment, args []string) (result int) {
|
func (c *command) Run(env packer.Environment, args []string) (result int) {
|
||||||
// Create and start the server for the Environment
|
nextId := c.mux.NextId()
|
||||||
server := rpc.NewServer()
|
server := NewServerWithMux(c.mux, nextId)
|
||||||
RegisterEnvironment(server, env)
|
server.RegisterEnvironment(env)
|
||||||
|
go server.Serve()
|
||||||
|
|
||||||
rpcArgs := &CommandRunArgs{serveSingleConn(server), args}
|
rpcArgs := &CommandRunArgs{
|
||||||
|
Args: args,
|
||||||
|
StreamId: nextId,
|
||||||
|
}
|
||||||
err := c.client.Call("Command.Run", rpcArgs, &result)
|
err := c.client.Call("Command.Run", rpcArgs, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -68,14 +72,13 @@ func (c *CommandServer) Help(args *interface{}, reply *string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommandServer) Run(args *CommandRunArgs, reply *int) error {
|
func (c *CommandServer) Run(args *CommandRunArgs, reply *int) error {
|
||||||
client, err := rpcDial(args.RPCAddress)
|
client, err := NewClientWithMux(c.mux, args.StreamId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return NewBasicError(err)
|
||||||
}
|
}
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
env := &Environment{client: client}
|
*reply = c.command.Run(client.Environment(), args.Args)
|
||||||
|
|
||||||
*reply = c.command.Run(env, args.Args)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,11 +59,6 @@ func TestRPCCommand(t *testing.T) {
|
||||||
t.Fatal("runEnv should not be nil")
|
t.Fatal("runEnv should not be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
command.runEnv.Ui()
|
|
||||||
if !testEnv.uiCalled {
|
|
||||||
t.Fatal("ui should be called")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test Synopsis
|
// Test Synopsis
|
||||||
synopsis := commClient.Synopsis()
|
synopsis := commClient.Synopsis()
|
||||||
if synopsis != "foo" {
|
if synopsis != "foo" {
|
||||||
|
|
|
@ -30,10 +30,6 @@ type PostProcessorProcessResponse struct {
|
||||||
StreamId uint32
|
StreamId uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostProcessor(client *rpc.Client) *postProcessor {
|
|
||||||
return &postProcessor{client: client}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *postProcessor) Configure(raw ...interface{}) (err error) {
|
func (p *postProcessor) Configure(raw ...interface{}) (err error) {
|
||||||
args := &PostProcessorConfigureArgs{Configs: raw}
|
args := &PostProcessorConfigureArgs{Configs: raw}
|
||||||
if cerr := p.client.Call("PostProcessor.Configure", args, &err); cerr != nil {
|
if cerr := p.client.Call("PostProcessor.Configure", args, &err); cerr != nil {
|
||||||
|
|
|
@ -83,7 +83,7 @@ func TestPostProcessorRPC(t *testing.T) {
|
||||||
|
|
||||||
func TestPostProcessor_Implements(t *testing.T) {
|
func TestPostProcessor_Implements(t *testing.T) {
|
||||||
var raw interface{}
|
var raw interface{}
|
||||||
raw = PostProcessor(nil)
|
raw = new(postProcessor)
|
||||||
if _, ok := raw.(packer.PostProcessor); !ok {
|
if _, ok := raw.(packer.PostProcessor); !ok {
|
||||||
t.Fatal("not a postprocessor")
|
t.Fatal("not a postprocessor")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue