mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 09:55:44 +03:00
Client init rebase
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user