From 7117935db4fc810d29d00e61f2a464ebfc1c686e Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Thu, 31 Mar 2016 13:33:58 -0700 Subject: [PATCH 1/3] Add test for exec'ing new process in existing container Signed-off-by: Kenfe-Mickael Laventure --- integration-test/exec_test.go | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 integration-test/exec_test.go diff --git a/integration-test/exec_test.go b/integration-test/exec_test.go new file mode 100644 index 0000000..cb6fc26 --- /dev/null +++ b/integration-test/exec_test.go @@ -0,0 +1,56 @@ +package main + +import ( + "github.com/docker/containerd/api/grpc/types" + "github.com/docker/docker/pkg/integration/checker" + "github.com/go-check/check" +) + +func (cs *ContainerdSuite) TestBusyboxTopExecEcho(t *check.C) { + bundleName := "busybox-top" + if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil { + t.Fatal(err) + } + + var ( + err error + initp *containerProcess + echop *containerProcess + ) + + containerId := "top" + initp, err = cs.StartContainer(containerId, bundleName) + t.Assert(err, checker.Equals, nil) + + echop, err = cs.AddProcessToContainer(initp, "echo", "/", []string{"PATH=/bin"}, []string{"sh", "-c", "echo -n Ay Caramba! ; exit 1"}, 0, 0) + t.Assert(err, checker.Equals, nil) + + for _, evt := range []types.Event{ + { + Type: "start-container", + Id: containerId, + Status: 0, + Pid: "", + }, + { + Type: "start-process", + Id: containerId, + Status: 0, + Pid: "echo", + }, + { + Type: "exit", + Id: containerId, + Status: 1, + Pid: "echo", + }, + } { + ch := initp.GetEventsChannel() + e := <-ch + evt.Timestamp = e.Timestamp + + t.Assert(*e, checker.Equals, evt) + } + + t.Assert(echop.io.stdoutBuffer.String(), checker.Equals, "Ay Caramba!") +} From a7f27b8fb9637e948afeca08fd9864fc1b032a4e Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Thu, 31 Mar 2016 13:59:00 -0700 Subject: [PATCH 2/3] Add test for killing a long lived exec process Signed-off-by: Kenfe-Mickael Laventure --- integration-test/exec_test.go | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/integration-test/exec_test.go b/integration-test/exec_test.go index cb6fc26..d1b7da2 100644 --- a/integration-test/exec_test.go +++ b/integration-test/exec_test.go @@ -1,6 +1,9 @@ package main import ( + "path/filepath" + "syscall" + "github.com/docker/containerd/api/grpc/types" "github.com/docker/docker/pkg/integration/checker" "github.com/go-check/check" @@ -54,3 +57,63 @@ func (cs *ContainerdSuite) TestBusyboxTopExecEcho(t *check.C) { t.Assert(echop.io.stdoutBuffer.String(), checker.Equals, "Ay Caramba!") } + +func (cs *ContainerdSuite) TestBusyboxTopExecTop(t *check.C) { + bundleName := "busybox-top" + if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil { + t.Fatal(err) + } + + var ( + err error + initp *containerProcess + ) + + containerId := "top" + initp, err = cs.StartContainer(containerId, bundleName) + t.Assert(err, checker.Equals, nil) + + execId := "top1" + _, err = cs.AddProcessToContainer(initp, execId, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0) + t.Assert(err, checker.Equals, nil) + + for idx, evt := range []types.Event{ + { + Type: "start-container", + Id: containerId, + Status: 0, + Pid: "", + }, + { + Type: "start-process", + Id: containerId, + Status: 0, + Pid: execId, + }, + { + Type: "exit", + Id: containerId, + Status: 137, + Pid: execId, + }, + } { + ch := initp.GetEventsChannel() + e := <-ch + evt.Timestamp = e.Timestamp + t.Assert(*e, checker.Equals, evt) + if idx == 1 { + // Process Started, kill it + cs.SignalContainerProcess(containerId, "top1", uint32(syscall.SIGKILL)) + } + } + + // Container should still be running + containers, err := cs.ListRunningContainers() + if err != nil { + t.Fatal(err) + } + t.Assert(len(containers), checker.Equals, 1) + t.Assert(containers[0].Id, checker.Equals, "top") + t.Assert(containers[0].Status, checker.Equals, "running") + t.Assert(containers[0].BundlePath, check.Equals, filepath.Join(cs.cwd, GetBundle(bundleName).Path)) +} From 22fabf733c804073d9bc8b87649e4684b8fdc3b3 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Thu, 31 Mar 2016 14:01:56 -0700 Subject: [PATCH 3/3] Add test for events order when killing container with exec process Signed-off-by: Kenfe-Mickael Laventure --- integration-test/exec_test.go | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/integration-test/exec_test.go b/integration-test/exec_test.go index d1b7da2..5752362 100644 --- a/integration-test/exec_test.go +++ b/integration-test/exec_test.go @@ -117,3 +117,59 @@ func (cs *ContainerdSuite) TestBusyboxTopExecTop(t *check.C) { t.Assert(containers[0].Status, checker.Equals, "running") t.Assert(containers[0].BundlePath, check.Equals, filepath.Join(cs.cwd, GetBundle(bundleName).Path)) } + +func (cs *ContainerdSuite) TestBusyboxTopExecTopKillInit(t *check.C) { + bundleName := "busybox-top" + if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil { + t.Fatal(err) + } + + var ( + err error + initp *containerProcess + ) + + containerId := "top" + initp, err = cs.StartContainer(containerId, bundleName) + t.Assert(err, checker.Equals, nil) + + execId := "top1" + _, err = cs.AddProcessToContainer(initp, execId, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0) + t.Assert(err, checker.Equals, nil) + + for idx, evt := range []types.Event{ + { + Type: "start-container", + Id: containerId, + Status: 0, + Pid: "", + }, + { + Type: "start-process", + Id: containerId, + Status: 0, + Pid: execId, + }, + { + Type: "exit", + Id: containerId, + Status: 137, + Pid: execId, + }, + { + Type: "exit", + Id: containerId, + Status: 143, + Pid: "init", + }, + } { + ch := initp.GetEventsChannel() + e := <-ch + evt.Timestamp = e.Timestamp + t.Assert(*e, checker.Equals, evt) + if idx == 1 { + // Process Started, kill it + cs.SignalContainerProcess(containerId, "init", uint32(syscall.SIGTERM)) + } + } +}