From 3cd7379d1f626908552d9d58b08f3f8112f8a048 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 2 Nov 2013 22:56:54 -0500 Subject: [PATCH] builder/amazon/*: warnings --- builder/amazon/chroot/builder.go | 10 +-- builder/amazon/chroot/builder_test.go | 40 ++++++++--- builder/amazon/ebs/builder.go | 10 +-- builder/amazon/ebs/builder_test.go | 25 +++++-- builder/amazon/instance/builder.go | 10 +-- builder/amazon/instance/builder_test.go | 90 ++++++++++++++++++++----- 6 files changed, 139 insertions(+), 46 deletions(-) diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index b0a9df638..e898f4173 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -45,15 +45,15 @@ type Builder struct { runner multistep.Runner } -func (b *Builder) Prepare(raws ...interface{}) error { +func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { md, err := common.DecodeConfig(&b.config, raws...) if err != nil { - return err + return nil, err } b.config.tpl, err = packer.NewConfigTemplate() if err != nil { - return err + return nil, err } b.config.tpl.UserVars = b.config.PackerUserVars b.config.tpl.Funcs(awscommon.TemplateFuncs) @@ -140,11 +140,11 @@ func (b *Builder) Prepare(raws ...interface{}) error { } if errs != nil && len(errs.Errors) > 0 { - return errs + return nil, errs } log.Println(common.ScrubConfig(b.config, b.config.AccessKey, b.config.SecretKey)) - return nil + return nil, nil } func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { diff --git a/builder/amazon/chroot/builder_test.go b/builder/amazon/chroot/builder_test.go index 6bdf7dc28..291651477 100644 --- a/builder/amazon/chroot/builder_test.go +++ b/builder/amazon/chroot/builder_test.go @@ -26,7 +26,10 @@ func TestBuilderPrepare_AMIName(t *testing.T) { // Test good config["ami_name"] = "foo" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Fatalf("should not have error: %s", err) } @@ -34,7 +37,10 @@ func TestBuilderPrepare_AMIName(t *testing.T) { // Test bad config["ami_name"] = "foo {{" b = Builder{} - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } @@ -42,7 +48,10 @@ func TestBuilderPrepare_AMIName(t *testing.T) { // Test bad delete(config, "ami_name") b = Builder{} - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } @@ -53,7 +62,10 @@ func TestBuilderPrepare_ChrootMounts(t *testing.T) { config := testConfig() config["chroot_mounts"] = nil - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Errorf("err: %s", err) } @@ -61,7 +73,10 @@ func TestBuilderPrepare_ChrootMounts(t *testing.T) { config["chroot_mounts"] = [][]string{ []string{"bad"}, } - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } @@ -71,13 +86,19 @@ func TestBuilderPrepare_SourceAmi(t *testing.T) { config := testConfig() config["source_ami"] = "" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } config["source_ami"] = "foo" - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Errorf("err: %s", err) } @@ -88,7 +109,10 @@ func TestBuilderPrepare_CommandWrapper(t *testing.T) { config := testConfig() config["command_wrapper"] = "echo hi; {{.Command}}" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Errorf("err: %s", err) } diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index f38c6826c..a590b96e7 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -33,15 +33,15 @@ type Builder struct { runner multistep.Runner } -func (b *Builder) Prepare(raws ...interface{}) error { +func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { md, err := common.DecodeConfig(&b.config, raws...) if err != nil { - return err + return nil, err } b.config.tpl, err = packer.NewConfigTemplate() if err != nil { - return err + return nil, err } b.config.tpl.UserVars = b.config.PackerUserVars b.config.tpl.Funcs(awscommon.TemplateFuncs) @@ -53,11 +53,11 @@ func (b *Builder) Prepare(raws ...interface{}) error { errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...) if errs != nil && len(errs.Errors) > 0 { - return errs + return nil, errs } log.Println(common.ScrubConfig(b.config, b.config.AccessKey, b.config.SecretKey)) - return nil + return nil, nil } func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { diff --git a/builder/amazon/ebs/builder_test.go b/builder/amazon/ebs/builder_test.go index 3ad6d17b6..6f777afa9 100644 --- a/builder/amazon/ebs/builder_test.go +++ b/builder/amazon/ebs/builder_test.go @@ -31,7 +31,10 @@ func TestBuilder_Prepare_BadType(t *testing.T) { "access_key": []string{}, } - err := b.Prepare(c) + warnings, err := b.Prepare(c) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatalf("prepare should fail") } @@ -43,7 +46,10 @@ func TestBuilderPrepare_AMIName(t *testing.T) { // Test good config["ami_name"] = "foo" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Fatalf("should not have error: %s", err) } @@ -51,7 +57,10 @@ func TestBuilderPrepare_AMIName(t *testing.T) { // Test bad config["ami_name"] = "foo {{" b = Builder{} - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } @@ -59,7 +68,10 @@ func TestBuilderPrepare_AMIName(t *testing.T) { // Test bad delete(config, "ami_name") b = Builder{} - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } @@ -71,7 +83,10 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) { // Add a random key config["i_should_not_be_valid"] = true - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index 8b1a5f6af..e44ac31a9 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -45,15 +45,15 @@ type Builder struct { runner multistep.Runner } -func (b *Builder) Prepare(raws ...interface{}) error { +func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { md, err := common.DecodeConfig(&b.config, raws...) if err != nil { - return err + return nil, err } b.config.tpl, err = packer.NewConfigTemplate() if err != nil { - return err + return nil, err } b.config.tpl.UserVars = b.config.PackerUserVars b.config.tpl.Funcs(awscommon.TemplateFuncs) @@ -156,11 +156,11 @@ func (b *Builder) Prepare(raws ...interface{}) error { } if errs != nil && len(errs.Errors) > 0 { - return errs + return nil, errs } log.Println(common.ScrubConfig(b.config, b.config.AccessKey, b.config.SecretKey)) - return nil + return nil, nil } func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { diff --git a/builder/amazon/instance/builder_test.go b/builder/amazon/instance/builder_test.go index c61a6f73d..e15c45131 100644 --- a/builder/amazon/instance/builder_test.go +++ b/builder/amazon/instance/builder_test.go @@ -40,19 +40,28 @@ func TestBuilderPrepare_AccountId(t *testing.T) { config := testConfig() config["account_id"] = "" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } config["account_id"] = "foo" - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Errorf("err: %s", err) } config["account_id"] = "0123-0456-7890" - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Fatalf("err: %s", err) } @@ -68,7 +77,10 @@ func TestBuilderPrepare_AMIName(t *testing.T) { // Test good config["ami_name"] = "foo" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Fatalf("should not have error: %s", err) } @@ -76,7 +88,10 @@ func TestBuilderPrepare_AMIName(t *testing.T) { // Test bad config["ami_name"] = "foo {{" b = Builder{} - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } @@ -84,7 +99,10 @@ func TestBuilderPrepare_AMIName(t *testing.T) { // Test bad delete(config, "ami_name") b = Builder{} - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } @@ -95,7 +113,10 @@ func TestBuilderPrepare_BundleDestination(t *testing.T) { config := testConfig() config["bundle_destination"] = "" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Fatalf("err: %s", err) } @@ -110,7 +131,10 @@ func TestBuilderPrepare_BundlePrefix(t *testing.T) { config := testConfig() config["bundle_prefix"] = "" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Fatalf("err: %s", err) } @@ -126,7 +150,10 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) { // Add a random key config["i_should_not_be_valid"] = true - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } @@ -137,13 +164,19 @@ func TestBuilderPrepare_S3Bucket(t *testing.T) { config := testConfig() config["s3_bucket"] = "" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } config["s3_bucket"] = "foo" - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Errorf("err: %s", err) } @@ -154,13 +187,19 @@ func TestBuilderPrepare_X509CertPath(t *testing.T) { config := testConfig() config["x509_cert_path"] = "" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } config["x509_cert_path"] = "i/am/a/file/that/doesnt/exist" - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Error("should have error") } @@ -172,7 +211,10 @@ func TestBuilderPrepare_X509CertPath(t *testing.T) { defer os.Remove(tf.Name()) config["x509_cert_path"] = tf.Name() - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Fatalf("should not have error: %s", err) } @@ -183,13 +225,19 @@ func TestBuilderPrepare_X509KeyPath(t *testing.T) { config := testConfig() config["x509_key_path"] = "" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Fatal("should have error") } config["x509_key_path"] = "i/am/a/file/that/doesnt/exist" - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err == nil { t.Error("should have error") } @@ -201,7 +249,10 @@ func TestBuilderPrepare_X509KeyPath(t *testing.T) { defer os.Remove(tf.Name()) config["x509_key_path"] = tf.Name() - err = b.Prepare(config) + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Fatalf("should not have error: %s", err) } @@ -212,7 +263,10 @@ func TestBuilderPrepare_X509UploadPath(t *testing.T) { config := testConfig() config["x509_upload_path"] = "" - err := b.Prepare(config) + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } if err != nil { t.Fatalf("should not have error: %s", err) }