packer: Introduce Cancel() method to Builder
This commit is contained in:
parent
e21d389fd2
commit
079d6f4d43
|
@ -102,3 +102,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
|
|||
// Build the artifact and return it
|
||||
return &artifact{state["amis"].(map[string]string)}
|
||||
}
|
||||
|
||||
func (b *Builder) Cancel() {
|
||||
}
|
||||
|
|
|
@ -2,14 +2,17 @@ package packer
|
|||
|
||||
// Implementers of Builder are responsible for actually building images
|
||||
// on some platform given some configuration.
|
||||
//
|
||||
// Prepare is responsible for reading in some configuration, in the raw form
|
||||
// of map[string]interface{}, and storing that state for use later. Any setup
|
||||
// should be done in this method. Note that NO side effects should really take
|
||||
// place in prepare. It is meant as a state setup step only.
|
||||
//
|
||||
// Run is where the actual build should take place. It takes a Build and a Ui.
|
||||
type Builder interface {
|
||||
// Prepare is responsible for reading in some configuration, in the raw form
|
||||
// of map[string]interface{}, and storing that state for use later. Any setup
|
||||
// should be done in this method. Note that NO side effects should really take
|
||||
// place in prepare. It is meant as a state setup step only.
|
||||
Prepare(config interface{}) error
|
||||
|
||||
// Run is where the actual build should take place. It takes a Build and a Ui.
|
||||
Run(ui Ui, hook Hook) Artifact
|
||||
|
||||
// Cancel cancels a possibly running Builder. This should block until
|
||||
// the builder actually cancels and cleans up after itself.
|
||||
Cancel()
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ type TestBuilder struct {
|
|||
runCalled bool
|
||||
runHook Hook
|
||||
runUi Ui
|
||||
cancelCalled bool
|
||||
}
|
||||
|
||||
func (tb *TestBuilder) Prepare(config interface{}) error {
|
||||
|
@ -20,3 +21,7 @@ func (tb *TestBuilder) Run(ui Ui, h Hook) Artifact {
|
|||
tb.runUi = ui
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tb *TestBuilder) Cancel() {
|
||||
tb.cancelCalled = true
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
|
|||
return b.builder.Run(ui, hook)
|
||||
}
|
||||
|
||||
func (b *cmdBuilder) Cancel() {
|
||||
}
|
||||
|
||||
func (c *cmdBuilder) checkExit(p interface{}, cb func()) {
|
||||
if c.client.Exited() && cb != nil {
|
||||
cb()
|
||||
|
|
|
@ -17,6 +17,8 @@ func (helperBuilder) Run(packer.Ui, packer.Hook) packer.Artifact {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (helperBuilder) Cancel() {}
|
||||
|
||||
func TestBuilder_NoExist(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
|
|
|
@ -60,6 +60,10 @@ func (b *builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
|
|||
return Artifact(client)
|
||||
}
|
||||
|
||||
func (b *builder) Cancel() {
|
||||
|
||||
}
|
||||
|
||||
func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error {
|
||||
err := b.builder.Prepare(args.Config)
|
||||
if err != nil {
|
||||
|
|
|
@ -15,6 +15,7 @@ type testBuilder struct {
|
|||
runCalled bool
|
||||
runHook packer.Hook
|
||||
runUi packer.Ui
|
||||
cancelCalled bool
|
||||
}
|
||||
|
||||
func (b *testBuilder) Prepare(config interface{}) error {
|
||||
|
@ -30,6 +31,10 @@ func (b *testBuilder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
|
|||
return testBuilderArtifact
|
||||
}
|
||||
|
||||
func (b *testBuilder) Cancel() {
|
||||
b.cancelCalled = true
|
||||
}
|
||||
|
||||
func TestBuilderRPC(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ func TestColoredUi(t *testing.T) {
|
|||
ui := &ColoredUi{UiColorRed, bufferUi}
|
||||
|
||||
ui.Say("foo")
|
||||
assert.Equal(readWriter(bufferUi), "\033[0;31;40mfoo\033[0m\n", "should have color")
|
||||
assert.Equal(readWriter(bufferUi), "\033[1;31;40mfoo\033[0m\n", "should have color")
|
||||
}
|
||||
|
||||
func TestPrefixedUi(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue