packer: Set DebugConfigKey to true if debug is on
This commit is contained in:
parent
fd044982d9
commit
8217e64a8d
|
@ -2,6 +2,10 @@ package packer
|
|||
|
||||
import "log"
|
||||
|
||||
// This is the key in configurations that is set to "true" when Packer
|
||||
// debugging is enabled.
|
||||
const DebugConfigKey = "packer_config"
|
||||
|
||||
// A Build represents a single job within Packer that is responsible for
|
||||
// building some machine image artifact. Builds are meant to be parallelized.
|
||||
type Build interface {
|
||||
|
@ -65,8 +69,12 @@ func (b *coreBuild) Prepare() (err error) {
|
|||
// TODO: lock
|
||||
b.prepareCalled = true
|
||||
|
||||
debugConfig := map[string]interface{}{
|
||||
DebugConfigKey: b.debug,
|
||||
}
|
||||
|
||||
// Prepare the builder
|
||||
err = b.builder.Prepare(b.builderConfig)
|
||||
err = b.builder.Prepare(b.builderConfig, debugConfig)
|
||||
if err != nil {
|
||||
log.Printf("Build '%s' prepare failure: %s\n", b.name, err)
|
||||
return
|
||||
|
@ -74,7 +82,11 @@ func (b *coreBuild) Prepare() (err error) {
|
|||
|
||||
// Prepare the provisioners
|
||||
for _, coreProv := range b.provisioners {
|
||||
if err = coreProv.provisioner.Prepare(coreProv.config...); err != nil {
|
||||
configs := make([]interface{}, len(coreProv.config), len(coreProv.config)+1)
|
||||
copy(configs, coreProv.config)
|
||||
configs = append(configs, debugConfig)
|
||||
|
||||
if err = coreProv.provisioner.Prepare(configs...); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,20 +33,40 @@ func TestBuild_Name(t *testing.T) {
|
|||
func TestBuild_Prepare(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
build := testBuild()
|
||||
debugFalseConfig := map[string]interface{}{DebugConfigKey: false}
|
||||
|
||||
build := testBuild()
|
||||
coreB := build.(*coreBuild)
|
||||
builder := coreB.builder.(*TestBuilder)
|
||||
|
||||
build.Prepare()
|
||||
assert.True(builder.prepareCalled, "prepare should be called")
|
||||
assert.Equal(builder.prepareConfig, []interface{}{42}, "prepare config should be 42")
|
||||
assert.Equal(builder.prepareConfig, []interface{}{42, debugFalseConfig}, "prepare config should be 42")
|
||||
|
||||
// Verify provisioners were prepared
|
||||
coreProv := coreB.provisioners[0]
|
||||
prov := coreProv.provisioner.(*TestProvisioner)
|
||||
assert.True(prov.prepCalled, "prepare should be called")
|
||||
assert.Equal(prov.prepConfigs, []interface{}{42}, "prepare should be called with proper config")
|
||||
assert.Equal(prov.prepConfigs, []interface{}{42, debugFalseConfig}, "prepare should be called with proper config")
|
||||
}
|
||||
|
||||
func TestBuild_Prepare_Debug(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
debugConfig := map[string]interface{}{DebugConfigKey: true}
|
||||
|
||||
build := testBuild()
|
||||
coreB := build.(*coreBuild)
|
||||
builder := coreB.builder.(*TestBuilder)
|
||||
|
||||
build.SetDebug(true)
|
||||
build.Prepare()
|
||||
assert.True(builder.prepareCalled, "prepare should be called")
|
||||
assert.Equal(builder.prepareConfig, []interface{}{42, debugConfig}, "prepare config should be 42")
|
||||
|
||||
coreProv := coreB.provisioners[0]
|
||||
prov := coreProv.provisioner.(*TestProvisioner)
|
||||
assert.True(prov.prepCalled, "prepare should be called")
|
||||
assert.Equal(prov.prepConfigs, []interface{}{42, debugConfig}, "prepare should be called with proper config")
|
||||
}
|
||||
|
||||
func TestBuild_Run(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue