Signed-off-by: Lei Jitang <leijitang@huawei.com>
| ... | ... |
@@ -336,7 +336,7 @@ func (container *Container) GetSize() (int64, int64) {
|
| 336 | 336 |
sizeRw = -1 |
| 337 | 337 |
} |
| 338 | 338 |
|
| 339 |
- if _, err = os.Stat(container.basefs); err != nil {
|
|
| 339 |
+ if _, err = os.Stat(container.basefs); err == nil {
|
|
| 340 | 340 |
if sizeRootfs, err = directory.Size(container.basefs); err != nil {
|
| 341 | 341 |
sizeRootfs = -1 |
| 342 | 342 |
} |
| ... | ... |
@@ -304,7 +304,7 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
| 304 | 304 |
} |
| 305 | 305 |
expectedSize := fmt.Sprintf("%d B", (2 + baseBytes))
|
| 306 | 306 |
foundSize := lines[1][sizeIndex:] |
| 307 |
- if foundSize != expectedSize {
|
|
| 307 |
+ if !strings.Contains(foundSize, expectedSize) {
|
|
| 308 | 308 |
c.Fatalf("Expected size %q, got %q", expectedSize, foundSize)
|
| 309 | 309 |
} |
| 310 | 310 |
|
| ... | ... |
@@ -666,3 +666,17 @@ func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
|
| 666 | 666 |
} |
| 667 | 667 |
|
| 668 | 668 |
} |
| 669 |
+ |
|
| 670 |
+func (s *DockerSuite) TestPsWithSize(c *check.C) {
|
|
| 671 |
+ out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "sizetest", "busybox", "top")) |
|
| 672 |
+ if err != nil {
|
|
| 673 |
+ c.Fatal(out, err) |
|
| 674 |
+ } |
|
| 675 |
+ out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "ps", "--size")) |
|
| 676 |
+ if err != nil {
|
|
| 677 |
+ c.Fatal(out, err) |
|
| 678 |
+ } |
|
| 679 |
+ if !strings.Contains(out, "virtual") {
|
|
| 680 |
+ c.Fatalf("docker ps with --size should show virtual size of container")
|
|
| 681 |
+ } |
|
| 682 |
+} |