diff --git a/client/alloc_runner_test.go b/client/alloc_runner_test.go index cfa0e530a..08c5a368c 100644 --- a/client/alloc_runner_test.go +++ b/client/alloc_runner_test.go @@ -1,6 +1,7 @@ package client import ( + "os" "testing" "time" @@ -26,7 +27,8 @@ func (m *MockAllocStateUpdater) Update(alloc *structs.Allocation) error { func testAllocRunner() (*MockAllocStateUpdater, *AllocRunner) { logger := testLogger() conf := DefaultConfig() - conf.StateDir = "/tmp" + conf.StateDir = os.TempDir() + conf.AllocDir = os.TempDir() upd := &MockAllocStateUpdater{} alloc := mock.Alloc() ar := NewAllocRunner(logger, conf, upd.Update, alloc) diff --git a/client/client.go b/client/client.go index 4f8ff2e4f..acf60d074 100644 --- a/client/client.go +++ b/client/client.go @@ -142,20 +142,27 @@ func NewClient(cfg *config.Config) (*Client, error) { // init is used to initialize the client and perform any setup // needed before we begin starting its various components. func (c *Client) init() error { - // Ensure the alloc dir exists if we have one - // TODO(alex): Make a tmp directory if it doesn't? - if c.config.AllocDir != "" { - if err := os.MkdirAll(c.config.AllocDir, 0700); err != nil { - return fmt.Errorf("failed creating alloc dir: %s", err) - } - } - // Ensure the state dir exists if we have one if c.config.StateDir != "" { if err := os.MkdirAll(c.config.StateDir, 0700); err != nil { return fmt.Errorf("failed creating state dir: %s", err) } } + + // Ensure the alloc dir exists if we have one + if c.config.AllocDir != "" { + if err := os.MkdirAll(c.config.AllocDir, 0700); err != nil { + return fmt.Errorf("failed creating alloc dir: %s", err) + } + } + + // Othewise make a temp directory to use. + p, err := ioutil.TempDir("", "NomadClient") + if err != nil { + return fmt.Errorf("failed creating temporary directory for the AllocDir: %v", err) + } + c.config.AllocDir = p + return nil } diff --git a/client/task_runner_test.go b/client/task_runner_test.go index 3a16b3274..e56273941 100644 --- a/client/task_runner_test.go +++ b/client/task_runner_test.go @@ -36,7 +36,8 @@ func (m *MockTaskStateUpdater) Update(name, status, desc string) { func testTaskRunner() (*MockTaskStateUpdater, *TaskRunner) { logger := testLogger() conf := DefaultConfig() - conf.StateDir = "/tmp" + conf.StateDir = os.TempDir() + conf.AllocDir = os.TempDir() upd := &MockTaskStateUpdater{} ctx := driver.NewExecContext() alloc := mock.Alloc()