2016-03-31 20:33:58 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-03-31 20:59:00 +00:00
|
|
|
"path/filepath"
|
|
|
|
"syscall"
|
|
|
|
|
2016-03-31 20:33:58 +00:00
|
|
|
"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
|
2016-06-03 22:00:49 +00:00
|
|
|
initp *ContainerProcess
|
|
|
|
echop *ContainerProcess
|
2016-03-31 20:33:58 +00:00
|
|
|
)
|
|
|
|
|
2016-06-03 22:00:49 +00:00
|
|
|
containerID := "top"
|
|
|
|
initp, err = cs.StartContainer(containerID, bundleName)
|
2016-03-31 20:33:58 +00:00
|
|
|
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",
|
2016-06-03 22:00:49 +00:00
|
|
|
Id: containerID,
|
2016-03-31 20:33:58 +00:00
|
|
|
Status: 0,
|
|
|
|
Pid: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "start-process",
|
2016-06-03 22:00:49 +00:00
|
|
|
Id: containerID,
|
2016-03-31 20:33:58 +00:00
|
|
|
Status: 0,
|
|
|
|
Pid: "echo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "exit",
|
2016-06-03 22:00:49 +00:00
|
|
|
Id: containerID,
|
2016-03-31 20:33:58 +00:00
|
|
|
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!")
|
|
|
|
}
|
2016-03-31 20:59:00 +00:00
|
|
|
|
|
|
|
func (cs *ContainerdSuite) TestBusyboxTopExecTop(t *check.C) {
|
|
|
|
bundleName := "busybox-top"
|
|
|
|
if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
2016-06-03 22:00:49 +00:00
|
|
|
initp *ContainerProcess
|
2016-03-31 20:59:00 +00:00
|
|
|
)
|
|
|
|
|
2016-06-03 22:00:49 +00:00
|
|
|
containerID := "top"
|
|
|
|
initp, err = cs.StartContainer(containerID, bundleName)
|
2016-03-31 20:59:00 +00:00
|
|
|
t.Assert(err, checker.Equals, nil)
|
|
|
|
|
2016-06-03 22:00:49 +00:00
|
|
|
execID := "top1"
|
|
|
|
_, err = cs.AddProcessToContainer(initp, execID, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0)
|
2016-03-31 20:59:00 +00:00
|
|
|
t.Assert(err, checker.Equals, nil)
|
|
|
|
|
|
|
|
for idx, evt := range []types.Event{
|
|
|
|
{
|
|
|
|
Type: "start-container",
|
2016-06-03 22:00:49 +00:00
|
|
|
Id: containerID,
|
2016-03-31 20:59:00 +00:00
|
|
|
Status: 0,
|
|
|
|
Pid: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "start-process",
|
2016-06-03 22:00:49 +00:00
|
|
|
Id: containerID,
|
2016-03-31 20:59:00 +00:00
|
|
|
Status: 0,
|
2016-06-03 22:00:49 +00:00
|
|
|
Pid: execID,
|
2016-03-31 20:59:00 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "exit",
|
2016-06-03 22:00:49 +00:00
|
|
|
Id: containerID,
|
2016-03-31 20:59:00 +00:00
|
|
|
Status: 137,
|
2016-06-03 22:00:49 +00:00
|
|
|
Pid: execID,
|
2016-03-31 20:59:00 +00:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
ch := initp.GetEventsChannel()
|
|
|
|
e := <-ch
|
|
|
|
evt.Timestamp = e.Timestamp
|
|
|
|
t.Assert(*e, checker.Equals, evt)
|
|
|
|
if idx == 1 {
|
|
|
|
// Process Started, kill it
|
2016-06-03 22:00:49 +00:00
|
|
|
cs.SignalContainerProcess(containerID, "top1", uint32(syscall.SIGKILL))
|
2016-03-31 20:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|
2016-03-31 21:01:56 +00:00
|
|
|
|
|
|
|
func (cs *ContainerdSuite) TestBusyboxTopExecTopKillInit(t *check.C) {
|
|
|
|
bundleName := "busybox-top"
|
|
|
|
if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
2016-06-03 22:00:49 +00:00
|
|
|
initp *ContainerProcess
|
2016-03-31 21:01:56 +00:00
|
|
|
)
|
|
|
|
|
2016-06-03 22:00:49 +00:00
|
|
|
containerID := "top"
|
|
|
|
initp, err = cs.StartContainer(containerID, bundleName)
|
2016-03-31 21:01:56 +00:00
|
|
|
t.Assert(err, checker.Equals, nil)
|
|
|
|
|
2016-06-03 22:00:49 +00:00
|
|
|
execID := "top1"
|
|
|
|
_, err = cs.AddProcessToContainer(initp, execID, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0)
|
2016-03-31 21:01:56 +00:00
|
|
|
t.Assert(err, checker.Equals, nil)
|
|
|
|
|
|
|
|
for idx, evt := range []types.Event{
|
|
|
|
{
|
|
|
|
Type: "start-container",
|
2016-06-03 22:00:49 +00:00
|
|
|
Id: containerID,
|
2016-03-31 21:01:56 +00:00
|
|
|
Status: 0,
|
|
|
|
Pid: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "start-process",
|
2016-06-03 22:00:49 +00:00
|
|
|
Id: containerID,
|
2016-03-31 21:01:56 +00:00
|
|
|
Status: 0,
|
2016-06-03 22:00:49 +00:00
|
|
|
Pid: execID,
|
2016-03-31 21:01:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "exit",
|
2016-06-03 22:00:49 +00:00
|
|
|
Id: containerID,
|
2016-03-31 21:01:56 +00:00
|
|
|
Status: 137,
|
2016-06-03 22:00:49 +00:00
|
|
|
Pid: execID,
|
2016-03-31 21:01:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "exit",
|
2016-06-03 22:00:49 +00:00
|
|
|
Id: containerID,
|
2016-03-31 21:01:56 +00:00
|
|
|
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
|
2016-06-03 22:00:49 +00:00
|
|
|
cs.SignalContainerProcess(containerID, "init", uint32(syscall.SIGTERM))
|
2016-03-31 21:01:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|