Client Restore test

This commit is contained in:
Alex Dadgar 2015-11-10 16:03:18 -08:00
parent 2c7da463b8
commit 933498e388
3 changed files with 15 additions and 13 deletions

View File

@ -148,8 +148,15 @@ func (c *Client) init() error {
return fmt.Errorf("failed creating state dir: %s", err)
}
c.logger.Printf("[INFO] client: using state directory %v", c.config.StateDir)
} else {
// Othewise make a temp directory to use.
p, err := ioutil.TempDir("", "NomadClient")
if err != nil {
return fmt.Errorf("failed creating temporary directory for the StateDir: %v", err)
}
c.config.StateDir = p
}
c.logger.Printf("[INFO] client: using state directory %v", c.config.StateDir)
// Ensure the alloc dir exists if we have one
if c.config.AllocDir != "" {

View File

@ -69,10 +69,10 @@ func testServer(t *testing.T, cb func(*nomad.Config)) (*nomad.Server, string) {
func testClient(t *testing.T, cb func(c *config.Config)) *Client {
conf := DefaultConfig()
conf.DevMode = true
if cb != nil {
cb(conf)
}
conf.DevMode = true
client, err := NewClient(conf)
if err != nil {
@ -319,11 +319,6 @@ func TestClient_WatchAllocs(t *testing.T) {
})
}
/*
TODO: This test is disabled til a follow-up api changes the restore state interface.
The driver/executor interface will be changed from Open to Cleanup, in which
clean-up tears down previous allocs.
func TestClient_SaveRestoreState(t *testing.T) {
ctestutil.ExecCompatible(t)
s1, _ := testServer(t, nil)
@ -331,6 +326,7 @@ func TestClient_SaveRestoreState(t *testing.T) {
testutil.WaitForLeader(t, s1.RPC)
c1 := testClient(t, func(c *config.Config) {
c.DevMode = false
c.RPCHandler = s1
})
defer c1.Shutdown()
@ -352,9 +348,9 @@ func TestClient_SaveRestoreState(t *testing.T) {
// Allocations should get registered
testutil.WaitForResult(func() (bool, error) {
c1.allocLock.RLock()
num := len(c1.allocs)
ar := c1.allocs[alloc1.ID]
c1.allocLock.RUnlock()
return num == 1, nil
return ar != nil && ar.Alloc().ClientStatus == structs.AllocClientStatusRunning, nil
}, func(err error) {
t.Fatalf("err: %v", err)
})
@ -374,13 +370,12 @@ func TestClient_SaveRestoreState(t *testing.T) {
// Ensure the allocation is running
c2.allocLock.RLock()
ar := c1.allocs[alloc1.ID]
ar := c2.allocs[alloc1.ID]
c2.allocLock.RUnlock()
if ar.Alloc().ClientStatus != structs.AllocClientStatusRunning {
t.Fatalf("bad: %#v", ar.Alloc())
}
}
*/
func TestClient_Init(t *testing.T) {
dir, err := ioutil.TempDir("", "nomad")

View File

@ -264,7 +264,7 @@ func (e *LinuxExecutor) ConfigureTaskDir(taskName string, alloc *allocdir.AllocD
// Mount dev
dev := filepath.Join(taskDir, "dev")
if err := os.Mkdir(dev, 0777); err != nil {
if err := os.MkdirAll(dev, 0777); err != nil {
return fmt.Errorf("Mkdir(%v) failed: %v", dev, err)
}
@ -274,7 +274,7 @@ func (e *LinuxExecutor) ConfigureTaskDir(taskName string, alloc *allocdir.AllocD
// Mount proc
proc := filepath.Join(taskDir, "proc")
if err := os.Mkdir(proc, 0777); err != nil {
if err := os.MkdirAll(proc, 0777); err != nil {
return fmt.Errorf("Mkdir(%v) failed: %v", proc, err)
}