From b34706b152c02355cc80aa3b0871ed4a4f6036bc Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Wed, 29 Jun 2016 19:48:53 -0700 Subject: [PATCH] Use HOSTNAME in the output of `docker node ls` This fix tries to address an issue raised in #24090 where the title field of `docker node ls` use NAME instead of HOSTNAME. Yet the content of this field is actually hostname. The fix makes needed changes for the output of `docker node ls`. An additional test has been added to cover the change in this fix. This fix fixes #24090. Signed-off-by: Yong Tang (cherry picked from commit 4bc91ceeb750db6a6270b2f1821cb0b2f30117fc) --- api/client/node/list.go | 8 ++------ integration-cli/docker_cli_swarm_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/api/client/node/list.go b/api/client/node/list.go index 374ecaccb3..16370056ca 100644 --- a/api/client/node/list.go +++ b/api/client/node/list.go @@ -74,16 +74,12 @@ func printTable(out io.Writer, nodes []swarm.Node, info types.Info) { // Ignore flushing errors defer writer.Flush() - fmt.Fprintf(writer, listItemFmt, "ID", "NAME", "MEMBERSHIP", "STATUS", "AVAILABILITY", "MANAGER STATUS") + fmt.Fprintf(writer, listItemFmt, "ID", "HOSTNAME", "MEMBERSHIP", "STATUS", "AVAILABILITY", "MANAGER STATUS") for _, node := range nodes { - name := node.Spec.Name + name := node.Description.Hostname availability := string(node.Spec.Availability) membership := string(node.Spec.Membership) - if name == "" { - name = node.Description.Hostname - } - reachability := "" if node.ManagerStatus != nil { if node.ManagerStatus.Leader { diff --git a/integration-cli/docker_cli_swarm_test.go b/integration-cli/docker_cli_swarm_test.go index 7ac5657d66..83b09d43fc 100644 --- a/integration-cli/docker_cli_swarm_test.go +++ b/integration-cli/docker_cli_swarm_test.go @@ -5,6 +5,7 @@ package main import ( "encoding/json" "io/ioutil" + "strings" "time" "github.com/docker/docker/pkg/integration/checker" @@ -158,3 +159,13 @@ func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *check.C) { // restart for teardown c.Assert(d.Start(), checker.IsNil) } + +// Test case for #24090 +func (s *DockerSwarmSuite) TestSwarmNodeListHostname(c *check.C) { + d := s.AddDaemon(c, true, true) + + // The first line should contain "HOSTNAME" + out, err := d.Cmd("node", "ls") + c.Assert(err, checker.IsNil) + c.Assert(strings.Split(out, "\n")[0], checker.Contains, "HOSTNAME") +}