From d0de2b1e2f0939b25c83183f450c71b8309d1d32 Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Tue, 19 May 2015 13:48:44 +0800 Subject: [PATCH] Make docker ps --size show virtual size really work Signed-off-by: Lei Jitang --- daemon/container_linux.go | 2 +- integration-cli/docker_cli_ps_test.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/daemon/container_linux.go b/daemon/container_linux.go index ee9a5092d9..d250f4feee 100644 --- a/daemon/container_linux.go +++ b/daemon/container_linux.go @@ -336,7 +336,7 @@ func (container *Container) GetSize() (int64, int64) { sizeRw = -1 } - if _, err = os.Stat(container.basefs); err != nil { + if _, err = os.Stat(container.basefs); err == nil { if sizeRootfs, err = directory.Size(container.basefs); err != nil { sizeRootfs = -1 } diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index bb34575fba..a9d36be491 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -304,7 +304,7 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) { } expectedSize := fmt.Sprintf("%d B", (2 + baseBytes)) foundSize := lines[1][sizeIndex:] - if foundSize != expectedSize { + if !strings.Contains(foundSize, expectedSize) { c.Fatalf("Expected size %q, got %q", expectedSize, foundSize) } @@ -666,3 +666,17 @@ func (s *DockerSuite) TestPsGroupPortRange(c *check.C) { } } + +func (s *DockerSuite) TestPsWithSize(c *check.C) { + out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "sizetest", "busybox", "top")) + if err != nil { + c.Fatal(out, err) + } + out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "ps", "--size")) + if err != nil { + c.Fatal(out, err) + } + if !strings.Contains(out, "virtual") { + c.Fatalf("docker ps with --size should show virtual size of container") + } +}