2015-04-13 02:36:04 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-07-23 07:34:40 -04:00
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2015-04-13 13:30:07 -04:00
|
|
|
"net/http"
|
2015-04-13 02:36:04 -04:00
|
|
|
"strings"
|
2015-08-04 07:44:54 -04:00
|
|
|
"sync"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-12-30 04:49:36 -05:00
|
|
|
"github.com/docker/docker/integration-cli/request"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2015-04-13 02:36:04 -04:00
|
|
|
)
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestExecResizeAPIHeightWidthNoInt(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
2015-04-13 02:36:04 -04:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"
|
2017-05-23 23:56:26 -04:00
|
|
|
res, _, err := request.Post(endpoint)
|
2015-10-15 10:28:21 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2017-05-23 23:56:26 -04:00
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
|
2015-04-13 02:36:04 -04:00
|
|
|
}
|
2015-07-23 07:34:40 -04:00
|
|
|
|
|
|
|
// Part of #14845
|
|
|
|
func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *check.C) {
|
|
|
|
name := "exec_resize_test"
|
|
|
|
dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh")
|
|
|
|
|
2015-08-04 07:44:54 -04:00
|
|
|
testExecResize := func() error {
|
|
|
|
data := map[string]interface{}{
|
|
|
|
"AttachStdin": true,
|
|
|
|
"Cmd": []string{"/bin/sh"},
|
|
|
|
}
|
|
|
|
uri := fmt.Sprintf("/containers/%s/exec", name)
|
2017-05-23 23:56:26 -04:00
|
|
|
res, body, err := request.Post(uri, request.JSONBody(data))
|
2015-08-04 07:44:54 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-05-23 23:56:26 -04:00
|
|
|
if res.StatusCode != http.StatusCreated {
|
|
|
|
return fmt.Errorf("POST %s is expected to return %d, got %d", uri, http.StatusCreated, res.StatusCode)
|
2015-08-04 07:44:54 -04:00
|
|
|
}
|
2015-07-23 07:34:40 -04:00
|
|
|
|
2017-05-23 23:56:26 -04:00
|
|
|
buf, err := request.ReadBody(body)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2015-08-04 07:44:54 -04:00
|
|
|
out := map[string]string{}
|
2017-05-23 23:56:26 -04:00
|
|
|
err = json.Unmarshal(buf, &out)
|
2015-08-04 07:44:54 -04:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("ExecCreate returned invalid json. Error: %q", err.Error())
|
|
|
|
}
|
2015-07-23 07:34:40 -04:00
|
|
|
|
2015-08-04 07:44:54 -04:00
|
|
|
execID := out["Id"]
|
|
|
|
if len(execID) < 1 {
|
|
|
|
return fmt.Errorf("ExecCreate got invalid execID")
|
|
|
|
}
|
2015-07-23 07:34:40 -04:00
|
|
|
|
2015-08-04 07:44:54 -04:00
|
|
|
payload := bytes.NewBufferString(`{"Tty":true}`)
|
2016-12-30 04:49:36 -05:00
|
|
|
conn, _, err := request.SockRequestHijack("POST", fmt.Sprintf("/exec/%s/start", execID), payload, "application/json", daemonHost())
|
2015-08-04 07:44:54 -04:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to start the exec: %q", err.Error())
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
2015-07-23 07:34:40 -04:00
|
|
|
|
2017-03-06 10:35:27 -05:00
|
|
|
_, rc, err := request.Post(fmt.Sprintf("/exec/%s/resize?h=24&w=80", execID), request.ContentType("text/plain"))
|
2015-08-04 07:44:54 -04:00
|
|
|
// It's probably a panic of the daemon if io.ErrUnexpectedEOF is returned.
|
|
|
|
if err == io.ErrUnexpectedEOF {
|
|
|
|
return fmt.Errorf("The daemon might have crashed.")
|
|
|
|
}
|
2015-07-23 07:34:40 -04:00
|
|
|
|
2015-08-04 07:44:54 -04:00
|
|
|
if err == nil {
|
|
|
|
rc.Close()
|
|
|
|
}
|
2015-07-23 07:34:40 -04:00
|
|
|
|
2015-08-04 07:44:54 -04:00
|
|
|
// We only interested in the io.ErrUnexpectedEOF error, so we return nil otherwise.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// The panic happens when daemon.ContainerExecStart is called but the
|
|
|
|
// container.Exec is not called.
|
|
|
|
// Because the panic is not 100% reproducible, we send the requests concurrently
|
|
|
|
// to increase the probability that the problem is triggered.
|
|
|
|
var (
|
|
|
|
n = 10
|
|
|
|
ch = make(chan error, n)
|
|
|
|
wg sync.WaitGroup
|
|
|
|
)
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
if err := testExecResize(); err != nil {
|
|
|
|
ch <- err
|
2015-07-23 07:34:40 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2015-08-04 07:44:54 -04:00
|
|
|
wg.Wait()
|
|
|
|
select {
|
|
|
|
case err := <-ch:
|
|
|
|
c.Fatal(err.Error())
|
|
|
|
default:
|
2015-07-23 07:34:40 -04:00
|
|
|
}
|
|
|
|
}
|