provisioner/salt-masterless: verify local_state_tree exists

/cc @rgarcia
This commit is contained in:
Mitchell Hashimoto 2013-07-31 23:11:08 -07:00
parent 116692212c
commit 4c1db34ac9
2 changed files with 22 additions and 1 deletions

View File

@ -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 {

View File

@ -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)
}
}