hyper-v/vmcx: add missing InterpolateContext
This commit is contained in:
parent
d890051940
commit
eeeee3ec35
|
@ -98,6 +98,7 @@ type Config struct {
|
||||||
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
err := config.Decode(&b.config, &config.DecodeOpts{
|
err := config.Decode(&b.config, &config.DecodeOpts{
|
||||||
Interpolate: true,
|
Interpolate: true,
|
||||||
|
InterpolateContext: &b.config.ctx,
|
||||||
InterpolateFilter: &interpolate.RenderFilter{
|
InterpolateFilter: &interpolate.RenderFilter{
|
||||||
Exclude: []string{
|
Exclude: []string{
|
||||||
"boot_command",
|
"boot_command",
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package vmcx
|
package vmcx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"fmt"
|
hypervcommon "github.com/hashicorp/packer/builder/hyperv/common"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
@ -486,3 +488,53 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUserVariablesInBootCommand(t *testing.T) {
|
||||||
|
var b Builder
|
||||||
|
config := testConfig()
|
||||||
|
|
||||||
|
//Create vmxc folder
|
||||||
|
td, err := ioutil.TempDir("", "packer")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(td)
|
||||||
|
config["clone_from_vmxc_path"] = td
|
||||||
|
|
||||||
|
config[packer.UserVariablesConfigKey] = map[string]string{"test-variable": "test"}
|
||||||
|
config["boot_command"] = []string{"blah {{user `test-variable`}} blah"}
|
||||||
|
|
||||||
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not have error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ui := packer.TestUi(t)
|
||||||
|
cache := &packer.FileCache{CacheDir: os.TempDir()}
|
||||||
|
hook := &packer.MockHook{}
|
||||||
|
driver := &hypervcommon.DriverMock{}
|
||||||
|
|
||||||
|
// Set up the state.
|
||||||
|
state := new(multistep.BasicStateBag)
|
||||||
|
state.Put("cache", cache)
|
||||||
|
state.Put("config", &b.config)
|
||||||
|
state.Put("driver", driver)
|
||||||
|
state.Put("hook", hook)
|
||||||
|
state.Put("http_port", uint(0))
|
||||||
|
state.Put("ui", ui)
|
||||||
|
state.Put("vmName", "packer-foo")
|
||||||
|
|
||||||
|
step := &hypervcommon.StepTypeBootCommand{
|
||||||
|
BootCommand: b.config.BootCommand,
|
||||||
|
SwitchName: b.config.SwitchName,
|
||||||
|
Ctx: b.config.ctx,
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := step.Run(state)
|
||||||
|
if ret != multistep.ActionContinue {
|
||||||
|
t.Fatalf("should not have error: %s", ret)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue