Client init rebase

This commit is contained in:
Alex Dadgar
2015-09-24 14:29:53 -07:00
parent 66fe1294da
commit dfd0efbacd
3 changed files with 20 additions and 10 deletions

View File

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

View File

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

View File

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