Merge pull request #16098 from thaJeztah/fix-16095-reverse-dangling

Fix docker volume dangling filter
This commit is contained in:
Brian Goff 2015-09-08 10:17:07 -04:00
Родитель 5f5d73d515 1cbf9047b3
Коммит 3a539c6db9
2 изменённых файлов: 36 добавлений и 1 удалений

Просмотреть файл

@ -381,7 +381,7 @@ func (daemon *Daemon) Volumes(filter string) ([]*types.Volume, error) {
volumes := daemon.volumes.List()
for _, v := range volumes {
if filterUsed && daemon.volumes.Count(v) == 0 {
if filterUsed && daemon.volumes.Count(v) > 0 {
continue
}
volumesOut = append(volumesOut, volumeToAPIType(v))

Просмотреть файл

@ -4,6 +4,7 @@ import (
"os/exec"
"strings"
"github.com/docker/docker/integration-cli/checker"
"github.com/go-check/check"
)
@ -54,6 +55,40 @@ func (s *DockerSuite) TestVolumeCliLs(c *check.C) {
c.Assert(strings.Contains(out, "test\n"), check.Equals, true)
}
func (s *DockerSuite) TestVolumeCliLsFilterDangling(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerCmd(c, "volume", "create", "--name", "testnotinuse1")
dockerCmd(c, "volume", "create", "--name", "testisinuse1")
dockerCmd(c, "volume", "create", "--name", "testisinuse2")
// Make sure both "created" (but not started), and started
// containers are included in reference counting
dockerCmd(c, "run", "--name", "volume-test1", "-v", "testisinuse1:/foo", "busybox", "true")
dockerCmd(c, "create", "--name", "volume-test2", "-v", "testisinuse2:/foo", "busybox", "true")
out, _ := dockerCmd(c, "volume", "ls")
// No filter, all volumes should show
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=false")
// Same as above, but expicitly disabling dangling
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=true")
// Filter "dangling" volumes; ony "dangling" (unused) volumes should be in the output
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
c.Assert(out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected"))
c.Assert(out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected"))
}
func (s *DockerSuite) TestVolumeCliRm(c *check.C) {
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "volume", "create")