Commit a35feebe authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Build no longer takes Ui for Prepare

parent c8120bc2
......@@ -144,7 +144,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
// Prepare all the builds
for _, b := range builds {
log.Printf("Preparing build: %s", b.Name())
err := b.Prepare(buildUis[b.Name()])
err := b.Prepare()
if err != nil {
env.Ui().Error(err.Error())
return 1
......
......@@ -6,7 +6,7 @@ import "log"
// building some machine image artifact. Builds are meant to be parallelized.
type Build interface {
Name() string
Prepare(Ui) error
Prepare() error
Run(Ui, Cache) (Artifact, error)
Cancel()
}
......@@ -39,7 +39,7 @@ func (b *coreBuild) Name() string {
// Prepare prepares the build by doing some initialization for the builder
// and any hooks. This _must_ be called prior to Run.
func (b *coreBuild) Prepare(ui Ui) (err error) {
func (b *coreBuild) Prepare() (err error) {
// TODO: lock
b.prepareCalled = true
......
......@@ -34,12 +34,11 @@ func TestBuild_Prepare(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
build := testBuild()
ui := testUi()
coreB := build.(*coreBuild)
builder := coreB.builder.(*TestBuilder)
build.Prepare(ui)
build.Prepare()
assert.True(builder.prepareCalled, "prepare should be called")
assert.Equal(builder.prepareConfig, 42, "prepare config should be 42")
......@@ -57,7 +56,7 @@ func TestBuild_Run(t *testing.T) {
ui := testUi()
build := testBuild()
build.Prepare(ui)
build.Prepare()
build.Run(ui, cache)
coreB := build.(*coreBuild)
......
......@@ -17,10 +17,6 @@ type BuildServer struct {
build packer.Build
}
type BuildPrepareArgs struct {
RPCAddress string
}
type BuildRunArgs struct {
UiRPCAddress string
}
......@@ -34,14 +30,8 @@ func (b *build) Name() (result string) {
return
}
func (b *build) Prepare(ui packer.Ui) (err error) {
// Create and start the server for the UI
// TODO: Error handling
server := rpc.NewServer()
RegisterUi(server, ui)
args := &BuildPrepareArgs{serveSingleConn(server)}
if cerr := b.client.Call("Build.Prepare", args, &err); cerr != nil {
func (b *build) Prepare() (err error) {
if cerr := b.client.Call("Build.Prepare", new(interface{}), &err); cerr != nil {
return cerr
}
......@@ -79,13 +69,8 @@ func (b *BuildServer) Name(args *interface{}, reply *string) error {
return nil
}
func (b *BuildServer) Prepare(args *BuildPrepareArgs, reply *error) error {
client, err := rpc.Dial("tcp", args.RPCAddress)
if err != nil {
return err
}
*reply = b.build.Prepare(&Ui{client})
func (b *BuildServer) Prepare(args interface{}, reply *error) error {
*reply = b.build.Prepare()
return nil
}
......
......@@ -13,7 +13,6 @@ var testBuildArtifact = &testArtifact{}
type testBuild struct {
nameCalled bool
prepareCalled bool
prepareUi packer.Ui
runCalled bool
runCache packer.Cache
runUi packer.Ui
......@@ -27,9 +26,8 @@ func (b *testBuild) Name() string {
return "name"
}
func (b *testBuild) Prepare(ui packer.Ui) error {
func (b *testBuild) Prepare() error {
b.prepareCalled = true
b.prepareUi = ui
return nil
}
......@@ -70,13 +68,12 @@ func TestBuildRPC(t *testing.T) {
assert.True(b.nameCalled, "name should be called")
// Test Prepare
ui := new(testUi)
bClient.Prepare(ui)
bClient.Prepare()
assert.True(b.prepareCalled, "prepare should be called")
// Test Run
cache := new(testCache)
ui = new(testUi)
ui := new(testUi)
_, err = bClient.Run(ui, cache)
assert.True(b.runCalled, "run should be called")
assert.Nil(err, "should not error")
......
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