diff --git a/cmd/minikube/cmd/status.go b/cmd/minikube/cmd/status.go index df7184c0c1cb..b428bbc3f56e 100644 --- a/cmd/minikube/cmd/status.go +++ b/cmd/minikube/cmd/status.go @@ -90,6 +90,11 @@ const ( ) var ( + exitCodeToHTTPCode = map[int]int{ + // exit code 26 corresponds to insufficient storage + 26: 507, + } + codeNames = map[int]string{ 100: "Starting", 101: "Pausing", @@ -442,14 +447,18 @@ func readEventLog(name string) ([]cloudevents.Event, time.Time, error) { // clusterState converts Status structs into a ClusterState struct func clusterState(sts []*Status) ClusterState { - sc := statusCode(sts[0].Host) + statusName := sts[0].APIServer + if sts[0].Host == codeNames[InsufficientStorage] { + statusName = sts[0].Host + } + sc := statusCode(statusName) cs := ClusterState{ BinaryVersion: version.GetVersion(), BaseState: BaseState{ Name: ClusterFlagValue(), StatusCode: sc, - StatusName: sts[0].Host, + StatusName: statusName, StatusDetail: codeDetails[sc], }, @@ -533,6 +542,9 @@ func clusterState(sts []*Status) ClusterState { glog.Errorf("unable to convert exit code to int: %v", err) continue } + if val, ok := exitCodeToHTTPCode[exitCode]; ok { + exitCode = val + } transientCode = exitCode for _, n := range cs.Nodes { n.StatusCode = transientCode diff --git a/test/integration/status_test.go b/test/integration/status_test.go index 15b8a702f899..9980d0a4c6b1 100644 --- a/test/integration/status_test.go +++ b/test/integration/status_test.go @@ -52,7 +52,7 @@ func TestInsufficientStorage(t *testing.T) { } // make sure 'minikube status' has correct output - stdout := runStatusCmd(ctx, t, profile) + stdout := runStatusCmd(ctx, t, profile, true) verifyClusterState(t, stdout) // try deleting events.json and make sure this still works @@ -60,16 +60,18 @@ func TestInsufficientStorage(t *testing.T) { if err := os.Remove(eventsFile); err != nil { t.Fatalf("removing %s", eventsFile) } - stdout = runStatusCmd(ctx, t, profile) + stdout = runStatusCmd(ctx, t, profile, true) verifyClusterState(t, stdout) } // runStatusCmd runs the status command and returns stdout -func runStatusCmd(ctx context.Context, t *testing.T, profile string) []byte { +func runStatusCmd(ctx context.Context, t *testing.T, profile string, increaseEnv bool) []byte { // make sure minikube status shows insufficient storage c := exec.CommandContext(ctx, Target(), "status", "-p", profile, "--output=json", "--layout=cluster") // artificially set /var to 100% capacity - c.Env = append(os.Environ(), fmt.Sprintf("%s=100", constants.TestDiskUsedEnv)) + if increaseEnv { + c.Env = append(os.Environ(), fmt.Sprintf("%s=100", constants.TestDiskUsedEnv)) + } rr, err := Run(t, c) // status exits non-0 if status isn't Running if err == nil { @@ -96,3 +98,41 @@ func verifyClusterState(t *testing.T, contents []byte) { } } } + +func TestPauseStatus(t *testing.T) { + // run start + profile := UniqueProfileName("pause-status") + ctx, cancel := context.WithTimeout(context.Background(), Minutes(5)) + defer Cleanup(t, profile, cancel) + + startArgs := []string{"start", "-p", profile, "--output=json", "--wait=true"} + startArgs = append(startArgs, StartArgs()...) + c := exec.CommandContext(ctx, Target(), startArgs...) + + rr, err := Run(t, c) + if err != nil { + t.Fatalf("minikube start failed %v\n%v", rr.Command(), err) + } + + // run pause + pauseArgs := []string{"pause", "-p", profile} + c = exec.CommandContext(ctx, Target(), pauseArgs...) + rr, err = Run(t, c) + if err != nil { + t.Fatalf("minikube pause failed %v\n%v", rr.Command(), err) + } + + // run status + statusOutput := runStatusCmd(context.Background(), t, profile, false) + var cs cmd.ClusterState + if err := json.Unmarshal(statusOutput, &cs); err != nil { + t.Fatalf("unmarshalling: %v", err) + } + // verify the status looks as we expect + if cs.StatusCode != cmd.Paused { + t.Fatalf("incorrect status code: %v", cs.StatusCode) + } + if cs.StatusName != "Paused" { + t.Fatalf("incorrect status name: %v", cs.StatusName) + } +}