1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Allow partial name match for node ls, and node tasks

This fix is an extension to last commit to expand the partial
filter to node and task searches.

Additional integration tests have been added to cover the changes.

This fix fixes 24270.
This fix fixes 24112.

Note: A separate pull request will be opened on swarmkit.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2016-07-17 13:21:29 -07:00
parent 1d600ebcb5
commit e734fa58ea
2 changed files with 50 additions and 8 deletions

View file

@ -21,7 +21,7 @@ func newListNodesFilters(filter filters.Args) (*swarmapi.ListNodesRequest_Filter
return nil, err return nil, err
} }
f := &swarmapi.ListNodesRequest_Filters{ f := &swarmapi.ListNodesRequest_Filters{
Names: filter.Get("name"), NamePrefixes: filter.Get("name"),
IDPrefixes: filter.Get("id"), IDPrefixes: filter.Get("id"),
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")), Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
} }
@ -79,7 +79,7 @@ func newListTasksFilters(filter filters.Args, transformFunc func(filters.Args) e
} }
} }
f := &swarmapi.ListTasksRequest_Filters{ f := &swarmapi.ListTasksRequest_Filters{
Names: filter.Get("name"), NamePrefixes: filter.Get("name"),
IDPrefixes: filter.Get("id"), IDPrefixes: filter.Get("id"),
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")), Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
ServiceIDs: filter.Get("service"), ServiceIDs: filter.Get("service"),

View file

@ -211,3 +211,45 @@ func (s *DockerSwarmSuite) TestSwarmServiceListFilter(c *check.C) {
c.Assert(out, checker.Contains, name2+" ") c.Assert(out, checker.Contains, name2+" ")
c.Assert(out, checker.Contains, name3+" ") c.Assert(out, checker.Contains, name3+" ")
} }
func (s *DockerSwarmSuite) TestSwarmNodeListFilter(c *check.C) {
d := s.AddDaemon(c, true, true)
out, err := d.Cmd("node", "inspect", "--format", "{{ .Description.Hostname }}", "self")
c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
name := strings.TrimSpace(out)
filter := "name=" + name[:4]
out, err = d.Cmd("node", "ls", "--filter", filter)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, name)
out, err = d.Cmd("node", "ls", "--filter", "name=none")
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Not(checker.Contains), name)
}
func (s *DockerSwarmSuite) TestSwarmNodeTaskListFilter(c *check.C) {
d := s.AddDaemon(c, true, true)
name := "redis-cluster-md5"
out, err := d.Cmd("service", "create", "--name", name, "--replicas=3", "busybox", "top")
c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
filter := "name=redis-cluster"
out, err = d.Cmd("node", "tasks", "--filter", filter, "self")
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, name+".1")
c.Assert(out, checker.Contains, name+".2")
c.Assert(out, checker.Contains, name+".3")
out, err = d.Cmd("node", "tasks", "--filter", "name=none", "self")
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Not(checker.Contains), name+".1")
c.Assert(out, checker.Not(checker.Contains), name+".2")
c.Assert(out, checker.Not(checker.Contains), name+".3")
}