Ignore 'not a swarm error' when inspecting a task.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-06-23 12:24:28 -04:00
parent 851c388ad9
commit fab2a3dc82
8 changed files with 22 additions and 17 deletions

View File

@ -2,6 +2,7 @@ package system
import ( import (
"fmt" "fmt"
"strings"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -85,14 +86,18 @@ func inspectAll(ctx context.Context, dockerCli *client.DockerCli, getSize bool)
return i, rawImage, err return i, rawImage, err
} }
// Search for task with that id if an image doesn't exists. // Search for task with that id if an image doesn't exist.
t, rawTask, err := client.TaskInspectWithRaw(ctx, ref) t, rawTask, err := client.TaskInspectWithRaw(ctx, ref)
if err == nil || !apiclient.IsErrNotFound(err) { if err == nil || !(apiclient.IsErrNotFound(err) || isErrorNoSwarmMode(err)) {
if getSize { if getSize {
fmt.Fprintln(dockerCli.Err(), "WARNING: --size ignored for tasks") fmt.Fprintln(dockerCli.Err(), "WARNING: --size ignored for tasks")
} }
return t, rawTask, err return t, rawTask, err
} }
return nil, nil, fmt.Errorf("Error: No such image, container or task: %s", ref) return nil, nil, fmt.Errorf("Error: No such container, image or task: %s", ref)
} }
} }
func isErrorNoSwarmMode(err error) bool {
return strings.Contains(err.Error(), "This node is not a swarm manager")
}

View File

