diff --git a/e2e/e2eutil/allocs.go b/e2e/e2eutil/allocs.go index 625732f44..5627d2a1a 100644 --- a/e2e/e2eutil/allocs.go +++ b/e2e/e2eutil/allocs.go @@ -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) { diff --git a/e2e/e2eutil/utils.go b/e2e/e2eutil/utils.go index 6cf10d574..1d59a95a1 100644 --- a/e2e/e2eutil/utils.go +++ b/e2e/e2eutil/utils.go @@ -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)