From 4c1db34ac9b188922d4bde21afa1e91ebcc433bf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 31 Jul 2013 23:11:08 -0700 Subject: [PATCH] provisioner/salt-masterless: verify local_state_tree exists /cc @rgarcia --- provisioner/salt-masterless/provisioner.go | 3 +++ .../salt-masterless/provisioner_test.go | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/provisioner/salt-masterless/provisioner.go b/provisioner/salt-masterless/provisioner.go index c3c8e1074..620099e67 100644 --- a/provisioner/salt-masterless/provisioner.go +++ b/provisioner/salt-masterless/provisioner.go @@ -48,6 +48,9 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { if p.config.LocalStateTree == "" { errs = packer.MultiErrorAppend(errs, errors.New("Please specify a local_state_tree")) + } else if _, err := os.Stat(p.config.LocalStateTree); err != nil { + errs = packer.MultiErrorAppend(errs, + errors.New("local_state_tree must exist and be accessible")) } if errs != nil && len(errs.Errors) > 0 { diff --git a/provisioner/salt-masterless/provisioner_test.go b/provisioner/salt-masterless/provisioner_test.go index 20a92bbbf..59c2fedeb 100644 --- a/provisioner/salt-masterless/provisioner_test.go +++ b/provisioner/salt-masterless/provisioner_test.go @@ -2,12 +2,13 @@ package saltmasterless import ( "github.com/mitchellh/packer/packer" + "os" "testing" ) func testConfig() map[string]interface{} { return map[string]interface{}{ - "local_state_tree": "/Users/me/salt", + "local_state_tree": os.TempDir(), } } @@ -44,3 +45,20 @@ func TestProvisionerPrepare_InvalidKey(t *testing.T) { t.Fatal("should have error") } } + +func TestProvisionerPrepare_LocalStateTree(t *testing.T) { + var p Provisioner + config := testConfig() + + config["local_state_tree"] = "/i/dont/exist/i/think" + err := p.Prepare(config) + if err == nil { + t.Fatal("should have error") + } + + config["local_state_tree"] = os.TempDir() + err = p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } +}