Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1342,8 +1342,8 @@ func (mgr *ContainerManager) Top(ctx context.Context, name string, psArgs string
return nil, err
}

if !c.IsRunning() {
return nil, fmt.Errorf("container %s is not running, cannot execute top command", c.ID)
if !c.IsRunningOrPaused() {
return nil, fmt.Errorf("container %s is not running or paused, cannot execute top command", c.ID)
}

pids, err := mgr.Client.ContainerPIDs(ctx, c.ID)
Expand Down
28 changes: 22 additions & 6 deletions test/cli_top_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ func (suite *PouchTopSuite) TearDownTest(c *check.C) {
func (suite *PouchTopSuite) TestTopStoppedContainer(c *check.C) {
name := "TestTopStoppedContainer"

res := command.PouchRun("create", "-m", "300M", "--name", name, busyboxImage)
res := command.PouchRun("create", "--name", name, busyboxImage, "top")
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)

res = command.PouchRun("top", name)
c.Assert(res.Stderr(), check.NotNil)

expectString := " is not running, cannot execute top command"
expectString := " is not running or paused, cannot execute top command"
if out := res.Combined(); !strings.Contains(out, expectString) {
// FIXME(ziren): for debug top error info is empty
fmt.Printf("%+v", res)
c.Fatalf("unexpected output %s expected %s", out, expectString)
}
}

// TestTopContainer is to verify the correctness of pouch top command.
func (suite *PouchTopSuite) TestTopContainer(c *check.C) {
name := "TestTopContainer"
// TestTopRunningOrPausedContainer is to verify the correctness of pouch top command.
func (suite *PouchTopSuite) TestTopRunningOrPausedContainer(c *check.C) {
name := "TestTopRunningOrPausedContainer"

res := command.PouchRun("run", "-d", "-m", "300M", "--name", name, busyboxImage, "top")
res := command.PouchRun("run", "-d", "--name", name, busyboxImage, "top")
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)

Expand All @@ -70,6 +70,22 @@ func (suite *PouchTopSuite) TestTopContainer(c *check.C) {
if out := util.TrimAllSpaceAndNewline(res.Combined()); !strings.HasSuffix(out, expectString) {
c.Fatalf("unexpected output %s expected %s", out, expectString)
}

// Top a paused contaner is valid
res = command.PouchRun("pause", name)
res.Assert(c, icmd.Success)

res = command.PouchRun("top", name)
res.Assert(c, icmd.Success)

expectString = "UIDPIDPPID"
if out := util.TrimAllSpaceAndNewline(res.Combined()); !strings.HasPrefix(out, expectString) {
c.Fatalf("unexpected output %s expected %s", out, expectString)
}
expectString = "top"
if out := util.TrimAllSpaceAndNewline(res.Combined()); !strings.HasSuffix(out, expectString) {
c.Fatalf("unexpected output %s expected %s", out, expectString)
}
}

// TestTopContainerWithOptions is to verify the correctness of pouch top command with ps options.
Expand Down