2018-09-27 00:29:54 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2018-10-16 03:07:16 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2018-09-27 00:29:54 +00:00
|
|
|
"github.com/hashicorp/nomad/helper"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2018-10-16 03:07:16 +00:00
|
|
|
"github.com/mitchellh/go-testing-interface"
|
2018-09-27 00:29:54 +00:00
|
|
|
)
|
|
|
|
|
2018-10-16 03:07:16 +00:00
|
|
|
// TestClientConfig returns a default client configuration for test clients and
|
|
|
|
// a cleanup func to remove the state and alloc dirs when finished.
|
|
|
|
func TestClientConfig(t testing.T) (*Config, func()) {
|
2018-09-27 00:29:54 +00:00
|
|
|
conf := DefaultConfig()
|
2018-10-16 03:07:16 +00:00
|
|
|
|
|
|
|
// Create a tempdir to hold state and alloc subdirs
|
|
|
|
parent, err := ioutil.TempDir("", "nomadtest")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating client dir: %v", err)
|
|
|
|
}
|
|
|
|
cleanup := func() {
|
|
|
|
os.RemoveAll(parent)
|
|
|
|
}
|
|
|
|
|
|
|
|
allocDir := filepath.Join(parent, "allocs")
|
|
|
|
if err := os.Mkdir(allocDir, 0777); err != nil {
|
|
|
|
cleanup()
|
|
|
|
t.Fatalf("error creating alloc dir: %v", err)
|
|
|
|
}
|
|
|
|
conf.AllocDir = allocDir
|
|
|
|
|
|
|
|
stateDir := filepath.Join(parent, "client")
|
|
|
|
if err := os.Mkdir(stateDir, 0777); err != nil {
|
|
|
|
cleanup()
|
|
|
|
t.Fatalf("error creating alloc dir: %v", err)
|
|
|
|
}
|
|
|
|
conf.StateDir = stateDir
|
|
|
|
|
2018-09-27 00:29:54 +00:00
|
|
|
conf.VaultConfig.Enabled = helper.BoolToPtr(false)
|
|
|
|
conf.DevMode = true
|
|
|
|
conf.Node = &structs.Node{
|
|
|
|
Reserved: &structs.Resources{
|
|
|
|
DiskMB: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loosen GC threshold
|
|
|
|
conf.GCDiskUsageThreshold = 98.0
|
|
|
|
conf.GCInodeUsageThreshold = 98.0
|
2018-10-16 03:07:16 +00:00
|
|
|
return conf, cleanup
|
2018-09-27 00:29:54 +00:00
|
|
|
}
|