additional e2e utils for multi-task allocs
This commit is contained in:
parent
3b580d9474
commit
aa55df0413
|
@ -186,6 +186,15 @@ func AllocLogs(allocID string, logStream LogStream) (string, error) {
|
|||
return Command(cmd[0], cmd[1:]...)
|
||||
}
|
||||
|
||||
func AllocTaskLogs(allocID, task string, logStream LogStream) (string, error) {
|
||||
cmd := []string{"nomad", "alloc", "logs"}
|
||||
if logStream == LogsStdErr {
|
||||
cmd = append(cmd, "-stderr")
|
||||
}
|
||||
cmd = append(cmd, allocID, task)
|
||||
return Command(cmd[0], cmd[1:]...)
|
||||
}
|
||||
|
||||
// AllocExec is a convenience wrapper that runs 'nomad alloc exec' with the
|
||||
// passed execCmd via '/bin/sh -c', retrying if the task isn't ready
|
||||
func AllocExec(allocID, taskID, execCmd, ns string, wc *WaitConfig) (string, error) {
|
||||
|
|
|
@ -140,6 +140,24 @@ func WaitForAllocRunning(t *testing.T, nomadClient *api.Client, allocID string)
|
|||
})
|
||||
}
|
||||
|
||||
func WaitForAllocTaskRunning(t *testing.T, nomadClient *api.Client, allocID, task string) {
|
||||
testutil.WaitForResultRetries(retries, func() (bool, error) {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
alloc, _, err := nomadClient.Allocations().Info(allocID, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
state := "n/a"
|
||||
if task := alloc.TaskStates[task]; task != nil {
|
||||
state = task.State
|
||||
}
|
||||
return state == structs.AllocClientStatusRunning, fmt.Errorf("expected status running, but was: %s", state)
|
||||
}, func(err error) {
|
||||
t.Fatalf("failed to wait on alloc: %v", err)
|
||||
})
|
||||
}
|
||||
|
||||
func WaitForAllocsRunning(t *testing.T, nomadClient *api.Client, allocIDs []string) {
|
||||
for _, allocID := range allocIDs {
|
||||
WaitForAllocRunning(t, nomadClient, allocID)
|
||||
|
|
Loading…
Reference in New Issue