Merge pull request #29874 from allencloud/fix-29872-volume-ls-filter

fix volume ls filter driver
This commit is contained in:
Vincent Demeester 2017-01-09 13:06:17 +01:00 committed by GitHub
commit e8e4546bc3
3 changed files with 34 additions and 16 deletions

View file

@ -623,7 +623,7 @@ func (daemon *Daemon) filterVolumes(vols []volume.Volume, filter filters.Args) (
}
}
if filter.Include("driver") {
if !filter.Match("driver", vol.DriverName()) {
if !filter.ExactMatch("driver", vol.DriverName()) {
continue
}
}

View file

@ -76,9 +76,9 @@ local rosemary
### driver
The `driver` filter matches on all or part of a volume's driver name.
The `driver` filter matches volumes based on their driver.
The following filter matches all volumes with a driver name containing the `local` string.
The following example matches volumes that are created with the `local` driver:
```bash
$ docker volume ls -f driver=local

View file

@ -184,19 +184,6 @@ func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *check.C) {
c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("execpeted volume 'testisinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invalidDriver")
outArr := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=local")
outArr = strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loc")
outArr = strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out))
}
func (s *DockerSuite) TestVolumeCLILsErrorWithInvalidFilterName(c *check.C) {
@ -377,6 +364,37 @@ func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *check.C) {
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
}
func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *check.C) {
// using default volume driver local to create volumes
testVol1 := "testvol-1"
out, _, err := dockerCmdWithError("volume", "create", testVol1)
c.Assert(err, check.IsNil)
testVol2 := "testvol-2"
out, _, err = dockerCmdWithError("volume", "create", testVol2)
c.Assert(err, check.IsNil)
// filter with driver=local
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=local")
c.Assert(out, checker.Contains, "testvol-1\n", check.Commentf("expected volume 'testvol-1' in output"))
c.Assert(out, checker.Contains, "testvol-2\n", check.Commentf("expected volume 'testvol-2' in output"))
// filter with driver=invaliddriver
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invaliddriver")
outArr := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
// filter with driver=loca
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loca")
outArr = strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
// filter with driver=
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=")
outArr = strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
}
func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *check.C) {
out, _ := dockerCmd(c, "volume", "create")
id := strings.TrimSpace(out)