Commit d926b987 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Update all packer/rpc, packer/plugin, builders for new builder API

parent 441edd25
...@@ -48,7 +48,7 @@ func (b *Builder) Prepare(raw interface{}) (err error) { ...@@ -48,7 +48,7 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
return return
} }
func (b *Builder) Run(build packer.Build, ui packer.Ui) { func (b *Builder) Run(ui packer.Ui, hook packer.Hook) {
auth := aws.Auth{b.config.AccessKey, b.config.SecretKey} auth := aws.Auth{b.config.AccessKey, b.config.SecretKey}
region := aws.Regions[b.config.Region] region := aws.Regions[b.config.Region]
ec2conn := ec2.New(auth, region) ec2conn := ec2.New(auth, region)
......
...@@ -22,13 +22,13 @@ func (b *cmdBuilder) Prepare(config interface{}) error { ...@@ -22,13 +22,13 @@ func (b *cmdBuilder) Prepare(config interface{}) error {
return b.builder.Prepare(config) return b.builder.Prepare(config)
} }
func (b *cmdBuilder) Run(build packer.Build, ui packer.Ui) { func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook) {
defer func() { defer func() {
r := recover() r := recover()
b.checkExit(r, nil) b.checkExit(r, nil)
}() }()
b.builder.Run(build, ui) b.builder.Run(ui, hook)
} }
func (c *cmdBuilder) checkExit(p interface{}, cb func()) { func (c *cmdBuilder) checkExit(p interface{}, cb func()) {
......
...@@ -13,7 +13,7 @@ func (helperBuilder) Prepare(interface{}) error { ...@@ -13,7 +13,7 @@ func (helperBuilder) Prepare(interface{}) error {
return nil return nil
} }
func (helperBuilder) Run(packer.Build, packer.Ui) {} func (helperBuilder) Run(packer.Ui, packer.Hook) {}
func TestBuilder_NoExist(t *testing.T) { func TestBuilder_NoExist(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) assert := asserts.NewTestingAsserts(t, true)
......
...@@ -38,12 +38,12 @@ func (b *builder) Prepare(config interface{}) (err error) { ...@@ -38,12 +38,12 @@ func (b *builder) Prepare(config interface{}) (err error) {
return return
} }
func (b *builder) Run(build packer.Build, ui packer.Ui) { func (b *builder) Run(ui packer.Ui, hook packer.Hook) {
// Create and start the server for the Build and UI // Create and start the server for the Build and UI
// TODO: Error handling // TODO: Error handling
server := rpc.NewServer() server := rpc.NewServer()
RegisterBuild(server, build)
RegisterUi(server, ui) RegisterUi(server, ui)
RegisterHook(server, hook)
args := &BuilderRunArgs{serveSingleConn(server)} args := &BuilderRunArgs{serveSingleConn(server)}
b.client.Call("Builder.Run", args, new(interface{})) b.client.Call("Builder.Run", args, new(interface{}))
...@@ -64,9 +64,9 @@ func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error { ...@@ -64,9 +64,9 @@ func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error {
return err return err
} }
build := &Build{client} hook := Hook(client)
ui := &Ui{client} ui := &Ui{client}
b.builder.Run(build, ui) b.builder.Run(ui, hook)
*reply = nil *reply = nil
return nil return nil
......
...@@ -11,7 +11,7 @@ type testBuilder struct { ...@@ -11,7 +11,7 @@ type testBuilder struct {
prepareCalled bool prepareCalled bool
prepareConfig interface{} prepareConfig interface{}
runCalled bool runCalled bool
runBuild packer.Build runHook packer.Hook
runUi packer.Ui runUi packer.Ui
} }
...@@ -21,9 +21,9 @@ func (b *testBuilder) Prepare(config interface{}) error { ...@@ -21,9 +21,9 @@ func (b *testBuilder) Prepare(config interface{}) error {
return nil return nil
} }
func (b *testBuilder) Run(build packer.Build, ui packer.Ui) { func (b *testBuilder) Run(ui packer.Ui, hook packer.Hook) {
b.runCalled = true b.runCalled = true
b.runBuild = build b.runHook = hook
b.runUi = ui b.runUi = ui
} }
...@@ -50,14 +50,14 @@ func TestBuilderRPC(t *testing.T) { ...@@ -50,14 +50,14 @@ func TestBuilderRPC(t *testing.T) {
assert.Equal(b.prepareConfig, 42, "prepare should be called with right arg") assert.Equal(b.prepareConfig, 42, "prepare should be called with right arg")
// Test Run // Test Run
build := &testBuild{} hook := &testHook{}
ui := &testUi{} ui := &testUi{}
bClient.Run(build, ui) bClient.Run(ui, hook)
assert.True(b.runCalled, "runs hould be called") assert.True(b.runCalled, "runs hould be called")
if b.runCalled { if b.runCalled {
b.runBuild.Prepare() b.runHook.Run("foo", nil, nil)
assert.True(build.prepareCalled, "prepare should be called") assert.True(hook.runCalled, "run should be called")
b.runUi.Say("format") b.runUi.Say("format")
assert.True(ui.sayCalled, "say should be called") assert.True(ui.sayCalled, "say should be called")
......
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