diff options
Diffstat (limited to 'vendor/github.com/mitchellh/packer/fix')
5 files changed, 257 insertions, 11 deletions
diff --git a/vendor/github.com/mitchellh/packer/fix/fixer.go b/vendor/github.com/mitchellh/packer/fix/fixer.go index 3c285c4b..938a7160 100644 --- a/vendor/github.com/mitchellh/packer/fix/fixer.go +++ b/vendor/github.com/mitchellh/packer/fix/fixer.go @@ -20,17 +20,19 @@ var FixerOrder []string func init() { Fixers = map[string]Fixer{ - "iso-md5": new(FixerISOMD5), - "createtime": new(FixerCreateTime), - "pp-vagrant-override": new(FixerVagrantPPOverride), - "virtualbox-gaattach": new(FixerVirtualBoxGAAttach), - "virtualbox-rename": new(FixerVirtualBoxRename), - "vmware-rename": new(FixerVMwareRename), - "parallels-headless": new(FixerParallelsHeadless), - "parallels-deprecations": new(FixerParallelsDeprecations), - "sshkeypath": new(FixerSSHKeyPath), - "manifest-filename": new(FixerManifestFilename), - "amazon-shutdown_behavior": new(FixerAmazonShutdownBehavior), + "iso-md5": new(FixerISOMD5), + "createtime": new(FixerCreateTime), + "pp-vagrant-override": new(FixerVagrantPPOverride), + "virtualbox-gaattach": new(FixerVirtualBoxGAAttach), + "virtualbox-rename": new(FixerVirtualBoxRename), + "vmware-rename": new(FixerVMwareRename), + "parallels-headless": new(FixerParallelsHeadless), + "parallels-deprecations": new(FixerParallelsDeprecations), + "sshkeypath": new(FixerSSHKeyPath), + "sshdisableagent": new(FixerSSHDisableAgent), + "manifest-filename": new(FixerManifestFilename), + "amazon-shutdown_behavior": new(FixerAmazonShutdownBehavior), + "amazon-enhanced-networking": new(FixerAmazonEnhancedNetworking), } FixerOrder = []string{ @@ -43,7 +45,9 @@ func init() { "parallels-headless", "parallels-deprecations", "sshkeypath", + "sshdisableagent", "manifest-filename", "amazon-shutdown_behavior", + "amazon-enhanced-networking", } } diff --git a/vendor/github.com/mitchellh/packer/fix/fixer_amazon_enhanced_networking.go b/vendor/github.com/mitchellh/packer/fix/fixer_amazon_enhanced_networking.go new file mode 100644 index 00000000..4c9330eb --- /dev/null +++ b/vendor/github.com/mitchellh/packer/fix/fixer_amazon_enhanced_networking.go @@ -0,0 +1,45 @@ +package fix + +import ( + "github.com/mitchellh/mapstructure" +) + +// FixerAmazonEnhancedNetworking is a Fixer that replaces the "enhanced_networking" configuration key +// with the clearer "ena_support". This disambiguates ena_support from sriov_support. +type FixerAmazonEnhancedNetworking struct{} + +func (FixerAmazonEnhancedNetworking) Fix(input map[string]interface{}) (map[string]interface{}, error) { + // Our template type we'll use for this fixer only + type template struct { + Builders []map[string]interface{} + } + + // Decode the input into our structure, if we can + var tpl template + if err := mapstructure.Decode(input, &tpl); err != nil { + return nil, err + } + + // Go through each builder and replace the enhanced_networking if we can + for _, builder := range tpl.Builders { + enhancedNetworkingRaw, ok := builder["enhanced_networking"] + if !ok { + continue + } + enhancedNetworkingString, ok := enhancedNetworkingRaw.(bool) + if !ok { + // TODO: error? + continue + } + + delete(builder, "enhanced_networking") + builder["ena_support"] = enhancedNetworkingString + } + + input["builders"] = tpl.Builders + return input, nil +} + +func (FixerAmazonEnhancedNetworking) Synopsis() string { + return `Replaces "enhanced_networking" in builders with "ena_support"` +} diff --git a/vendor/github.com/mitchellh/packer/fix/fixer_amazon_enhanced_networking_test.go b/vendor/github.com/mitchellh/packer/fix/fixer_amazon_enhanced_networking_test.go new file mode 100644 index 00000000..f8b5be17 --- /dev/null +++ b/vendor/github.com/mitchellh/packer/fix/fixer_amazon_enhanced_networking_test.go @@ -0,0 +1,64 @@ +package fix + +import ( + "reflect" + "testing" +) + +func TestFixerAmazonEnhancedNetworking_Impl(t *testing.T) { + var _ Fixer = new(FixerAmazonEnhancedNetworking) +} + +func TestFixerAmazonEnhancedNetworking(t *testing.T) { + cases := []struct { + Input map[string]interface{} + Expected map[string]interface{} + }{ + // Attach field == false + { + Input: map[string]interface{}{ + "type": "ebs", + "enhanced_networking": false, + }, + + Expected: map[string]interface{}{ + "type": "ebs", + "ena_support": false, + }, + }, + + // Attach field == true + { + Input: map[string]interface{}{ + "type": "ebs", + "enhanced_networking": true, + }, + + Expected: map[string]interface{}{ + "type": "ebs", + "ena_support": true, + }, + }, + } + + for _, tc := range cases { + var f FixerAmazonEnhancedNetworking + + input := map[string]interface{}{ + "builders": []map[string]interface{}{tc.Input}, + } + + expected := map[string]interface{}{ + "builders": []map[string]interface{}{tc.Expected}, + } + + output, err := f.Fix(input) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !reflect.DeepEqual(output, expected) { + t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) + } + } +} diff --git a/vendor/github.com/mitchellh/packer/fix/fixer_sshdisableagent.go b/vendor/github.com/mitchellh/packer/fix/fixer_sshdisableagent.go new file mode 100644 index 00000000..b399af52 --- /dev/null +++ b/vendor/github.com/mitchellh/packer/fix/fixer_sshdisableagent.go @@ -0,0 +1,50 @@ +package fix + +import ( + "github.com/mitchellh/mapstructure" +) + +// FixerSSHDisableAgent changes the "ssh_disable_agent" of a template +// to "ssh_disable_agent_forwarding". +type FixerSSHDisableAgent struct{} + +func (FixerSSHDisableAgent) Fix(input map[string]interface{}) (map[string]interface{}, error) { + // The type we'll decode into; we only care about builders + type template struct { + Builders []map[string]interface{} + } + + // Decode the input into our structure, if we can + var tpl template + if err := mapstructure.Decode(input, &tpl); err != nil { + return nil, err + } + + for _, builder := range tpl.Builders { + sshDisableAgentRaw, ok := builder["ssh_disable_agent"] + if !ok { + continue + } + + sshDisableAgent, ok := sshDisableAgentRaw.(bool) + if !ok { + continue + } + + // only assign to ssh_disable_agent_forwarding if it doesn't + // already exist; otherwise we'll just ignore ssh_disable_agent + _, sshDisableAgentIncluded := builder["ssh_disable_agent_forwarding"] + if !sshDisableAgentIncluded { + builder["ssh_disable_agent_forwarding"] = sshDisableAgent + } + + delete(builder, "ssh_disable_agent") + } + + input["builders"] = tpl.Builders + return input, nil +} + +func (FixerSSHDisableAgent) Synopsis() string { + return `Updates builders using "ssh_disable_agent" to use "ssh_disable_agent_forwarding"` +} diff --git a/vendor/github.com/mitchellh/packer/fix/fixer_sshdisableagent_test.go b/vendor/github.com/mitchellh/packer/fix/fixer_sshdisableagent_test.go new file mode 100644 index 00000000..c38f9c58 --- /dev/null +++ b/vendor/github.com/mitchellh/packer/fix/fixer_sshdisableagent_test.go @@ -0,0 +1,83 @@ +package fix + +import ( + "reflect" + "testing" +) + +func TestFixerSSHDisableAgent_Impl(t *testing.T) { + var _ Fixer = new(FixerSSHDisableAgent) +} + +func TestFixerSSHDisableAgent_Fix(t *testing.T) { + cases := []struct { + Input map[string]interface{} + Expected map[string]interface{} + }{ + // No disable_agent field + { + Input: map[string]interface{}{ + "type": "virtualbox", + }, + + Expected: map[string]interface{}{ + "type": "virtualbox", + }, + }, + + // disable_agent_forwarding without disable_agent + { + Input: map[string]interface{}{ + "ssh_disable_agent_forwarding": true, + }, + + Expected: map[string]interface{}{ + "ssh_disable_agent_forwarding": true, + }, + }, + + // disable_agent without disable_agent_forwarding + { + Input: map[string]interface{}{ + "ssh_disable_agent": true, + }, + + Expected: map[string]interface{}{ + "ssh_disable_agent_forwarding": true, + }, + }, + + // disable_agent and disable_agent_forwarding + { + Input: map[string]interface{}{ + "ssh_disable_agent": true, + "ssh_disable_agent_forwarding": false, + }, + + Expected: map[string]interface{}{ + "ssh_disable_agent_forwarding": false, + }, + }, + } + + for _, tc := range cases { + var f FixerSSHDisableAgent + + input := map[string]interface{}{ + "builders": []map[string]interface{}{tc.Input}, + } + + expected := map[string]interface{}{ + "builders": []map[string]interface{}{tc.Expected}, + } + + output, err := f.Fix(input) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !reflect.DeepEqual(output, expected) { + t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) + } + } +} |