Browse code

Merge pull request #12822 from brahmaroutu/container_stop_api

restapi stop fails if ?t=int not present

David Calavera authored on 2015/05/08 01:38:59
Showing 2 changed files
... ...
@@ -1037,10 +1037,7 @@ func (s *Server) postContainersStop(version version.Version, w http.ResponseWrit
1037 1037
 		return fmt.Errorf("Missing parameter")
1038 1038
 	}
1039 1039
 
1040
-	seconds, err := strconv.Atoi(r.Form.Get("t"))
1041
-	if err != nil {
1042
-		return err
1043
-	}
1040
+	seconds, _ := strconv.Atoi(r.Form.Get("t"))
1044 1041
 
1045 1042
 	if err := s.daemon.ContainerStop(vars["name"], seconds); err != nil {
1046 1043
 		if err.Error() == "Container already stopped" {
... ...
@@ -1221,3 +1221,22 @@ func (s *DockerSuite) TestContainersApiChunkedEncoding(c *check.C) {
1221 1221
 		c.Fatalf("got incorrect bind spec, wanted %s, got: %s", expected, binds[0])
1222 1222
 	}
1223 1223
 }
1224
+
1225
+func (s *DockerSuite) TestPostContainerStop(c *check.C) {
1226
+	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
1227
+	out, _, err := runCommandWithOutput(runCmd)
1228
+	c.Assert(err, check.IsNil)
1229
+
1230
+	containerID := strings.TrimSpace(out)
1231
+	c.Assert(waitRun(containerID), check.IsNil)
1232
+
1233
+	statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/stop", nil)
1234
+
1235
+	// 204 No Content is expected, not 200
1236
+	c.Assert(statusCode, check.Equals, http.StatusNoContent)
1237
+	c.Assert(err, check.IsNil)
1238
+
1239
+	if err := waitInspect(containerID, "{{ .State.Running  }}", "false", 5); err != nil {
1240
+		c.Fatal(err)
1241
+	}
1242
+}