From 3a2c04e4e5c4228445c7ebbf00238dff43935e95 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 11 Dec 2013 11:21:51 -0800 Subject: [PATCH] provisioner/puppet-masterless: validate manifest_dir is a dir --- provisioner/puppet-masterless/provisioner.go | 11 +++++++++++ provisioner/puppet-masterless/provisioner_test.go | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/provisioner/puppet-masterless/provisioner.go b/provisioner/puppet-masterless/provisioner.go index 1fb2d4bc6..e3dd4dd77 100644 --- a/provisioner/puppet-masterless/provisioner.go +++ b/provisioner/puppet-masterless/provisioner.go @@ -163,6 +163,17 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { } } + if p.config.ManifestDir != "" { + info, err := os.Stat(p.config.ManifestDir) + if err != nil { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("manifest_dir is invalid: %s", err)) + } else if !info.IsDir() { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("manifest_dir must point to a directory")) + } + } + if p.config.ManifestFile == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("A manifest_file must be specified.")) diff --git a/provisioner/puppet-masterless/provisioner_test.go b/provisioner/puppet-masterless/provisioner_test.go index b71534aea..0d5576b6b 100644 --- a/provisioner/puppet-masterless/provisioner_test.go +++ b/provisioner/puppet-masterless/provisioner_test.go @@ -87,13 +87,13 @@ func TestProvisionerPrepare_manifestDir(t *testing.T) { } // Test with a good one - tf, err := ioutil.TempFile("", "packer") + td, err := ioutil.TempDir("", "packer") if err != nil { - t.Fatalf("error tempfile: %s", err) + t.Fatalf("error: %s", err) } - defer os.Remove(tf.Name()) + defer os.RemoveAll(td) - config["manifest_dir"] = tf.Name() + config["manifest_dir"] = td p = new(Provisioner) err = p.Prepare(config) if err != nil {