From e734fa58eadb4dfaa33b4be275d6f8f29d899e78 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Sun, 17 Jul 2016 13:21:29 -0700 Subject: [PATCH] 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 --- daemon/cluster/filters.go | 16 ++++----- integration-cli/docker_cli_swarm_test.go | 42 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/daemon/cluster/filters.go b/daemon/cluster/filters.go index 70e7c34b14..c49ea7b39b 100644 --- a/daemon/cluster/filters.go +++ b/daemon/cluster/filters.go @@ -21,9 +21,9 @@ func newListNodesFilters(filter filters.Args) (*swarmapi.ListNodesRequest_Filter return nil, err } f := &swarmapi.ListNodesRequest_Filters{ - Names: filter.Get("name"), - IDPrefixes: filter.Get("id"), - Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")), + NamePrefixes: filter.Get("name"), + IDPrefixes: filter.Get("id"), + Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")), } for _, r := range filter.Get("role") { @@ -79,11 +79,11 @@ func newListTasksFilters(filter filters.Args, transformFunc func(filters.Args) e } } f := &swarmapi.ListTasksRequest_Filters{ - Names: filter.Get("name"), - IDPrefixes: filter.Get("id"), - Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")), - ServiceIDs: filter.Get("service"), - NodeIDs: filter.Get("node"), + NamePrefixes: filter.Get("name"), + IDPrefixes: filter.Get("id"), + Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")), + ServiceIDs: filter.Get("service"), + NodeIDs: filter.Get("node"), } for _, s := range filter.Get("desired-state") { diff --git a/integration-cli/docker_cli_swarm_test.go b/integration-cli/docker_cli_swarm_test.go index 335526376f..8f6ee9d54d 100644 --- a/integration-cli/docker_cli_swarm_test.go +++ b/integration-cli/docker_cli_swarm_test.go @@ -211,3 +211,45 @@ func (s *DockerSwarmSuite) TestSwarmServiceListFilter(c *check.C) { c.Assert(out, checker.Contains, name2+" ") 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") +}