mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #12822 from brahmaroutu/container_stop_api
restapi stop fails if ?t=int not present
This commit is contained in:
commit
d78755d159
2 changed files with 20 additions and 4 deletions
|
@ -1037,10 +1037,7 @@ func (s *Server) postContainersStop(version version.Version, w http.ResponseWrit
|
|||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
|
||||
seconds, err := strconv.Atoi(r.Form.Get("t"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
seconds, _ := strconv.Atoi(r.Form.Get("t"))
|
||||
|
||||
if err := s.daemon.ContainerStop(vars["name"], seconds); err != nil {
|
||||
if err.Error() == "Container already stopped" {
|
||||
|
|
|
@ -1221,3 +1221,22 @@ func (s *DockerSuite) TestContainersApiChunkedEncoding(c *check.C) {
|
|||
c.Fatalf("got incorrect bind spec, wanted %s, got: %s", expected, binds[0])
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPostContainerStop(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
containerID := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(containerID), check.IsNil)
|
||||
|
||||
statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/stop", nil)
|
||||
|
||||
// 204 No Content is expected, not 200
|
||||
c.Assert(statusCode, check.Equals, http.StatusNoContent)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
if err := waitInspect(containerID, "{{ .State.Running }}", "false", 5); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue