From ed6d999b1f6ba48754cf173d8585fc40bcf7c1cb Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 27 Apr 2018 11:24:08 -0700 Subject: [PATCH 01/24] add windows-sql-cloud to the list of projects to check for an image name --- builder/googlecompute/driver_gce.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/googlecompute/driver_gce.go b/builder/googlecompute/driver_gce.go index 91f20a58a..e24c4c768 100644 --- a/builder/googlecompute/driver_gce.go +++ b/builder/googlecompute/driver_gce.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "google.golang.org/api/compute/v1" + compute "google.golang.org/api/compute/v1" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/useragent" @@ -168,7 +168,7 @@ func (d *driverGCE) DeleteDisk(zone, name string) (<-chan error, error) { } func (d *driverGCE) GetImage(name string, fromFamily bool) (*Image, error) { - projects := []string{d.projectId, "centos-cloud", "coreos-cloud", "cos-cloud", "debian-cloud", "google-containers", "opensuse-cloud", "rhel-cloud", "suse-cloud", "ubuntu-os-cloud", "windows-cloud", "gce-nvme"} + projects := []string{d.projectId, "centos-cloud", "coreos-cloud", "cos-cloud", "debian-cloud", "google-containers", "opensuse-cloud", "rhel-cloud", "suse-cloud", "ubuntu-os-cloud", "windows-cloud", "gce-nvme", "windows-sql-cloud"} var errs error for _, project := range projects { image, err := d.GetImageFromProject(project, name, fromFamily) From c27f3e944504704139694e5713087aa187eb58e6 Mon Sep 17 00:00:00 2001 From: AlessioT Date: Sat, 28 Apr 2018 11:00:33 +0100 Subject: [PATCH 02/24] alessio.tomasino@yahoo.co.uk --- builder/amazon/ebs/step_create_ami.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index 0dde4fc30..bee540da9 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -52,13 +52,16 @@ func (s *stepCreateAMI) Run(_ context.Context, state multistep.StateBag) multist ui.Say("Waiting for AMI to become ready...") if _, err := awscommon.WaitForState(&stateChange); err != nil { - err := fmt.Errorf("Error waiting for AMI: %s", err) + imagesResp, _ := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) + stateReason := imagesResp.Images[0].StateReason.Message + err := fmt.Errorf("Error waiting for AMI: %s. Cause: %s", err, *stateReason) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } imagesResp, err := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) + if err != nil { err := fmt.Errorf("Error searching for AMI: %s", err) state.Put("error", err) From 09bb21774d30f3768806cc94e688448e0950621b Mon Sep 17 00:00:00 2001 From: AlessioT Date: Sat, 28 Apr 2018 11:02:53 +0100 Subject: [PATCH 03/24] alessio.tomasino@yahoo.co.uk --- builder/amazon/ebs/step_create_ami.go | 1 - 1 file changed, 1 deletion(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index bee540da9..1c3bd18e2 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -61,7 +61,6 @@ func (s *stepCreateAMI) Run(_ context.Context, state multistep.StateBag) multist } imagesResp, err := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) - if err != nil { err := fmt.Errorf("Error searching for AMI: %s", err) state.Put("error", err) From 373226e9c516be93d9d016fd6d082536bd6d4fe5 Mon Sep 17 00:00:00 2001 From: AlessioT Date: Sat, 28 Apr 2018 12:40:48 +0100 Subject: [PATCH 04/24] Extract state reason for failure --- builder/amazon/ebs/step_create_ami.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index 1c3bd18e2..254311fcd 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -54,7 +54,7 @@ func (s *stepCreateAMI) Run(_ context.Context, state multistep.StateBag) multist if _, err := awscommon.WaitForState(&stateChange); err != nil { imagesResp, _ := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) stateReason := imagesResp.Images[0].StateReason.Message - err := fmt.Errorf("Error waiting for AMI: %s. Cause: %s", err, *stateReason) + err := fmt.Errorf("Error waiting for AMI: %s. Root cause: %s", err, *stateReason) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt From 7e478f650e83b8fc115bcbf2a2cae63f78fdf978 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 12:25:45 +0100 Subject: [PATCH 05/24] Remove tmp files created by common/ tests --- common/download_test.go | 12 ++++++++++-- common/iso_config_test.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/common/download_test.go b/common/download_test.go index beac9cbab..ae22fbc09 100644 --- a/common/download_test.go +++ b/common/download_test.go @@ -60,6 +60,7 @@ func TestDownloadClient_basic(t *testing.T) { TargetPath: tf.Name(), CopyFile: true, }) + defer os.Remove(tf.Name()) path, err := client.Get() if err != nil { @@ -96,6 +97,7 @@ func TestDownloadClient_checksumBad(t *testing.T) { Checksum: checksum, CopyFile: true, }) + defer os.Remove(tf.Name()) if _, err := client.Get(); err == nil { t.Fatal("should error") } @@ -121,6 +123,7 @@ func TestDownloadClient_checksumGood(t *testing.T) { Checksum: checksum, CopyFile: true, }) + defer os.Remove(tf.Name()) path, err := client.Get() if err != nil { t.Fatalf("err: %s", err) @@ -191,6 +194,7 @@ func TestDownloadClient_resume(t *testing.T) { TargetPath: tf.Name(), CopyFile: true, }) + defer os.Remove(tf.Name()) path, err := client.Get() if err != nil { t.Fatalf("err: %s", err) @@ -211,7 +215,8 @@ func TestDownloadClient_usesDefaultUserAgent(t *testing.T) { if err != nil { t.Fatalf("tempfile error: %s", err) } - defer os.Remove(tf.Name()) + tf.Close() + os.Remove(tf.Name()) defaultUserAgent := "" asserted := false @@ -249,6 +254,7 @@ func TestDownloadClient_usesDefaultUserAgent(t *testing.T) { TargetPath: tf.Name(), CopyFile: true, } + defer os.Remove(tf.Name()) client := NewDownloadClient(config) _, err = client.Get() @@ -266,7 +272,8 @@ func TestDownloadClient_setsUserAgent(t *testing.T) { if err != nil { t.Fatalf("tempfile error: %s", err) } - defer os.Remove(tf.Name()) + tf.Close() + os.Remove(tf.Name()) asserted := false server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -281,6 +288,7 @@ func TestDownloadClient_setsUserAgent(t *testing.T) { UserAgent: "fancy user agent", CopyFile: true, } + defer os.Remove(tf.Name()) client := NewDownloadClient(config) _, err = client.Get() diff --git a/common/iso_config_test.go b/common/iso_config_test.go index f31c687b2..b465bead8 100644 --- a/common/iso_config_test.go +++ b/common/iso_config_test.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "net/http" "net/http/httptest" + "os" "reflect" "runtime" "testing" @@ -90,6 +91,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) { i = testISOConfig() i.ISOChecksum = "" cs_file, _ := ioutil.TempFile("", "packer-test-") + defer os.Remove(cs_file.Name()) + defer cs_file.Close() ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style), 0666) filePrefix := "file://" if runtime.GOOS == "windows" { @@ -112,6 +115,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) { i = testISOConfig() i.ISOChecksum = "" cs_file, _ = ioutil.TempFile("", "packer-test-") + defer os.Remove(cs_file.Name()) + defer cs_file.Close() ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0666) i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name()) warns, err = i.Prepare(nil) @@ -130,6 +135,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) { i = testISOConfig() i.ISOChecksum = "" cs_file, _ = ioutil.TempFile("", "packer-test-") + defer os.Remove(cs_file.Name()) + defer cs_file.Close() ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style_no_newline), 0666) i.ISOChecksumURL = fmt.Sprintf("file://%s", cs_file.Name()) warns, err = i.Prepare(nil) @@ -150,6 +157,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) { cs_dir, _ := ioutil.TempDir("", "packer-testdir-") cs_file, _ = ioutil.TempFile(cs_dir, "packer-test-") + defer os.RemoveAll(cs_dir) // Removes the file as well + defer cs_file.Close() ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style_subdir), 0666) i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name()) i.RawSingleISOUrl = fmt.Sprintf("%s%s", cs_dir, "/subdir/the-OS.iso") @@ -169,6 +178,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) { i = testISOConfig() i.ISOChecksum = "" cs_file, _ = ioutil.TempFile("", "packer-test-") + defer os.Remove(cs_file.Name()) + defer cs_file.Close() ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style_no_newline), 0666) i.ISOChecksumURL = fmt.Sprintf("file://%s", cs_file.Name()) warns, err = i.Prepare(nil) @@ -189,6 +200,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) { i.RawSingleISOUrl = "http://www.packer.io/the-OS.iso?stuff=boo" cs_file, _ = ioutil.TempFile("", "packer-test-") + defer os.Remove(cs_file.Name()) + defer cs_file.Close() ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0666) i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name()) warns, err = i.Prepare(nil) @@ -208,6 +221,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) { i.ISOChecksum = "" cs_file, _ = ioutil.TempFile(cs_dir, "packer-test-") + defer os.Remove(cs_file.Name()) + defer cs_file.Close() ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style_subdir), 0666) i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name()) i.RawSingleISOUrl = fmt.Sprintf("%s%s", cs_dir, "/subdir/the-OS.iso") From 96adb4a9d1577b1c22344983d0c46ea101202a82 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 12:30:54 +0100 Subject: [PATCH 06/24] Remove tmp files created by builder/alicloud/ecs tests --- builder/alicloud/ecs/run_config_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builder/alicloud/ecs/run_config_test.go b/builder/alicloud/ecs/run_config_test.go index d62f60b38..fe499e21f 100644 --- a/builder/alicloud/ecs/run_config_test.go +++ b/builder/alicloud/ecs/run_config_test.go @@ -2,6 +2,7 @@ package ecs import ( "io/ioutil" + "os" "testing" "github.com/hashicorp/packer/helper/communicator" @@ -68,6 +69,7 @@ func TestRunConfigPrepare_UserData(t *testing.T) { if err != nil { t.Fatalf("err: %s", err) } + defer os.Remove(tf.Name()) defer tf.Close() c.UserData = "foo" @@ -92,6 +94,7 @@ func TestRunConfigPrepare_UserDataFile(t *testing.T) { if err != nil { t.Fatalf("err: %s", err) } + defer os.Remove(tf.Name()) defer tf.Close() c.UserDataFile = tf.Name() From 54e9690dff30c36a5c2b2b01e794652b706c933b Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 12:39:55 +0100 Subject: [PATCH 07/24] Remove tmp files created by builder/amazon/common tests --- builder/amazon/common/run_config_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builder/amazon/common/run_config_test.go b/builder/amazon/common/run_config_test.go index 7cf42ded1..a88730e82 100644 --- a/builder/amazon/common/run_config_test.go +++ b/builder/amazon/common/run_config_test.go @@ -119,6 +119,7 @@ func TestRunConfigPrepare_UserData(t *testing.T) { if err != nil { t.Fatalf("err: %s", err) } + defer os.Remove(tf.Name()) defer tf.Close() c.UserData = "foo" @@ -143,6 +144,7 @@ func TestRunConfigPrepare_UserDataFile(t *testing.T) { if err != nil { t.Fatalf("err: %s", err) } + defer os.Remove(tf.Name()) defer tf.Close() c.UserDataFile = tf.Name() From 9b6fc5a58ddd6830ad2d00033d10174aa23985bf Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 13:23:36 +0100 Subject: [PATCH 08/24] Remove tmp files created by builder/amazon/instance tests --- builder/amazon/instance/builder_test.go | 44 ++++++++++++++++++------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/builder/amazon/instance/builder_test.go b/builder/amazon/instance/builder_test.go index 4136d57fe..1ad77d82b 100644 --- a/builder/amazon/instance/builder_test.go +++ b/builder/amazon/instance/builder_test.go @@ -8,13 +8,13 @@ import ( "github.com/hashicorp/packer/packer" ) -func testConfig() map[string]interface{} { +func testConfig() (config map[string]interface{}, tf *os.File) { tf, err := ioutil.TempFile("", "packer") if err != nil { panic(err) } - return map[string]interface{}{ + config = map[string]interface{}{ "account_id": "foo", "ami_name": "foo", "instance_type": "m1.small", @@ -26,6 +26,8 @@ func testConfig() map[string]interface{} { "x509_key_path": tf.Name(), "x509_upload_path": "/foo", } + + return config, tf } func TestBuilder_ImplementsBuilder(t *testing.T) { @@ -38,7 +40,9 @@ func TestBuilder_ImplementsBuilder(t *testing.T) { func TestBuilderPrepare_AccountId(t *testing.T) { b := &Builder{} - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() config["account_id"] = "" warnings, err := b.Prepare(config) @@ -74,7 +78,9 @@ func TestBuilderPrepare_AccountId(t *testing.T) { func TestBuilderPrepare_AMIName(t *testing.T) { var b Builder - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() // Test good config["ami_name"] = "foo" @@ -111,7 +117,9 @@ func TestBuilderPrepare_AMIName(t *testing.T) { func TestBuilderPrepare_BundleDestination(t *testing.T) { b := &Builder{} - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() config["bundle_destination"] = "" warnings, err := b.Prepare(config) @@ -129,7 +137,9 @@ func TestBuilderPrepare_BundleDestination(t *testing.T) { func TestBuilderPrepare_BundlePrefix(t *testing.T) { b := &Builder{} - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() warnings, err := b.Prepare(config) if len(warnings) > 0 { @@ -146,7 +156,9 @@ func TestBuilderPrepare_BundlePrefix(t *testing.T) { func TestBuilderPrepare_InvalidKey(t *testing.T) { var b Builder - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() // Add a random key config["i_should_not_be_valid"] = true @@ -161,7 +173,9 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) { func TestBuilderPrepare_S3Bucket(t *testing.T) { b := &Builder{} - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() config["s3_bucket"] = "" warnings, err := b.Prepare(config) @@ -184,7 +198,9 @@ func TestBuilderPrepare_S3Bucket(t *testing.T) { func TestBuilderPrepare_X509CertPath(t *testing.T) { b := &Builder{} - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() config["x509_cert_path"] = "" warnings, err := b.Prepare(config) @@ -209,6 +225,7 @@ func TestBuilderPrepare_X509CertPath(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["x509_cert_path"] = tf.Name() warnings, err = b.Prepare(config) @@ -222,7 +239,9 @@ func TestBuilderPrepare_X509CertPath(t *testing.T) { func TestBuilderPrepare_X509KeyPath(t *testing.T) { b := &Builder{} - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() config["x509_key_path"] = "" warnings, err := b.Prepare(config) @@ -247,6 +266,7 @@ func TestBuilderPrepare_X509KeyPath(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["x509_key_path"] = tf.Name() warnings, err = b.Prepare(config) @@ -260,7 +280,9 @@ func TestBuilderPrepare_X509KeyPath(t *testing.T) { func TestBuilderPrepare_X509UploadPath(t *testing.T) { b := &Builder{} - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() config["x509_upload_path"] = "" warnings, err := b.Prepare(config) From 5642f8cb012a04cb70aa94b08c8b4e49e2605aa1 Mon Sep 17 00:00:00 2001 From: DanHam Date: Mon, 30 Apr 2018 20:36:48 +0100 Subject: [PATCH 09/24] Remove tmp files created by builder/googlecompute tests --- builder/googlecompute/config_test.go | 38 ++++++++++++++----- .../googlecompute/step_create_ssh_key_test.go | 1 + .../step_create_windows_password_test.go | 1 + 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/builder/googlecompute/config_test.go b/builder/googlecompute/config_test.go index d3ed84506..2da3faa59 100644 --- a/builder/googlecompute/config_test.go +++ b/builder/googlecompute/config_test.go @@ -3,6 +3,7 @@ package googlecompute import ( "fmt" "io/ioutil" + "os" "strings" "testing" ) @@ -199,7 +200,8 @@ func TestConfigPrepare(t *testing.T) { } for _, tc := range cases { - raw := testConfig(t) + raw, tempfile := testConfig(t) + defer os.Remove(tempfile) if tc.Value == nil { delete(raw, tc.Key) @@ -251,7 +253,8 @@ func TestConfigPrepareAccelerator(t *testing.T) { } for _, tc := range cases { - raw := testConfig(t) + raw, tempfile := testConfig(t) + defer os.Remove(tempfile) errStr := "" for k := range tc.Keys { @@ -300,7 +303,8 @@ func TestConfigPrepareServiceAccount(t *testing.T) { } for _, tc := range cases { - raw := testConfig(t) + raw, tempfile := testConfig(t) + defer os.Remove(tempfile) errStr := "" for k := range tc.Keys { @@ -342,7 +346,8 @@ func TestConfigDefaults(t *testing.T) { } for _, tc := range cases { - raw := testConfig(t) + raw, tempfile := testConfig(t) + defer os.Remove(tempfile) c, warns, errs := NewConfig(raw) testConfigOk(t, warns, errs) @@ -355,7 +360,10 @@ func TestConfigDefaults(t *testing.T) { } func TestImageName(t *testing.T) { - c, _, _ := NewConfig(testConfig(t)) + raw, tempfile := testConfig(t) + defer os.Remove(tempfile) + + c, _, _ := NewConfig(raw) if !strings.HasPrefix(c.ImageName, "packer-") { t.Fatalf("ImageName should have 'packer-' prefix, found %s", c.ImageName) } @@ -365,7 +373,10 @@ func TestImageName(t *testing.T) { } func TestRegion(t *testing.T) { - c, _, _ := NewConfig(testConfig(t)) + raw, tempfile := testConfig(t) + defer os.Remove(tempfile) + + c, _, _ := NewConfig(raw) if c.Region != "us-east1" { t.Fatalf("Region should be 'us-east1' given Zone of 'us-east1-a', but is %s", c.Region) } @@ -373,9 +384,11 @@ func TestRegion(t *testing.T) { // Helper stuff below -func testConfig(t *testing.T) map[string]interface{} { - return map[string]interface{}{ - "account_file": testAccountFile(t), +func testConfig(t *testing.T) (config map[string]interface{}, tempAccountFile string) { + tempAccountFile = testAccountFile(t) + + config = map[string]interface{}{ + "account_file": tempAccountFile, "project_id": "hashicorp", "source_image": "foo", "ssh_username": "root", @@ -389,10 +402,15 @@ func testConfig(t *testing.T) map[string]interface{} { }, "zone": "us-east1-a", } + + return config, tempAccountFile } func testConfigStruct(t *testing.T) *Config { - c, warns, errs := NewConfig(testConfig(t)) + raw, tempfile := testConfig(t) + defer os.Remove(tempfile) + + c, warns, errs := NewConfig(raw) if len(warns) > 0 { t.Fatalf("bad: %#v", len(warns)) } diff --git a/builder/googlecompute/step_create_ssh_key_test.go b/builder/googlecompute/step_create_ssh_key_test.go index bc1b2e6b5..5e5150738 100644 --- a/builder/googlecompute/step_create_ssh_key_test.go +++ b/builder/googlecompute/step_create_ssh_key_test.go @@ -55,6 +55,7 @@ func TestStepCreateSSHKey_debug(t *testing.T) { if err != nil { t.Fatalf("err: %s", err) } + defer os.Remove(tf.Name()) tf.Close() state := testState(t) diff --git a/builder/googlecompute/step_create_windows_password_test.go b/builder/googlecompute/step_create_windows_password_test.go index 3a58d4816..6abb6243d 100644 --- a/builder/googlecompute/step_create_windows_password_test.go +++ b/builder/googlecompute/step_create_windows_password_test.go @@ -75,6 +75,7 @@ func TestStepCreateOrResetWindowsPassword_debug(t *testing.T) { if err != nil { t.Fatalf("err: %s", err) } + defer os.Remove(tf.Name()) tf.Close() state := testState(t) From 475b3978d25fe1feacd504ce317bc4cc17fb33f1 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 14:59:44 +0100 Subject: [PATCH 10/24] Remove tmp directories created by builder/parallels/common tests --- builder/parallels/common/driver_9_test.go | 5 +++-- builder/parallels/common/step_output_dir_test.go | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/builder/parallels/common/driver_9_test.go b/builder/parallels/common/driver_9_test.go index 32d7c6662..bc9d3eb42 100644 --- a/builder/parallels/common/driver_9_test.go +++ b/builder/parallels/common/driver_9_test.go @@ -16,6 +16,7 @@ func TestIPAddress(t *testing.T) { t.Fatalf("err: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() d := Parallels9Driver{ dhcpLeaseFile: tf.Name(), @@ -62,9 +63,9 @@ func TestIPAddress(t *testing.T) { func TestXMLParseConfig(t *testing.T) { td, err := ioutil.TempDir("", "configpvs") if err != nil { - t.Fatalf("Error creating temp file: %s", err) + t.Fatalf("Error creating temp dir: %s", err) } - defer os.Remove(td) + defer os.RemoveAll(td) config := []byte(` diff --git a/builder/parallels/common/step_output_dir_test.go b/builder/parallels/common/step_output_dir_test.go index 17d441457..53c1d885c 100644 --- a/builder/parallels/common/step_output_dir_test.go +++ b/builder/parallels/common/step_output_dir_test.go @@ -28,6 +28,8 @@ func TestStepOutputDir_impl(t *testing.T) { func TestStepOutputDir(t *testing.T) { state := testState(t) step := testStepOutputDir(t) + // Delete the test output directory when done + defer os.RemoveAll(step.Path) // Test the run if action := step.Run(context.Background(), state); action != multistep.ActionContinue { From 13b7078cb04b156d7b208fa74738f9f1188505b4 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 15:39:20 +0100 Subject: [PATCH 11/24] Remove tmp directories created by builder/virtualbox/common tests --- builder/virtualbox/common/step_output_dir_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builder/virtualbox/common/step_output_dir_test.go b/builder/virtualbox/common/step_output_dir_test.go index 1e2f05c84..766154ca9 100644 --- a/builder/virtualbox/common/step_output_dir_test.go +++ b/builder/virtualbox/common/step_output_dir_test.go @@ -28,6 +28,7 @@ func TestStepOutputDir_impl(t *testing.T) { func TestStepOutputDir(t *testing.T) { state := testState(t) step := testStepOutputDir(t) + defer os.RemoveAll(step.Path) // Test the run if action := step.Run(context.Background(), state); action != multistep.ActionContinue { @@ -55,6 +56,7 @@ func TestStepOutputDir_exists(t *testing.T) { if err := os.MkdirAll(step.Path, 0755); err != nil { t.Fatalf("bad: %s", err) } + defer os.RemoveAll(step.Path) // Test the run if action := step.Run(context.Background(), state); action != multistep.ActionHalt { From 25dd27a164355efbbf1dcb0df51f282a3734c0a1 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 17:07:38 +0100 Subject: [PATCH 12/24] Remove tmp directories created by builder/vmware/common tests --- builder/vmware/common/step_output_dir_test.go | 4 ++++ builder/vmware/common/step_shutdown_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/builder/vmware/common/step_output_dir_test.go b/builder/vmware/common/step_output_dir_test.go index fe71bbea8..3726a9354 100644 --- a/builder/vmware/common/step_output_dir_test.go +++ b/builder/vmware/common/step_output_dir_test.go @@ -30,6 +30,8 @@ func TestStepOutputDir(t *testing.T) { step := new(StepOutputDir) dir := testOutputDir(t) + // Delete the test output directory when done + defer os.RemoveAll(dir.dir) state.Put("dir", dir) // Test the run @@ -61,6 +63,7 @@ func TestStepOutputDir_existsNoForce(t *testing.T) { if err := os.MkdirAll(dir.dir, 0755); err != nil { t.Fatalf("err: %s", err) } + defer os.RemoveAll(dir.dir) // Test the run if action := step.Run(context.Background(), state); action != multistep.ActionHalt { @@ -89,6 +92,7 @@ func TestStepOutputDir_existsForce(t *testing.T) { if err := os.MkdirAll(dir.dir, 0755); err != nil { t.Fatalf("err: %s", err) } + defer os.RemoveAll(dir.dir) // Test the run if action := step.Run(context.Background(), state); action != multistep.ActionContinue { diff --git a/builder/vmware/common/step_shutdown_test.go b/builder/vmware/common/step_shutdown_test.go index ff775f2f2..0c3d98589 100644 --- a/builder/vmware/common/step_shutdown_test.go +++ b/builder/vmware/common/step_shutdown_test.go @@ -85,6 +85,12 @@ func TestStepShutdown_command(t *testing.T) { if comm.StartCmd.Command != "foo" { t.Fatalf("bad: %#v", comm.StartCmd.Command) } + + // Clean up the created test output directory + dir := state.Get("dir").(*LocalOutputDir) + if err := dir.RemoveAll(); err != nil { + t.Fatalf("Error cleaning up directory: %s", err) + } } func TestStepShutdown_noCommand(t *testing.T) { @@ -113,6 +119,12 @@ func TestStepShutdown_noCommand(t *testing.T) { if comm.StartCalled { t.Fatal("start should not be called") } + + // Clean up the created test output directory + dir := state.Get("dir").(*LocalOutputDir) + if err := dir.RemoveAll(); err != nil { + t.Fatalf("Error cleaning up directory: %s", err) + } } func TestStepShutdown_locks(t *testing.T) { From fd07cfd2b169643cd7bb323426eaca6975dda013 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 19:49:13 +0100 Subject: [PATCH 13/24] Remove tmp files created by provisioner/puppet-masterless tests --- .../puppet-masterless/provisioner_test.go | 67 ++++++++++++++----- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/provisioner/puppet-masterless/provisioner_test.go b/provisioner/puppet-masterless/provisioner_test.go index dd6725768..294534779 100644 --- a/provisioner/puppet-masterless/provisioner_test.go +++ b/provisioner/puppet-masterless/provisioner_test.go @@ -13,15 +13,17 @@ import ( "github.com/stretchr/testify/assert" ) -func testConfig() map[string]interface{} { +func testConfig() (config map[string]interface{}, tf *os.File) { tf, err := ioutil.TempFile("", "packer") if err != nil { panic(err) } - return map[string]interface{}{ + config = map[string]interface{}{ "manifest_file": tf.Name(), } + + return config, tf } func TestProvisioner_Impl(t *testing.T) { @@ -33,7 +35,10 @@ func TestProvisioner_Impl(t *testing.T) { } func TestGuestOSConfig_empty_unix(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() + p := new(Provisioner) err := p.Prepare(config) if err != nil { @@ -58,7 +63,10 @@ func TestGuestOSConfig_empty_unix(t *testing.T) { } func TestGuestOSConfig_full_unix(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() + p := new(Provisioner) err := p.Prepare(config) if err != nil { @@ -95,7 +103,10 @@ func TestGuestOSConfig_full_unix(t *testing.T) { } func TestGuestOSConfig_empty_windows(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() + config["guest_os_type"] = "windows" p := new(Provisioner) err := p.Prepare(config) @@ -120,7 +131,10 @@ func TestGuestOSConfig_empty_windows(t *testing.T) { } func TestGuestOSConfig_full_windows(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() + config["guest_os_type"] = "windows" p := new(Provisioner) err := p.Prepare(config) @@ -158,7 +172,9 @@ func TestGuestOSConfig_full_windows(t *testing.T) { } func TestProvisionerPrepare_puppetBinDir(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "puppet_bin_dir") p := new(Provisioner) @@ -183,7 +199,9 @@ func TestProvisionerPrepare_puppetBinDir(t *testing.T) { } func TestProvisionerPrepare_hieraConfigPath(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "hiera_config_path") p := new(Provisioner) @@ -208,7 +226,9 @@ func TestProvisionerPrepare_hieraConfigPath(t *testing.T) { } func TestProvisionerPrepare_manifestFile(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "manifest_file") p := new(Provisioner) @@ -233,7 +253,9 @@ func TestProvisionerPrepare_manifestFile(t *testing.T) { } func TestProvisionerPrepare_manifestDir(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "manifestdir") p := new(Provisioner) @@ -258,7 +280,9 @@ func TestProvisionerPrepare_manifestDir(t *testing.T) { } func TestProvisionerPrepare_modulePaths(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "module_paths") p := new(Provisioner) @@ -291,7 +315,9 @@ func TestProvisionerPrepare_modulePaths(t *testing.T) { } func TestProvisionerPrepare_facterFacts(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "facter") p := new(Provisioner) @@ -346,7 +372,9 @@ func TestProvisionerPrepare_facterFacts(t *testing.T) { } func TestProvisionerPrepare_extraArguments(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() // Test with missing parameter delete(config, "extra_arguments") @@ -377,7 +405,9 @@ func TestProvisionerPrepare_extraArguments(t *testing.T) { } func TestProvisionerPrepare_stagingDir(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "staging_directory") p := new(Provisioner) @@ -405,7 +435,9 @@ func TestProvisionerPrepare_stagingDir(t *testing.T) { } func TestProvisionerPrepare_workingDir(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "working_directory") p := new(Provisioner) @@ -438,7 +470,10 @@ func TestProvisionerPrepare_workingDir(t *testing.T) { } func TestProvisionerProvision_extraArguments(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() + ui := &packer.MachineReadableUi{ Writer: ioutil.Discard, } From 70ccb8adffd0d929309cfb0cdf83110ae2f1b6f9 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 19:56:16 +0100 Subject: [PATCH 14/24] Remove tmp files created by provisioner/puppet-server tests --- provisioner/puppet-server/provisioner_test.go | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/provisioner/puppet-server/provisioner_test.go b/provisioner/puppet-server/provisioner_test.go index 4c7746c78..68e9369b6 100644 --- a/provisioner/puppet-server/provisioner_test.go +++ b/provisioner/puppet-server/provisioner_test.go @@ -8,15 +8,17 @@ import ( "github.com/hashicorp/packer/packer" ) -func testConfig() map[string]interface{} { +func testConfig() (config map[string]interface{}, tf *os.File) { tf, err := ioutil.TempFile("", "packer") if err != nil { panic(err) } - return map[string]interface{}{ + config = map[string]interface{}{ "puppet_server": tf.Name(), } + + return config, tf } func TestProvisioner_Impl(t *testing.T) { @@ -28,7 +30,9 @@ func TestProvisioner_Impl(t *testing.T) { } func TestProvisionerPrepare_puppetBinDir(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "puppet_bin_dir") p := new(Provisioner) @@ -53,7 +57,9 @@ func TestProvisionerPrepare_puppetBinDir(t *testing.T) { } func TestProvisionerPrepare_clientPrivateKeyPath(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "client_private_key_path") p := new(Provisioner) @@ -86,7 +92,9 @@ func TestProvisionerPrepare_clientPrivateKeyPath(t *testing.T) { } func TestProvisionerPrepare_clientCertPath(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "client_cert_path") p := new(Provisioner) @@ -119,7 +127,9 @@ func TestProvisionerPrepare_clientCertPath(t *testing.T) { } func TestProvisionerPrepare_executeCommand(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "execute_command") p := new(Provisioner) @@ -130,7 +140,9 @@ func TestProvisionerPrepare_executeCommand(t *testing.T) { } func TestProvisionerPrepare_facterFacts(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "facter") p := new(Provisioner) @@ -185,7 +197,9 @@ func TestProvisionerPrepare_facterFacts(t *testing.T) { } func TestProvisionerPrepare_stagingDir(t *testing.T) { - config := testConfig() + config, tempfile := testConfig() + defer os.Remove(tempfile.Name()) + defer tempfile.Close() delete(config, "staging_dir") p := new(Provisioner) From b738f41efad42eac7019950591478bba2a63d8c4 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 22:50:10 +0100 Subject: [PATCH 15/24] Remove tmp files created by provisioner/powershell tests --- provisioner/powershell/provisioner_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/provisioner/powershell/provisioner_test.go b/provisioner/powershell/provisioner_test.go index 06fe39ef7..7e739016c 100644 --- a/provisioner/powershell/provisioner_test.go +++ b/provisioner/powershell/provisioner_test.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io/ioutil" - //"log" "os" "regexp" "strings" @@ -30,6 +29,7 @@ func TestProvisionerPrepare_extractScript(t *testing.T) { p := new(Provisioner) _ = p.Prepare(config) file, err := extractScript(p) + defer os.Remove(file) if err != nil { t.Fatalf("Should not be error: %s", err) } @@ -177,6 +177,7 @@ func TestProvisionerPrepare_Script(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["script"] = tf.Name() p = new(Provisioner) @@ -203,6 +204,7 @@ func TestProvisionerPrepare_ScriptAndInline(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["inline"] = []interface{}{"foo"} config["script"] = tf.Name() @@ -222,6 +224,7 @@ func TestProvisionerPrepare_ScriptAndScripts(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["inline"] = []interface{}{"foo"} config["scripts"] = []string{tf.Name()} @@ -248,6 +251,7 @@ func TestProvisionerPrepare_Scripts(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["scripts"] = []string{tf.Name()} p = new(Provisioner) @@ -444,6 +448,8 @@ func TestProvisionerProvision_Inline(t *testing.T) { func TestProvisionerProvision_Scripts(t *testing.T) { tempFile, _ := ioutil.TempFile("", "packer") defer os.Remove(tempFile.Name()) + defer tempFile.Close() + config := testConfig() delete(config, "inline") config["scripts"] = []string{tempFile.Name()} @@ -473,6 +479,8 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) { config := testConfig() ui := testUi() defer os.Remove(tempFile.Name()) + defer tempFile.Close() + delete(config, "inline") config["scripts"] = []string{tempFile.Name()} From 69ac7b56f6cc3033457db42c8559fcadfae479a6 Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 25 Apr 2018 23:51:46 +0100 Subject: [PATCH 16/24] Remove tmp files created by provisioner/windows-shell tests --- provisioner/windows-shell/provisioner_test.go | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/provisioner/windows-shell/provisioner_test.go b/provisioner/windows-shell/provisioner_test.go index e0731da10..5f4149478 100644 --- a/provisioner/windows-shell/provisioner_test.go +++ b/provisioner/windows-shell/provisioner_test.go @@ -25,6 +25,7 @@ func TestProvisionerPrepare_extractScript(t *testing.T) { p := new(Provisioner) _ = p.Prepare(config) file, err := extractScript(p) + defer os.Remove(file) if err != nil { t.Fatalf("Should not be error: %s", err) } @@ -104,6 +105,7 @@ func TestProvisionerPrepare_Script(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["script"] = tf.Name() p = new(Provisioner) @@ -130,6 +132,7 @@ func TestProvisionerPrepare_ScriptAndInline(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["inline"] = []interface{}{"foo"} config["script"] = tf.Name() @@ -149,6 +152,7 @@ func TestProvisionerPrepare_ScriptAndScripts(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["inline"] = []interface{}{"foo"} config["scripts"] = []string{tf.Name()} @@ -175,6 +179,7 @@ func TestProvisionerPrepare_Scripts(t *testing.T) { t.Fatalf("error tempfile: %s", err) } defer os.Remove(tf.Name()) + defer tf.Close() config["scripts"] = []string{tf.Name()} p = new(Provisioner) @@ -322,11 +327,16 @@ func TestProvisionerProvision_Inline(t *testing.T) { } func TestProvisionerProvision_Scripts(t *testing.T) { - tempFile, _ := ioutil.TempFile("", "packer") - defer os.Remove(tempFile.Name()) + tf, err := ioutil.TempFile("", "packer") + if err != nil { + t.Fatalf("error tempfile: %s", err) + } + defer os.Remove(tf.Name()) + defer tf.Close() + config := testConfig() delete(config, "inline") - config["scripts"] = []string{tempFile.Name()} + config["scripts"] = []string{tf.Name()} config["packer_build_name"] = "foobuild" config["packer_builder_type"] = "footype" ui := testUi() @@ -334,7 +344,7 @@ func TestProvisionerProvision_Scripts(t *testing.T) { p := new(Provisioner) comm := new(packer.MockCommunicator) p.Prepare(config) - err := p.Provision(ui, comm) + err = p.Provision(ui, comm) if err != nil { t.Fatal("should not have error") } @@ -349,13 +359,18 @@ func TestProvisionerProvision_Scripts(t *testing.T) { } func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) { - tempFile, _ := ioutil.TempFile("", "packer") + tf, err := ioutil.TempFile("", "packer") + if err != nil { + t.Fatalf("error tempfile: %s", err) + } + defer os.Remove(tf.Name()) + defer tf.Close() + config := testConfig() ui := testUi() - defer os.Remove(tempFile.Name()) delete(config, "inline") - config["scripts"] = []string{tempFile.Name()} + config["scripts"] = []string{tf.Name()} config["packer_build_name"] = "foobuild" config["packer_builder_type"] = "footype" @@ -368,7 +383,7 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) { p := new(Provisioner) comm := new(packer.MockCommunicator) p.Prepare(config) - err := p.Provision(ui, comm) + err = p.Provision(ui, comm) if err != nil { t.Fatal("should not have error") } From 3d4c7d0df173c063c07aa8c4b5a298a9c2eddadd Mon Sep 17 00:00:00 2001 From: AlessioT Date: Mon, 30 Apr 2018 20:59:13 +0100 Subject: [PATCH 17/24] Feature Request: Log reason why AMI creation failed --- builder/amazon/ebs/step_create_ami.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index 254311fcd..1f0ad717c 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -52,9 +52,15 @@ func (s *stepCreateAMI) Run(_ context.Context, state multistep.StateBag) multist ui.Say("Waiting for AMI to become ready...") if _, err := awscommon.WaitForState(&stateChange); err != nil { - imagesResp, _ := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) - stateReason := imagesResp.Images[0].StateReason.Message - err := fmt.Errorf("Error waiting for AMI: %s. Root cause: %s", err, *stateReason) + err := fmt.Errorf("Error waiting for AMI: %s", err) + imagesResp, err := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) + if err != nil { + stateReason := imagesResp.Images[0].StateReason.Message + if stateReason != nil { + err = fmt.Errorf("%s. Root cause: %s", err.Error(), *stateReason) + } + } + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt From 4f1395e0f6c4dc7397f50b4efb6599aaff7597ce Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Tue, 1 May 2018 12:40:00 -0700 Subject: [PATCH 18/24] builder/qemu: properly prepare boot command. --- builder/qemu/builder.go | 1 + builder/qemu/step_type_boot_command.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index 7f54adae5..d664dade9 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -217,6 +217,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { } errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(&b.config.ctx)...) + errs = packer.MultiErrorAppend(errs, b.config.VNCConfig.Prepare(&b.config.ctx)...) if b.config.NetDevice == "" { b.config.NetDevice = "virtio-net" diff --git a/builder/qemu/step_type_boot_command.go b/builder/qemu/step_type_boot_command.go index da3eb48aa..a21256b6b 100644 --- a/builder/qemu/step_type_boot_command.go +++ b/builder/qemu/step_type_boot_command.go @@ -48,7 +48,7 @@ func (s *stepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) } // Wait the for the vm to boot. - if int64(config.BootConfig.BootWait) > 0 { + if int64(config.BootWait) > 0 { ui.Say(fmt.Sprintf("Waiting %s for boot...", config.BootWait.String())) select { case <-time.After(config.BootWait): From 2fc67f2210afafb4d7dc7345e68dd083db32e417 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Tue, 1 May 2018 13:09:55 -0700 Subject: [PATCH 19/24] Revert "Merge pull request #4494 from tb3088/EOL-handling" This reverts commit dfe4f56c75abe1fb25f5453a5e7828a4c2504260, reversing changes made to e90c87f88524c2f4a41f4b721e3b7b0eb29eafcc. Revert changes to makefile and format checker --- Makefile | 9 +++------ scripts/gofmtcheck.sh | 14 ++++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 45f107947..0ccd547b4 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ VET?=$(shell ls -d */ | grep -v vendor | grep -v website) GITSHA:=$(shell git rev-parse HEAD) # Get the current local branch name from git (if we can, this may be blank) GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null) -GOFMT_FILES?=find . -path ./vendor -prune -o -name "*.go" +GOFMT_FILES?=$$(find . -not -path "./vendor/*" -name "*.go") GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) GOPATH=$(shell go env GOPATH) @@ -58,13 +58,10 @@ dev: deps ## Build and install a development build @cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH) fmt: ## Format Go code - @$(GOFMT_FILES) | xargs gofmt -w -s + @gofmt -w -s $(GOFMT_FILES) fmt-check: ## Check go code formatting - @echo "==> Checking that code complies with gofmt requirements..." - @echo "You can use the command: \`make fmt\` to reformat code." - @$(GOFMT_FILES) | xargs $(CURDIR)/scripts/gofmtcheck.sh - @echo "Check complete." + $(CURDIR)/scripts/gofmtcheck.sh $(GOFMT_FILES) fmt-docs: @find ./website/source/docs -name "*.md" -exec pandoc --wrap auto --columns 79 --atx-headers -s -f "markdown_github+yaml_metadata_block" -t "markdown_github+yaml_metadata_block" {} -o {} \; diff --git a/scripts/gofmtcheck.sh b/scripts/gofmtcheck.sh index cc6deb81e..5b99bcdc4 100755 --- a/scripts/gofmtcheck.sh +++ b/scripts/gofmtcheck.sh @@ -1,8 +1,14 @@ #!/usr/bin/env bash -for f in $@; do - [ -n "`dos2unix 2>/dev/null < $f | gofmt -s -d`" ] && echo $f -done +# Check gofmt +echo "==> Checking that code complies with gofmt requirements..." +gofmt_files=$(gofmt -s -l ${@}) +if [[ -n ${gofmt_files} ]]; then + echo 'gofmt needs running on the following files:' + echo "${gofmt_files}" + echo "You can use the command: \`make fmt\` to reformat code." + exit 1 +fi +echo "Check passed." -# always return success or else 'make' will abort exit 0 From 78d68880c01395efb693fa7f6e0fe34f26a04096 Mon Sep 17 00:00:00 2001 From: Oskar Wycislak Date: Wed, 2 May 2018 20:18:03 +0200 Subject: [PATCH 20/24] Randomize osDisk name for Azure Managed Image builds. This fixes #6115 --- builder/azure/arm/TestVirtualMachineDeployment05.approved.txt | 2 +- .../arm/template_factory_test.TestPlanInfo01.approved.json | 2 +- .../arm/template_factory_test.TestPlanInfo02.approved.json | 2 +- ..._factory_test.TestVirtualMachineDeployment03.approved.json | 2 +- ..._factory_test.TestVirtualMachineDeployment04.approved.json | 2 +- ..._factory_test.TestVirtualMachineDeployment05.approved.json | 2 +- ..._factory_test.TestVirtualMachineDeployment06.approved.json | 2 +- ..._factory_test.TestVirtualMachineDeployment07.approved.json | 2 +- ..._factory_test.TestVirtualMachineDeployment08.approved.json | 2 +- ..._factory_test.TestVirtualMachineDeployment09.approved.json | 2 +- ..._factory_test.TestVirtualMachineDeployment10.approved.json | 2 +- ..._factory_test.TestVirtualMachineDeployment11.approved.json | 2 +- ..._factory_test.TestVirtualMachineDeployment12.approved.json | 2 +- builder/azure/common/template/TestBuildLinux02.approved.txt | 2 +- builder/azure/common/template/template_builder.go | 4 +--- .../template_builder_test.TestBuildLinux00.approved.json | 2 +- .../template_builder_test.TestBuildLinux01.approved.json | 2 +- .../template_builder_test.TestBuildLinux02.approved.json | 2 +- .../template_builder_test.TestBuildWindows00.approved.json | 2 +- .../template_builder_test.TestBuildWindows01.approved.json | 2 +- .../template_builder_test.TestBuildWindows02.approved.json | 2 +- 21 files changed, 21 insertions(+), 23 deletions(-) diff --git a/builder/azure/arm/TestVirtualMachineDeployment05.approved.txt b/builder/azure/arm/TestVirtualMachineDeployment05.approved.txt index 8a8a5d4d4..31532ddbe 100644 --- a/builder/azure/arm/TestVirtualMachineDeployment05.approved.txt +++ b/builder/azure/arm/TestVirtualMachineDeployment05.approved.txt @@ -90,7 +90,7 @@ "image": { "uri": "https://localhost/custom.vhd" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" diff --git a/builder/azure/arm/template_factory_test.TestPlanInfo01.approved.json b/builder/azure/arm/template_factory_test.TestPlanInfo01.approved.json index 1d2ef2207..392dc0ec9 100644 --- a/builder/azure/arm/template_factory_test.TestPlanInfo01.approved.json +++ b/builder/azure/arm/template_factory_test.TestPlanInfo01.approved.json @@ -167,7 +167,7 @@ "osDisk": { "caching": "ReadWrite", "createOption": "FromImage", - "name": "osdisk", + "name": "[parameters('osDiskName')]", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" } diff --git a/builder/azure/arm/template_factory_test.TestPlanInfo02.approved.json b/builder/azure/arm/template_factory_test.TestPlanInfo02.approved.json index bc3ef83ef..b29616711 100644 --- a/builder/azure/arm/template_factory_test.TestPlanInfo02.approved.json +++ b/builder/azure/arm/template_factory_test.TestPlanInfo02.approved.json @@ -171,7 +171,7 @@ "osDisk": { "caching": "ReadWrite", "createOption": "FromImage", - "name": "osdisk", + "name": "[parameters('osDiskName')]", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" } diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment03.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment03.approved.json index 2a9a429e5..edb21ca39 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment03.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment03.approved.json @@ -144,7 +144,7 @@ "osDisk": { "caching": "ReadWrite", "createOption": "FromImage", - "name": "osdisk", + "name": "[parameters('osDiskName')]", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" } diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment04.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment04.approved.json index 215acda04..ae52ff483 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment04.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment04.approved.json @@ -141,7 +141,7 @@ "image": { "uri": "https://localhost/custom.vhd" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment05.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment05.approved.json index c7a73e7ad..5c78f287a 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment05.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment05.approved.json @@ -102,7 +102,7 @@ "image": { "uri": "https://localhost/custom.vhd" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment06.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment06.approved.json index 258fd9261..04ce31e33 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment06.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment06.approved.json @@ -156,7 +156,7 @@ "image": { "uri": "https://localhost/custom.vhd" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment07.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment07.approved.json index 8d7101cfe..a3b278f1e 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment07.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment07.approved.json @@ -142,7 +142,7 @@ "image": { "uri": "https://localhost/custom.vhd" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment08.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment08.approved.json index ae0700880..8e61c0055 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment08.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment08.approved.json @@ -144,7 +144,7 @@ "managedDisk": { "storageAccountType": "Standard_LRS" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux" } } diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment09.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment09.approved.json index a7baa806f..e64f16913 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment09.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment09.approved.json @@ -147,7 +147,7 @@ "managedDisk": { "storageAccountType": "Standard_LRS" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux" } } diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment10.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment10.approved.json index 8c27336c5..dfde04a08 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment10.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment10.approved.json @@ -125,7 +125,7 @@ "managedDisk": { "storageAccountType": "Standard_LRS" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux" } } diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment11.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment11.approved.json index 4776d5344..bf94c8581 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment11.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment11.approved.json @@ -156,7 +156,7 @@ "osDisk": { "caching": "ReadWrite", "createOption": "FromImage", - "name": "osdisk", + "name": "[parameters('osDiskName')]", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" } diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment12.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment12.approved.json index 25449da24..6f6ef5749 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment12.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment12.approved.json @@ -159,7 +159,7 @@ "managedDisk": { "storageAccountType": "Standard_LRS" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux" } } diff --git a/builder/azure/common/template/TestBuildLinux02.approved.txt b/builder/azure/common/template/TestBuildLinux02.approved.txt index c2533dd2d..97aad4de1 100644 --- a/builder/azure/common/template/TestBuildLinux02.approved.txt +++ b/builder/azure/common/template/TestBuildLinux02.approved.txt @@ -103,7 +103,7 @@ "storageProfile": { "osDisk": { "osType": "Linux", - "name": "osdisk", + "name": "[parameters('osDiskName')]", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" }, diff --git a/builder/azure/common/template/template_builder.go b/builder/azure/common/template/template_builder.go index 3067c906e..3180a81a4 100644 --- a/builder/azure/common/template/template_builder.go +++ b/builder/azure/common/template/template_builder.go @@ -111,7 +111,6 @@ func (s *TemplateBuilder) SetManagedDiskUrl(managedImageId string, storageAccoun profile.ImageReference = &compute.ImageReference{ ID: &managedImageId, } - profile.OsDisk.Name = to.StringPtr("osdisk") profile.OsDisk.OsType = s.osType profile.OsDisk.CreateOption = compute.FromImage profile.OsDisk.Vhd = nil @@ -136,7 +135,6 @@ func (s *TemplateBuilder) SetManagedMarketplaceImage(location, publisher, offer, Version: &version, //ID: &imageID, } - profile.OsDisk.Name = to.StringPtr("osdisk") profile.OsDisk.OsType = s.osType profile.OsDisk.CreateOption = compute.FromImage profile.OsDisk.Vhd = nil @@ -583,7 +581,7 @@ const BasicTemplate = `{ }, "storageProfile": { "osDisk": { - "name": "osdisk", + "name": "[parameters('osDiskName')]", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" }, diff --git a/builder/azure/common/template/template_builder_test.TestBuildLinux00.approved.json b/builder/azure/common/template/template_builder_test.TestBuildLinux00.approved.json index 5a4b69427..85986d344 100644 --- a/builder/azure/common/template/template_builder_test.TestBuildLinux00.approved.json +++ b/builder/azure/common/template/template_builder_test.TestBuildLinux00.approved.json @@ -144,7 +144,7 @@ "osDisk": { "caching": "ReadWrite", "createOption": "FromImage", - "name": "osdisk", + "name": "[parameters('osDiskName')]", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" } diff --git a/builder/azure/common/template/template_builder_test.TestBuildLinux01.approved.json b/builder/azure/common/template/template_builder_test.TestBuildLinux01.approved.json index d23117b48..d98871cb8 100644 --- a/builder/azure/common/template/template_builder_test.TestBuildLinux01.approved.json +++ b/builder/azure/common/template/template_builder_test.TestBuildLinux01.approved.json @@ -141,7 +141,7 @@ "image": { "uri": "http://azure/custom.vhd" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" diff --git a/builder/azure/common/template/template_builder_test.TestBuildLinux02.approved.json b/builder/azure/common/template/template_builder_test.TestBuildLinux02.approved.json index 68d1bc427..d7dd46a45 100644 --- a/builder/azure/common/template/template_builder_test.TestBuildLinux02.approved.json +++ b/builder/azure/common/template/template_builder_test.TestBuildLinux02.approved.json @@ -103,7 +103,7 @@ "image": { "uri": "http://azure/custom.vhd" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Linux", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" diff --git a/builder/azure/common/template/template_builder_test.TestBuildWindows00.approved.json b/builder/azure/common/template/template_builder_test.TestBuildWindows00.approved.json index cbf46d3e8..e1d511f40 100644 --- a/builder/azure/common/template/template_builder_test.TestBuildWindows00.approved.json +++ b/builder/azure/common/template/template_builder_test.TestBuildWindows00.approved.json @@ -158,7 +158,7 @@ "osDisk": { "caching": "ReadWrite", "createOption": "FromImage", - "name": "osdisk", + "name": "[parameters('osDiskName')]", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" } diff --git a/builder/azure/common/template/template_builder_test.TestBuildWindows01.approved.json b/builder/azure/common/template/template_builder_test.TestBuildWindows01.approved.json index c660dcd75..881500148 100644 --- a/builder/azure/common/template/template_builder_test.TestBuildWindows01.approved.json +++ b/builder/azure/common/template/template_builder_test.TestBuildWindows01.approved.json @@ -183,7 +183,7 @@ "managedDisk": { "storageAccountType": "Premium_LRS" }, - "name": "osdisk", + "name": "[parameters('osDiskName')]", "osType": "Windows" } } diff --git a/builder/azure/common/template/template_builder_test.TestBuildWindows02.approved.json b/builder/azure/common/template/template_builder_test.TestBuildWindows02.approved.json index 0507771ee..7c44163c3 100644 --- a/builder/azure/common/template/template_builder_test.TestBuildWindows02.approved.json +++ b/builder/azure/common/template/template_builder_test.TestBuildWindows02.approved.json @@ -174,7 +174,7 @@ "osDisk": { "caching": "ReadWrite", "createOption": "FromImage", - "name": "osdisk", + "name": "[parameters('osDiskName')]", "vhd": { "uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]" } From 585b93cfd6dc13c25855d487c188e40acd37c3d8 Mon Sep 17 00:00:00 2001 From: DanHam Date: Thu, 3 May 2018 00:17:51 +0100 Subject: [PATCH 21/24] Follow variable privateKey <-> statebag private_key convention --- builder/scaleway/ssh.go | 2 +- builder/scaleway/step_create_ssh_key.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builder/scaleway/ssh.go b/builder/scaleway/ssh.go index a2c9b8f16..946c2046f 100644 --- a/builder/scaleway/ssh.go +++ b/builder/scaleway/ssh.go @@ -46,7 +46,7 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { } if config.Comm.SSHPrivateKey != "" { - if priv, ok := state.GetOk("privateKey"); ok { + if priv, ok := state.GetOk("private_key"); ok { privateKey = priv.(string) } signer, err := ssh.ParsePrivateKey([]byte(privateKey)) diff --git a/builder/scaleway/step_create_ssh_key.go b/builder/scaleway/step_create_ssh_key.go index c5405ccd6..4272d9ff4 100644 --- a/builder/scaleway/step_create_ssh_key.go +++ b/builder/scaleway/step_create_ssh_key.go @@ -36,7 +36,7 @@ func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult return multistep.ActionHalt } - state.Put("privateKey", string(privateKeyBytes)) + state.Put("private_key", string(privateKeyBytes)) state.Put("ssh_pubkey", "") return multistep.ActionContinue @@ -61,7 +61,7 @@ func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult } // Set the private key in the statebag for later - state.Put("privateKey", string(pem.EncodeToMemory(&priv_blk))) + state.Put("private_key", string(pem.EncodeToMemory(&priv_blk))) pub, _ := ssh.NewPublicKey(&priv.PublicKey) pub_sshformat := string(ssh.MarshalAuthorizedKey(pub)) From c47e5d19f036fdb6f5a79de29961fbdb043972b3 Mon Sep 17 00:00:00 2001 From: DanHam Date: Thu, 3 May 2018 11:33:28 +0100 Subject: [PATCH 22/24] Fix use of auto generated ssh key for scaleway builder --- builder/scaleway/ssh.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/builder/scaleway/ssh.go b/builder/scaleway/ssh.go index 946c2046f..e4677849f 100644 --- a/builder/scaleway/ssh.go +++ b/builder/scaleway/ssh.go @@ -18,7 +18,6 @@ func commHost(state multistep.StateBag) (string, error) { func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { config := state.Get("config").(Config) - var privateKey string var auth []ssh.AuthMethod @@ -45,11 +44,9 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { ) } - if config.Comm.SSHPrivateKey != "" { - if priv, ok := state.GetOk("private_key"); ok { - privateKey = priv.(string) - } - signer, err := ssh.ParsePrivateKey([]byte(privateKey)) + // Use key based auth if there is a private key in the state bag + if privateKey, ok := state.GetOk("private_key"); ok { + signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string))) if err != nil { return nil, fmt.Errorf("Error setting up SSH config: %s", err) } From 6ff69461f548c75d1d8e11715fbae2fe5fab7f33 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Thu, 3 May 2018 12:26:55 -0700 Subject: [PATCH 23/24] remove bad newline --- vendor/vendor.json | 1 - 1 file changed, 1 deletion(-) diff --git a/vendor/vendor.json b/vendor/vendor.json index bb9f4ec61..8f48e1ee0 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1013,7 +1013,6 @@ { "checksumSHA1": "UIqCj7qI0hhIMpAhS9YYqs2jD48=", "path": "github.com/mitchellh/cli", - "revision": "65fcae5817c8600da98ada9d7edf26dd1a84837b", "revisionTime": "2017-09-08T18:10:43Z" }, From 0521efa2002a094e0284df517f0831e7af88c948 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Thu, 3 May 2018 12:27:09 -0700 Subject: [PATCH 24/24] correctly log reason waiting for ami failed. --- builder/amazon/ebs/step_create_ami.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index 1f0ad717c..4782f533b 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -3,6 +3,7 @@ package ebs import ( "context" "fmt" + "log" "github.com/aws/aws-sdk-go/service/ec2" awscommon "github.com/hashicorp/packer/builder/amazon/common" @@ -52,13 +53,14 @@ func (s *stepCreateAMI) Run(_ context.Context, state multistep.StateBag) multist ui.Say("Waiting for AMI to become ready...") if _, err := awscommon.WaitForState(&stateChange); err != nil { - err := fmt.Errorf("Error waiting for AMI: %s", err) + log.Printf("Error waiting for AMI: %s", err) imagesResp, err := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}}) if err != nil { - stateReason := imagesResp.Images[0].StateReason.Message - if stateReason != nil { - err = fmt.Errorf("%s. Root cause: %s", err.Error(), *stateReason) - } + log.Printf("Unable to determine reason waiting for AMI failed: %s", err) + err = fmt.Errorf("Unknown error waiting for AMI.") + } else { + stateReason := imagesResp.Images[0].StateReason + err = fmt.Errorf("Error waiting for AMI. Reason: %s", stateReason) } state.Put("error", err)