change all provision func signatures to use map[string]interface{}
This commit is contained in:
parent
0ca7c9f397
commit
39fd462b56
|
@ -10,6 +10,7 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/packer/common"
|
||||
"github.com/hashicorp/packer/common/shell"
|
||||
configHelper "github.com/hashicorp/packer/helper/config"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
|
@ -45,12 +46,13 @@ type Config struct {
|
|||
// GeneratedData
|
||||
|
||||
ctx interpolate.Context
|
||||
generatedData map[string]interface{}
|
||||
}
|
||||
|
||||
func Decode(config *Config, raws ...interface{}) error {
|
||||
// Create passthrough for build-generated data so we can fill it in once we know
|
||||
// it
|
||||
// config.ctx.Data = common.PlaceholderData()
|
||||
config.ctx.Data = common.PlaceholderData()
|
||||
|
||||
err := configHelper.Decode(&config, &configHelper.DecodeOpts{
|
||||
Interpolate: true,
|
||||
|
|
|
@ -28,7 +28,15 @@ type EnvVarsTemplate struct {
|
|||
WinRMPassword string
|
||||
}
|
||||
|
||||
func Run(ctx context.Context, ui packer.Ui, config *Config) (bool, error) {
|
||||
func Run(ctx context.Context, ui packer.Ui, config *Config, generatedData map[string]interface{}) (bool, error) {
|
||||
if generatedData != nil {
|
||||
config.generatedData = generatedData
|
||||
} else {
|
||||
// No fear; probably just in the post-processor, not provisioner.
|
||||
// Make sure it's not a nil map so we can assign to it later.
|
||||
config.generatedData = make(map[string]interface{})
|
||||
}
|
||||
config.ctx.Data = generatedData
|
||||
// Check if shell-local can even execute against this runtime OS
|
||||
if len(config.OnlyOn) > 0 {
|
||||
runCommand := false
|
||||
|
@ -120,11 +128,6 @@ func createInlineScriptFile(config *Config) (string, error) {
|
|||
writer.WriteString(shebang)
|
||||
}
|
||||
|
||||
// generate context so you can interpolate the command
|
||||
config.ctx.Data = &EnvVarsTemplate{
|
||||
WinRMPassword: getWinRMPassword(config.PackerBuildName),
|
||||
}
|
||||
|
||||
for _, command := range config.Inline {
|
||||
// interpolate command to check for template variables.
|
||||
command, err := interpolate.Render(command, &config.ctx)
|
||||
|
@ -152,12 +155,11 @@ func createInlineScriptFile(config *Config) (string, error) {
|
|||
// user-provided ExecuteCommand or defaulting to something that makes sense for
|
||||
// the host OS
|
||||
func createInterpolatedCommands(config *Config, script string, flattenedEnvVars string) ([]string, error) {
|
||||
config.ctx.Data = &ExecuteCommandTemplate{
|
||||
Vars: flattenedEnvVars,
|
||||
Script: script,
|
||||
Command: script,
|
||||
WinRMPassword: getWinRMPassword(config.PackerBuildName),
|
||||
}
|
||||
config.generatedData["Vars"] = flattenedEnvVars
|
||||
config.generatedData["Script"] = script
|
||||
config.generatedData["Command"] = script
|
||||
|
||||
config.ctx.Data = config.generatedData
|
||||
|
||||
interpolatedCmds := make([]string, len(config.ExecuteCommand))
|
||||
for i, cmd := range config.ExecuteCommand {
|
||||
|
@ -192,10 +194,6 @@ func createFlattenedEnvVars(config *Config) (string, error) {
|
|||
envVars["PACKER_HTTP_PORT"] = httpPort
|
||||
}
|
||||
|
||||
// interpolate environment variables
|
||||
config.ctx.Data = &EnvVarsTemplate{
|
||||
WinRMPassword: getWinRMPassword(config.PackerBuildName),
|
||||
}
|
||||
// Split vars into key/value components
|
||||
for _, envVar := range config.Vars {
|
||||
envVar, err := interpolate.Render(envVar, &config.ctx)
|
||||
|
|
|
@ -75,10 +75,9 @@ func PopulateProvisionHookData(state multistep.StateBag) map[string]interface{}
|
|||
if fieldName == "ID" {
|
||||
continue
|
||||
}
|
||||
|
||||
fVal := v.FieldByName(fieldName)
|
||||
if fVal.IsZero() {
|
||||
log.Printf("Megan NONINTERFACABLE fVal is %#v", fVal)
|
||||
} else {
|
||||
if !fVal.IsZero() {
|
||||
hookData[fieldName] = fVal.Interface()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ func (c *cmdProvisioner) Prepare(configs ...interface{}) error {
|
|||
return c.p.Prepare(configs...)
|
||||
}
|
||||
|
||||
func (c *cmdProvisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData interface{}) error {
|
||||
func (c *cmdProvisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData map[string]interface{}) error {
|
||||
defer func() {
|
||||
r := recover()
|
||||
c.checkExit(r, nil)
|
||||
|
|
|
@ -20,7 +20,7 @@ type Provisioner interface {
|
|||
// given for cancellation, a UI is given to communicate with the user, and
|
||||
// a communicator is given that is guaranteed to be connected to some
|
||||
// machine so that provisioning can be done.
|
||||
Provision(context.Context, Ui, Communicator, interface{}) error
|
||||
Provision(context.Context, Ui, Communicator, map[string]interface{}) error
|
||||
}
|
||||
|
||||
// A HookedProvisioner represents a provisioner and information describing it
|
||||
|
@ -53,7 +53,26 @@ func (h *ProvisionHook) Run(ctx context.Context, name string, ui Ui, comm Commun
|
|||
for _, p := range h.Provisioners {
|
||||
ts := CheckpointReporter.AddSpan(p.TypeName, "provisioner", p.Config)
|
||||
|
||||
err := p.Provisioner.Provision(ctx, ui, comm, data)
|
||||
// Provisioners expect a map[string]interface{} in their data field, but
|
||||
// it gets converted into a map[interface]interface on the way over the
|
||||
// RPC. Check that data can be cast into such a form, and cast it.
|
||||
cast := make(map[string]interface{})
|
||||
interMap, ok := data.(map[interface{}]interface{})
|
||||
if !ok {
|
||||
log.Printf("Unable to read map[string]interface out of data." +
|
||||
"Using empty interface.")
|
||||
} else {
|
||||
for key, val := range interMap {
|
||||
keyString, ok := key.(string)
|
||||
if ok {
|
||||
cast[keyString] = val
|
||||
} else {
|
||||
log.Printf("Error casting generated data key to a string.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err := p.Provisioner.Provision(ctx, ui, comm, cast)
|
||||
|
||||
ts.End(err)
|
||||
if err != nil {
|
||||
|
@ -75,7 +94,7 @@ func (p *PausedProvisioner) Prepare(raws ...interface{}) error {
|
|||
return p.Provisioner.Prepare(raws...)
|
||||
}
|
||||
|
||||
func (p *PausedProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData interface{}) error {
|
||||
func (p *PausedProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) error {
|
||||
|
||||
// Use a select to determine if we get cancelled during the wait
|
||||
ui.Say(fmt.Sprintf("Pausing %s before the next provisioner...", p.PauseBefore))
|
||||
|
@ -102,7 +121,7 @@ func (p *DebuggedProvisioner) Prepare(raws ...interface{}) error {
|
|||
return p.Provisioner.Prepare(raws...)
|
||||
}
|
||||
|
||||
func (p *DebuggedProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData interface{}) error {
|
||||
func (p *DebuggedProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) error {
|
||||
// Use a select to determine if we get cancelled during the wait
|
||||
message := "Pausing before the next provisioner . Press enter to continue."
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ func (t *MockProvisioner) Prepare(configs ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *MockProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData interface{}) error {
|
||||
func (t *MockProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) error {
|
||||
t.ProvCalled = true
|
||||
t.ProvCommunicator = comm
|
||||
t.ProvUi = ui
|
||||
|
|
|
@ -114,7 +114,7 @@ func TestPausedProvisionerProvision(t *testing.T) {
|
|||
|
||||
ui := testUi()
|
||||
comm := new(MockCommunicator)
|
||||
prov.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
prov.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if !mock.ProvCalled {
|
||||
t.Fatal("prov should be called")
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ func TestPausedProvisionerProvision_waits(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err := prov.Provision(context.Background(), testUi(), new(MockCommunicator), make(map[interface{}]interface{}))
|
||||
err := prov.Provision(context.Background(), testUi(), new(MockCommunicator), make(map[string]interface{}))
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("prov failed: %v", err)
|
||||
|
@ -164,7 +164,7 @@ func TestPausedProvisionerCancel(t *testing.T) {
|
|||
return ctx.Err()
|
||||
}
|
||||
|
||||
err := prov.Provision(topCtx, testUi(), new(MockCommunicator), make(map[interface{}]interface{}))
|
||||
err := prov.Provision(topCtx, testUi(), new(MockCommunicator), make(map[string]interface{}))
|
||||
if err == nil {
|
||||
t.Fatal("should have err")
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ func TestDebuggedProvisionerProvision(t *testing.T) {
|
|||
ui := testUi()
|
||||
comm := new(MockCommunicator)
|
||||
writeReader(ui, "\n")
|
||||
prov.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
prov.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if !mock.ProvCalled {
|
||||
t.Fatal("prov should be called")
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ func TestDebuggedProvisionerCancel(t *testing.T) {
|
|||
return ctx.Err()
|
||||
}
|
||||
|
||||
err := prov.Provision(topCtx, testUi(), new(MockCommunicator), make(map[interface{}]interface{}))
|
||||
err := prov.Provision(topCtx, testUi(), new(MockCommunicator), make(map[string]interface{}))
|
||||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ type TimeoutProvisioner struct {
|
|||
Timeout time.Duration
|
||||
}
|
||||
|
||||
func (p *TimeoutProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData interface{}) error {
|
||||
func (p *TimeoutProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, p.Timeout)
|
||||
defer cancel()
|
||||
|
||||
|
|
|
@ -39,11 +39,11 @@ func (p *provisioner) Prepare(configs ...interface{}) (err error) {
|
|||
}
|
||||
|
||||
type ProvisionerProvisionArgs struct {
|
||||
GeneratedData interface{}
|
||||
GeneratedData map[string]interface{}
|
||||
StreamID uint32
|
||||
}
|
||||
|
||||
func (p *provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData interface{}) error {
|
||||
func (p *provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData map[string]interface{}) error {
|
||||
nextId := p.mux.NextId()
|
||||
server := newServerWithMux(p.mux, nextId)
|
||||
server.RegisterCommunicator(comm)
|
||||
|
@ -74,7 +74,6 @@ func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *interfa
|
|||
|
||||
func (p *ProvisionerServer) Provision(args *ProvisionerProvisionArgs, reply *interface{}) error {
|
||||
streamId := args.StreamID
|
||||
generatedData := args.GeneratedData
|
||||
client, err := newClientWithMux(p.mux, streamId)
|
||||
if err != nil {
|
||||
return NewBasicError(err)
|
||||
|
@ -84,8 +83,7 @@ func (p *ProvisionerServer) Provision(args *ProvisionerProvisionArgs, reply *int
|
|||
if p.context == nil {
|
||||
p.context, p.contextCancel = context.WithCancel(context.Background())
|
||||
}
|
||||
|
||||
if err := p.p.Provision(p.context, client.Ui(), client.Communicator(), generatedData); err != nil {
|
||||
if err := p.p.Provision(p.context, client.Ui(), client.Communicator(), args.GeneratedData); err != nil {
|
||||
return NewBasicError(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ func TestProvisionerRPC(t *testing.T) {
|
|||
// Test Provision
|
||||
ui := &testUi{}
|
||||
comm := &packer.MockCommunicator{}
|
||||
if err := pClient.Provision(topCtx, ui, comm, make(map[interface{}]interface{})); err == nil {
|
||||
if err := pClient.Provision(topCtx, ui, comm, make(map[string]interface{})); err == nil {
|
||||
t.Fatalf("Provison should have err")
|
||||
}
|
||||
if !p.ProvCalled {
|
||||
|
|
|
@ -41,7 +41,7 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
|
|||
// this particular post-processor doesn't do anything with the artifact
|
||||
// except to return it.
|
||||
|
||||
success, retErr := sl.Run(ctx, ui, &p.config)
|
||||
success, retErr := sl.Run(ctx, ui, &p.config, map[string]interface{}{})
|
||||
if !success {
|
||||
return nil, false, false, retErr
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
ui.Say("Provisioning with Ansible...")
|
||||
|
||||
if len(p.config.PlaybookDir) > 0 {
|
||||
|
|
|
@ -134,7 +134,7 @@ func TestProvisionerProvision_PlaybookFiles(t *testing.T) {
|
|||
}
|
||||
|
||||
comm := &communicatorMock{}
|
||||
if err := p.Provision(context.Background(), new(packer.NoopUi), comm, make(map[interface{}]interface{})); err != nil {
|
||||
if err := p.Provision(context.Background(), new(packer.NoopUi), comm, make(map[string]interface{})); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ func TestProvisionerProvision_PlaybookFilesWithPlaybookDir(t *testing.T) {
|
|||
}
|
||||
|
||||
comm := &communicatorMock{}
|
||||
if err := p.Provision(context.Background(), new(packer.NoopUi), comm, make(map[interface{}]interface{})); err != nil {
|
||||
if err := p.Provision(context.Background(), new(packer.NoopUi), comm, make(map[string]interface{})); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ func (p *Provisioner) getVersion() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
ui.Say("Provisioning with Ansible...")
|
||||
// Interpolate env vars to check for .WinRMPassword
|
||||
p.config.ctx.Data = &PassthroughTemplate{
|
||||
|
|
|
@ -349,7 +349,7 @@ func TestAnsibleLongMessages(t *testing.T) {
|
|||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
if p.config.Disable {
|
||||
if p.config.Note != "" {
|
||||
ui.Say(fmt.Sprintf(
|
||||
|
|
|
@ -244,7 +244,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
|
||||
p.communicator = comm
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
ui.Say("Provisioning with chef-solo")
|
||||
|
||||
if !p.config.SkipInstall {
|
||||
|
|
|
@ -108,7 +108,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
}
|
||||
|
||||
// Provision node somehow. TODO: actual docs
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
ui.Say("Provisioning with Converge")
|
||||
|
||||
// bootstrapping
|
||||
|
|
|
@ -92,7 +92,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
if p.config.Direction == "download" {
|
||||
return p.ProvisionDownload(ui, comm)
|
||||
} else {
|
||||
|
|
|
@ -127,7 +127,7 @@ func TestProvisionerProvision_SendsFile(t *testing.T) {
|
|||
Writer: b,
|
||||
}
|
||||
comm := &packer.MockCommunicator{}
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatalf("should successfully provision: %s", err)
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ func (p *Provisioner) getVersion() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
ui.Say("Provisioning with Inspec...")
|
||||
|
||||
for i, envVar := range p.config.InspecEnvVars {
|
||||
|
|
|
@ -220,26 +220,20 @@ func extractScript(p *Provisioner) (string, error) {
|
|||
return temp.Name(), nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData map[string]interface{}) error {
|
||||
ui.Say(fmt.Sprintf("Provisioning with Powershell..."))
|
||||
p.communicator = comm
|
||||
p.generatedData = make(map[string]interface{})
|
||||
// test that generatedData is a map, not an empty interface.
|
||||
dataMap, ok := generatedData.(map[interface{}]interface{})
|
||||
if ok {
|
||||
for key, val := range dataMap {
|
||||
keyString, ok := key.(string)
|
||||
if ok {
|
||||
p.generatedData[keyString] = val
|
||||
} else {
|
||||
log.Printf("Error casting generated data key to a string.")
|
||||
}
|
||||
}
|
||||
|
||||
if generatedData != nil {
|
||||
log.Printf("Gen data isn't nil.")
|
||||
p.generatedData = generatedData
|
||||
if winRMPass, ok := p.generatedData["WinRMPassword"]; ok {
|
||||
log.Printf("Found winrm pass")
|
||||
packer.LogSecretFilter.Set(winRMPass.(string))
|
||||
}
|
||||
} else {
|
||||
log.Printf("error reading generated data from builder")
|
||||
log.Printf("generatedData passed to Provision method is nil!")
|
||||
}
|
||||
|
||||
scripts := make([]string, len(p.config.Scripts))
|
||||
|
@ -445,7 +439,6 @@ func (p *Provisioner) createCommandTextPrivileged() (command string, err error)
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ctxData := p.generatedData
|
||||
ctxData["Path"] = p.config.RemotePath
|
||||
ctxData["Vars"] = p.config.RemoteEnvVarPath
|
||||
|
@ -475,7 +468,6 @@ func (p *Provisioner) ElevatedUser() string {
|
|||
func (p *Provisioner) ElevatedPassword() string {
|
||||
// Replace ElevatedPassword for winrm users who used this feature
|
||||
p.config.ctx.Data = p.generatedData
|
||||
|
||||
elevatedPassword, _ := interpolate.Render(p.config.ElevatedPassword, &p.config.ctx)
|
||||
|
||||
return elevatedPassword
|
||||
|
|
|
@ -355,7 +355,7 @@ func TestProvisionerProvision_ValidExitCodes(t *testing.T) {
|
|||
comm := new(packer.MockCommunicator)
|
||||
comm.StartExitStatus = 200
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
@ -378,7 +378,7 @@ func TestProvisionerProvision_InvalidExitCodes(t *testing.T) {
|
|||
comm := new(packer.MockCommunicator)
|
||||
comm.StartExitStatus = 201 // Invalid!
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ func TestProvisionerProvision_Inline(t *testing.T) {
|
|||
p.config.PackerBuilderType = "iso"
|
||||
comm := new(packer.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ func TestProvisionerProvision_Inline(t *testing.T) {
|
|||
config["remote_path"] = "c:/Windows/Temp/inlineScript.ps1"
|
||||
|
||||
p.Prepare(config)
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ func TestProvisionerProvision_Scripts(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
@ -484,7 +484,7 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
@ -511,7 +511,7 @@ func TestProvisionerProvision_UploadFails(t *testing.T) {
|
|||
comm := new(packer.ScriptUploadErrorMockCommunicator)
|
||||
p.Prepare(config)
|
||||
p.config.StartRetryTimeout = 1 * time.Second
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if !strings.Contains(err.Error(), packer.ScriptUploadErrorMockCommunicatorError.Error()) {
|
||||
t.Fatalf("expected Provision() error %q to contain %q",
|
||||
err.Error(),
|
||||
|
|
|
@ -259,7 +259,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
ui.Say("Provisioning with Puppet...")
|
||||
p.communicator = comm
|
||||
ui.Message("Creating Puppet staging directory...")
|
||||
|
|
|
@ -494,7 +494,7 @@ func TestProvisionerProvision_extraArguments(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
@ -514,7 +514,7 @@ func TestProvisionerProvision_extraArguments(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
ui.Say("Provisioning with Puppet...")
|
||||
p.communicator = comm
|
||||
ui.Message("Creating Puppet staging directory...")
|
||||
|
|
|
@ -222,7 +222,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
var err error
|
||||
var src, dst string
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, _ packer.Communicator, _ interface{}) error {
|
||||
_, retErr := sl.Run(ctx, ui, &p.config)
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, _ packer.Communicator, generatedData map[string]interface{}) error {
|
||||
_, retErr := sl.Run(ctx, ui, &p.config, generatedData)
|
||||
|
||||
return retErr
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
scripts := make([]string, len(p.config.Scripts))
|
||||
copy(scripts, p.config.Scripts)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return config.Decode(&p, &config.DecodeOpts{}, raws...)
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, _ packer.Ui, _ packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, _ packer.Ui, _ packer.Communicator, _ map[string]interface{}) error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
|
|
|
@ -96,7 +96,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
p.cancelLock.Lock()
|
||||
p.cancel = make(chan struct{})
|
||||
p.cancelLock.Unlock()
|
||||
|
|
|
@ -104,7 +104,7 @@ func TestProvisionerProvision_Success(t *testing.T) {
|
|||
waitForRestart = func(context.Context, *Provisioner, packer.Communicator) error {
|
||||
return nil
|
||||
}
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ func TestProvisionerProvision_CustomCommand(t *testing.T) {
|
|||
waitForRestart = func(context.Context, *Provisioner, packer.Communicator) error {
|
||||
return nil
|
||||
}
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ func TestProvisionerProvision_RestartCommandFail(t *testing.T) {
|
|||
comm.StartExitStatus = 1
|
||||
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ func TestProvisionerProvision_WaitForRestartFail(t *testing.T) {
|
|||
waitForCommunicator = func(context.Context, *Provisioner) error {
|
||||
return fmt.Errorf("Machine did not restart properly")
|
||||
}
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ func TestProvision_waitForRestartTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
go func() {
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
waitDone <- true
|
||||
}()
|
||||
<-waitContinue
|
||||
|
@ -327,7 +327,7 @@ func TestProvision_Cancel(t *testing.T) {
|
|||
// Create two go routines to provision and cancel in parallel
|
||||
// Provision will block until cancel happens
|
||||
go func() {
|
||||
done <- p.Provision(topCtx, ui, comm, make(map[interface{}]interface{}))
|
||||
done <- p.Provision(topCtx, ui, comm, make(map[string]interface{}))
|
||||
}()
|
||||
|
||||
// Expect interrupt error
|
||||
|
|
|
@ -156,7 +156,7 @@ func extractScript(p *Provisioner) (string, error) {
|
|||
return temp.Name(), nil
|
||||
}
|
||||
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ interface{}) error {
|
||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
||||
ui.Say(fmt.Sprintf("Provisioning with windows-shell..."))
|
||||
scripts := make([]string, len(p.config.Scripts))
|
||||
copy(scripts, p.config.Scripts)
|
||||
|
|
|
@ -292,7 +292,7 @@ func TestProvisionerProvision_Inline(t *testing.T) {
|
|||
p.config.PackerBuilderType = "iso"
|
||||
comm := new(packer.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err := p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ func TestProvisionerProvision_Inline(t *testing.T) {
|
|||
config["remote_path"] = "c:/Windows/Temp/inlineScript.bat"
|
||||
|
||||
p.Prepare(config)
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ func TestProvisionerProvision_Scripts(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
@ -381,7 +381,7 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[interface{}]interface{}))
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package interpolate
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
@ -166,7 +165,6 @@ func funcGenTemplateDir(ctx *Context) interface{} {
|
|||
|
||||
func funcGenGenerated(ctx *Context) interface{} {
|
||||
return func(s string) (string, error) {
|
||||
log.Printf("Megan context data is %#v", ctx.Data)
|
||||
if data, ok := ctx.Data.(map[string]string); ok {
|
||||
// PlaceholderData has been passed into generator, and we can check
|
||||
// the value against the placeholder data to make sure that it is
|
||||
|
|
Loading…
Reference in New Issue