Browse code

Merge pull request #15023 from hqhq/hq_add_status_in_inspect

Add status string to State field for inspect

Alexander Morozov authored on 2015/08/29 00:27:36
Showing 4 changed files
... ...
@@ -227,6 +227,7 @@ type ExecStartCheck struct {
227 227
 // ContainerState stores container's running state
228 228
 // it's part of ContainerJSONBase and will return by "inspect" command
229 229
 type ContainerState struct {
230
+	Status     string
230 231
 	Running    bool
231 232
 	Paused     bool
232 233
 	Restarting bool
... ...
@@ -46,6 +46,7 @@ func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSON
46 46
 	}
47 47
 
48 48
 	containerState := &types.ContainerState{
49
+		Status:     container.State.StateString(),
49 50
 		Running:    container.State.Running,
50 51
 		Paused:     container.State.Paused,
51 52
 		Restarting: container.State.Restarting,
... ...
@@ -437,8 +437,9 @@ Return low-level information on the container `id`
437 437
 			"Paused": false,
438 438
 			"Pid": 0,
439 439
 			"Restarting": false,
440
-			"Running": false,
441
-			"StartedAt": "2015-01-06T15:47:32.072697474Z"
440
+			"Running": true,
441
+			"StartedAt": "2015-01-06T15:47:32.072697474Z",
442
+			"Status": "running"
442 443
 		},
443 444
 		"Mounts": [
444 445
 			{
... ...
@@ -2176,6 +2177,7 @@ Return low-level information about the `exec` command `id`.
2176 2176
       "OpenStdout" : false,
2177 2177
       "Container" : {
2178 2178
         "State" : {
2179
+          "Status" : "running",
2179 2180
           "Running" : true,
2180 2181
           "Paused" : false,
2181 2182
           "Restarting" : false,
... ...
@@ -49,6 +49,38 @@ func (s *DockerSuite) TestInspectDefault(c *check.C) {
49 49
 	dockerCmd(c, "inspect", "busybox")
50 50
 }
51 51
 
52
+func (s *DockerSuite) TestInspectStatus(c *check.C) {
53
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
54
+	out = strings.TrimSpace(out)
55
+
56
+	inspectOut, err := inspectField(out, "State.Status")
57
+	c.Assert(err, check.IsNil)
58
+	if inspectOut != "running" {
59
+		c.Fatalf("inspect got wrong status, got: %q, expected: running", inspectOut)
60
+	}
61
+
62
+	dockerCmd(c, "pause", out)
63
+	inspectOut, err = inspectField(out, "State.Status")
64
+	c.Assert(err, check.IsNil)
65
+	if inspectOut != "paused" {
66
+		c.Fatalf("inspect got wrong status, got: %q, expected: paused", inspectOut)
67
+	}
68
+
69
+	dockerCmd(c, "unpause", out)
70
+	inspectOut, err = inspectField(out, "State.Status")
71
+	c.Assert(err, check.IsNil)
72
+	if inspectOut != "running" {
73
+		c.Fatalf("inspect got wrong status, got: %q, expected: running", inspectOut)
74
+	}
75
+
76
+	dockerCmd(c, "stop", out)
77
+	inspectOut, err = inspectField(out, "State.Status")
78
+	c.Assert(err, check.IsNil)
79
+	if inspectOut != "exited" {
80
+		c.Fatalf("inspect got wrong status, got: %q, expected: exited", inspectOut)
81
+	}
82
+}
83
+
52 84
 func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
53 85
 
54 86
 	//Both the container and image are named busybox. docker inspect will fetch container