From 556492fb0d54084846f1dcc37b29d9313fe000e2 Mon Sep 17 00:00:00 2001 From: Brendan Devenney Date: Wed, 24 Jul 2019 16:28:08 +0100 Subject: [PATCH 1/6] Add fixers erroneously removed by e8f04c3 Signed-off-by: Brendan Devenney --- fix/fixer.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fix/fixer.go b/fix/fixer.go index 4b0b1ad09..bd822a4c2 100644 --- a/fix/fixer.go +++ b/fix/fixer.go @@ -66,6 +66,8 @@ func init() { "docker-email", "powershell-escapes", "vmware-compaction", + "hyperv-deprecations", + "hyperv-vmxc-typo", "hyperv-cpu-and-ram", "clean-image-name", "spot-price-auto-product", From 9f0bc29db5fab772849b75ebd293c1e049fb37b8 Mon Sep 17 00:00:00 2001 From: Brendan Devenney Date: Wed, 24 Jul 2019 16:46:28 +0100 Subject: [PATCH 2/6] Test that Fixers and FixerOrder are equal length Signed-off-by: Brendan Devenney --- command/fix_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/command/fix_test.go b/command/fix_test.go index 966367c71..a49d5cd2f 100644 --- a/command/fix_test.go +++ b/command/fix_test.go @@ -1,6 +1,7 @@ package command import ( + "github.com/hashicorp/packer/fix" "path/filepath" "strings" "testing" @@ -61,3 +62,12 @@ func TestFix_invalidTemplateDisableValidation(t *testing.T) { fatalCommand(t, c.Meta) } } + +func TestFix_allFixersEnabled(t *testing.T) { + f := fix.Fixers + o := fix.FixerOrder + + if len(f) != len(o) { + t.Fatalf("Fixers length (%d) does not match FixerOrder length (%d)", len(f), len(o)) + } +} \ No newline at end of file From 91b7d8c5724776f0333d69b28a8660b0439afd5b Mon Sep 17 00:00:00 2001 From: Brendan Devenney Date: Wed, 24 Jul 2019 16:52:07 +0100 Subject: [PATCH 3/6] Add test to ensure all fixers are enabled Signed-off-by: Brendan Devenney --- command/fix_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/command/fix_test.go b/command/fix_test.go index a49d5cd2f..ee0d051ec 100644 --- a/command/fix_test.go +++ b/command/fix_test.go @@ -70,4 +70,19 @@ func TestFix_allFixersEnabled(t *testing.T) { if len(f) != len(o) { t.Fatalf("Fixers length (%d) does not match FixerOrder length (%d)", len(f), len(o)) } + + for fixer, _ := range(f) { + found := false + + for _, orderedFixer := range(o) { + if orderedFixer == fixer { + found = true + break + } + } + + if !found { + t.Fatalf("Did not find Fixer %s in FixerOrder", fixer) + } + } } \ No newline at end of file From 75d8d7fce5e2c1fe3120008c23e0b236c9c9c275 Mon Sep 17 00:00:00 2001 From: Brendan Devenney Date: Wed, 24 Jul 2019 17:18:07 +0100 Subject: [PATCH 4/6] Update and futureproof fix command usage * Dynamically generate the fixer documentation (in order) from FixerOrder * Update fixers which used linebreaks in their Synopsis Signed-off-by: Brendan Devenney --- command/fix.go | 48 ++++++----------------------- fix/fixer_parallels_deprecations.go | 3 +- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/command/fix.go b/command/fix.go index 227edc403..6185b2954 100644 --- a/command/fix.go +++ b/command/fix.go @@ -120,46 +120,16 @@ Usage: packer fix [options] TEMPLATE If the template cannot be fixed due to an error, the command will exit with a non-zero exit status. Error messages will appear on standard error. -Fixes that are run: - - iso-md5 Replaces "iso_md5" in builders with newer - "iso_checksum" - createtime Replaces ".CreateTime" in builder configs with - "{{timestamp}}" - virtualbox-gaattach Updates VirtualBox builders using - "guest_additions_attach" to use - "guest_additions_mode" - pp-vagrant-override Replaces old-style provider overrides for the - Vagrant post-processor to new-style as of Packer - 0.5.0. - virtualbox-rename Updates "virtualbox" builders to "virtualbox-iso" - vmware-rename Updates "vmware" builders to "vmware-iso" - parallels-headless Removes unused "headless" setting from Parallels - builders - parallels-deprecations Removes deprecated "parallels_tools_host_path" from - Parallels builders - sshkeypath Updates builders using "ssh_key_path" to use - "ssh_private_key_file" - sshdisableagent Updates builders using "ssh_disable_agent" to use - "ssh_disable_agent_forwarding" - manifest-filename Updates "manifest" post-processor so any "filename" - field is renamed to "output" - amazon-shutdown_behavior Changes "shutdown_behaviour" to "shutdown_behavior" - in Amazon builders - amazon-enhanced-networking Replaces "enhanced_networking" in builders with - "ena_support" - amazon-private-ip Replaces "ssh_private_ip": true in amazon builders - with "ssh_interface": "private_ip" - docker-email Removes "login_email" from the Docker builder - powershell-escapes Removes PowerShell escapes from user env vars and - elevated username and password strings - hyperv-deprecations Removes the deprecated "vhd_temp_path" setting from - Hyper-V ISO builder templates - hyperv-vmxc-typo Corrects a typo in the "clone_from_vmxc_path" - setting. Replaces with "clone_from_vmcx_path". - vmware-compaction Adds "skip_compaction = true" to "vmware-iso" - builders with incompatible disk_type_id +Fixes that are run (in order): +` + + for _, name := range fix.FixerOrder { + helpText += fmt.Sprintf( + "\t%-30s\t%s\n",name, fix.Fixers[name].Synopsis()) + } + + helpText += ` Options: -validate=true If true (default), validates the fixed template. diff --git a/fix/fixer_parallels_deprecations.go b/fix/fixer_parallels_deprecations.go index 9aff731ad..9afc22088 100644 --- a/fix/fixer_parallels_deprecations.go +++ b/fix/fixer_parallels_deprecations.go @@ -54,6 +54,5 @@ func (FixerParallelsDeprecations) Fix(input map[string]interface{}) (map[string] } func (FixerParallelsDeprecations) Synopsis() string { - return `Removes deprecated "parallels_tools_host_path" from Parallels builders - and changes "guest_os_distribution" to "guest_os_type".` + return `Removes deprecated "parallels_tools_host_path" from Parallels builders and changes "guest_os_distribution" to "guest_os_type".` } From 6520814a6c2c42ad86ad20ccbe0ef81e0ae8e2bd Mon Sep 17 00:00:00 2001 From: Brendan Devenney Date: Wed, 24 Jul 2019 17:40:05 +0100 Subject: [PATCH 5/6] Ensure help output is consistently formatted Signed-off-by: Brendan Devenney --- command/fix.go | 2 +- command/fix_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/command/fix.go b/command/fix.go index 6185b2954..8b33fa895 100644 --- a/command/fix.go +++ b/command/fix.go @@ -126,7 +126,7 @@ Fixes that are run (in order): for _, name := range fix.FixerOrder { helpText += fmt.Sprintf( - "\t%-30s\t%s\n",name, fix.Fixers[name].Synopsis()) + " %-27s%s\n", name, fix.Fixers[name].Synopsis()) } helpText += ` diff --git a/command/fix_test.go b/command/fix_test.go index ee0d051ec..c6ef8bf01 100644 --- a/command/fix_test.go +++ b/command/fix_test.go @@ -71,10 +71,10 @@ func TestFix_allFixersEnabled(t *testing.T) { t.Fatalf("Fixers length (%d) does not match FixerOrder length (%d)", len(f), len(o)) } - for fixer, _ := range(f) { + for fixer, _ := range f { found := false - for _, orderedFixer := range(o) { + for _, orderedFixer := range o { if orderedFixer == fixer { found = true break @@ -85,4 +85,4 @@ func TestFix_allFixersEnabled(t *testing.T) { t.Fatalf("Did not find Fixer %s in FixerOrder", fixer) } } -} \ No newline at end of file +} From 2b16b5cae47f6b3a7105eeccd5aa44cb069781e3 Mon Sep 17 00:00:00 2001 From: Brendan Devenney Date: Wed, 24 Jul 2019 18:01:14 +0100 Subject: [PATCH 6/6] Move fixer test to fix package Signed-off-by: Brendan Devenney --- command/fix_test.go | 25 ------------------------- fix/fixer_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 fix/fixer_test.go diff --git a/command/fix_test.go b/command/fix_test.go index c6ef8bf01..966367c71 100644 --- a/command/fix_test.go +++ b/command/fix_test.go @@ -1,7 +1,6 @@ package command import ( - "github.com/hashicorp/packer/fix" "path/filepath" "strings" "testing" @@ -62,27 +61,3 @@ func TestFix_invalidTemplateDisableValidation(t *testing.T) { fatalCommand(t, c.Meta) } } - -func TestFix_allFixersEnabled(t *testing.T) { - f := fix.Fixers - o := fix.FixerOrder - - if len(f) != len(o) { - t.Fatalf("Fixers length (%d) does not match FixerOrder length (%d)", len(f), len(o)) - } - - for fixer, _ := range f { - found := false - - for _, orderedFixer := range o { - if orderedFixer == fixer { - found = true - break - } - } - - if !found { - t.Fatalf("Did not find Fixer %s in FixerOrder", fixer) - } - } -} diff --git a/fix/fixer_test.go b/fix/fixer_test.go new file mode 100644 index 000000000..820c6dcf3 --- /dev/null +++ b/fix/fixer_test.go @@ -0,0 +1,29 @@ +package fix + +import ( + "testing" +) + +func TestFix_allFixersEnabled(t *testing.T) { + f := Fixers + o := FixerOrder + + if len(f) != len(o) { + t.Fatalf("Fixers length (%d) does not match FixerOrder length (%d)", len(f), len(o)) + } + + for fixer, _ := range f { + found := false + + for _, orderedFixer := range o { + if orderedFixer == fixer { + found = true + break + } + } + + if !found { + t.Fatalf("Did not find Fixer %s in FixerOrder", fixer) + } + } +}