@ -176,7 +176,7 @@ func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) {
_, err = inspectFieldWithError(imageReference, "Id") _, err = inspectFieldWithError(imageReference, "Id")
//unexpected nil err trying to inspect what should be a non-existent image //unexpected nil err trying to inspect what should be a non-existent image
c.Assert(err, checker.NotNil) c.Assert(err, checker.NotNil)
c.Assert(err.Error(), checker.Contains, "No such image") c.Assert(err.Error(), checker.Contains, "No such container, image")
} }
func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) { func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {

View File

@ -326,7 +326,7 @@ func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) {
} }
// make sure the container is not running // make sure the container is not running
runningOut, err := s.d.Cmd("inspect", "--format='{{.State.Running}}'", "top") runningOut, err := s.d.Cmd("inspect", "--format={{.State.Running}}", "top")
if err != nil { if err != nil {
c.Fatalf("Could not inspect on container: %s, %v", out, err) c.Fatalf("Could not inspect on container: %s, %v", out, err)
} }
@ -2196,7 +2196,7 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) {
} }
// container should be running. // container should be running.
out, err = s.d.Cmd("inspect", "--format='{{.State.Running}}'", id) out, err = s.d.Cmd("inspect", "--format={{.State.Running}}", id)
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
out = strings.TrimSpace(out) out = strings.TrimSpace(out)
if out != "true" { if out != "true" {

View File

@ -353,7 +353,7 @@ func (s *DockerExternalGraphdriverSuite) testExternalGraphDriver(name string, ex
err = s.d.Restart("-s", name) err = s.d.Restart("-s", name)
out, err = s.d.Cmd("inspect", "--format='{{.GraphDriver.Name}}'", "graphtest") out, err = s.d.Cmd("inspect", "--format={{.GraphDriver.Name}}", "graphtest")
c.Assert(err, check.IsNil, check.Commentf(out)) c.Assert(err, check.IsNil, check.Commentf(out))
c.Assert(strings.TrimSpace(out), check.Equals, name) c.Assert(strings.TrimSpace(out), check.Equals, name)

View File

@ -73,10 +73,10 @@ func (s *DockerSuite) TestHealth(c *check.C) {
// Inspect the options // Inspect the options
out, _ = dockerCmd(c, "inspect", out, _ = dockerCmd(c, "inspect",
"--format='timeout={{.Config.Healthcheck.Timeout}} "+ "--format=timeout={{.Config.Healthcheck.Timeout}} "+
"interval={{.Config.Healthcheck.Interval}} "+ "interval={{.Config.Healthcheck.Interval}} "+
"retries={{.Config.Healthcheck.Retries}} "+ "retries={{.Config.Healthcheck.Retries}} "+
"test={{.Config.Healthcheck.Test}}'", name) "test={{.Config.Healthcheck.Test}}", name)
c.Check(out, checker.Equals, "timeout=30s interval=1s retries=0 test=[CMD-SHELL cat /status]\n") c.Check(out, checker.Equals, "timeout=30s interval=1s retries=0 test=[CMD-SHELL cat /status]\n")
// Start // Start

View File

@ -85,7 +85,7 @@ func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top") dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
formatStr := "--format='{{.State.Running}}'" formatStr := "--format={{.State.Running}}"
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox") out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
c.Assert(out, checker.Equals, "true\n") // not a container JSON c.Assert(out, checker.Equals, "true\n") // not a container JSON
} }
@ -137,7 +137,7 @@ func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect size of the image: %s, %v", out, err)) c.Assert(err, checker.IsNil, check.Commentf("failed to inspect size of the image: %s, %v", out, err))
//now see if the size turns out to be the same //now see if the size turns out to be the same
formatStr := fmt.Sprintf("--format='{{eq .Size %d}}'", size) formatStr := fmt.Sprintf("--format={{eq .Size %d}}", size)
out, _ = dockerCmd(c, "inspect", formatStr, imageTest) out, _ = dockerCmd(c, "inspect", formatStr, imageTest)
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")) result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
@ -159,7 +159,7 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect exitcode of the container: %s, %v", out, err)) c.Assert(err, checker.IsNil, check.Commentf("failed to inspect exitcode of the container: %s, %v", out, err))
//now get the exit code to verify //now get the exit code to verify
formatStr := fmt.Sprintf("--format='{{eq .State.ExitCode %d}}'", exitCode) formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode)
out, _ = dockerCmd(c, "inspect", formatStr, id) out, _ = dockerCmd(c, "inspect", formatStr, id)
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")) result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
@ -289,7 +289,7 @@ func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) {
runSleepingContainer(c, "--name=busybox", "-d") runSleepingContainer(c, "--name=busybox", "-d")
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'" formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}"
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox") out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
c.Assert(strings.TrimSpace(out), check.Equals, "<nil>,<nil>", check.Commentf("Exepcted not to display size info: %s", out)) c.Assert(strings.TrimSpace(out), check.Equals, "<nil>,<nil>", check.Commentf("Exepcted not to display size info: %s", out))
} }
@ -333,7 +333,7 @@ func (s *DockerSuite) TestInspectTemplateError(c *check.C) {
func (s *DockerSuite) TestInspectJSONFields(c *check.C) { func (s *DockerSuite) TestInspectJSONFields(c *check.C) {
runSleepingContainer(c, "--name=busybox", "-d") runSleepingContainer(c, "--name=busybox", "-d")
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='{{.HostConfig.Dns}}'", "busybox") out, _, err := dockerCmdWithError("inspect", "--type=container", "--format={{.HostConfig.Dns}}", "busybox")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
c.Assert(out, checker.Equals, "[]\n") c.Assert(out, checker.Equals, "[]\n")

View File

@ -63,7 +63,7 @@ func (s *DockerSuite) TestRenameCheckNames(c *check.C) {
name, err := inspectFieldWithError("first_name", "Name") name, err := inspectFieldWithError("first_name", "Name")
c.Assert(err, checker.NotNil, check.Commentf(name)) c.Assert(err, checker.NotNil, check.Commentf(name))
c.Assert(err.Error(), checker.Contains, "No such image, container or task: first_name") c.Assert(err.Error(), checker.Contains, "No such container, image or task: first_name")
} }
func (s *DockerSuite) TestRenameInvalidName(c *check.C) { func (s *DockerSuite) TestRenameInvalidName(c *check.C) {
@ -129,7 +129,7 @@ func (s *DockerSuite) TestRenameContainerWithLinkedContainer(c *check.C) {
db1, _ := dockerCmd(c, "run", "--name", "db1", "-d", "busybox", "top") db1, _ := dockerCmd(c, "run", "--name", "db1", "-d", "busybox", "top")
dockerCmd(c, "run", "--name", "app1", "-d", "--link", "db1:/mysql", "busybox", "top") dockerCmd(c, "run", "--name", "app1", "-d", "--link", "db1:/mysql", "busybox", "top")
dockerCmd(c, "rename", "app1", "app2") dockerCmd(c, "rename", "app1", "app2")
out, _, err := dockerCmdWithError("inspect", "--format='{{ .Id }}'", "app2/mysql") out, _, err := dockerCmdWithError("inspect", "--format={{ .Id }}", "app2/mysql")
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(db1)) c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(db1))
} }

View File

@ -45,7 +45,7 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
user := s.findUser(c, "userns") user := s.findUser(c, "userns")
c.Assert(uidgid[0], checker.Equals, user) c.Assert(uidgid[0], checker.Equals, user)
pid, err := s.d.Cmd("inspect", "--format='{{.State.Pid}}'", "userns") pid, err := s.d.Cmd("inspect", "--format={{.State.Pid}}", "userns")
c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid)) c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid))
// check the uid and gid maps for the PID to ensure root is remapped // check the uid and gid maps for the PID to ensure root is remapped
// (cmd = cat /proc/<pid>/uid_map | grep -E '0\s+9999\s+1') // (cmd = cat /proc/<pid>/uid_map | grep -E '0\s+9999\s+1')