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

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 (
"fmt"
"strings"
"golang.org/x/net/context"
@ -85,14 +86,18 @@ func inspectAll(ctx context.Context, dockerCli *client.DockerCli, getSize bool)
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)
if err == nil || !apiclient.IsErrNotFound(err) {
if err == nil || !(apiclient.IsErrNotFound(err) || isErrorNoSwarmMode(err)) {
if getSize {
fmt.Fprintln(dockerCli.Err(), "WARNING: --size ignored for tasks")
}
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")
//unexpected nil err trying to inspect what should be a non-existent image
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) {

View file

@ -326,7 +326,7 @@ func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) {
}
// 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 {
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.
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))
out = strings.TrimSpace(out)
if out != "true" {

View file

@ -353,7 +353,7 @@ func (s *DockerExternalGraphdriverSuite) testExternalGraphDriver(name string, ex
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(strings.TrimSpace(out), check.Equals, name)

View file

@ -73,10 +73,10 @@ func (s *DockerSuite) TestHealth(c *check.C) {
// Inspect the options
out, _ = dockerCmd(c, "inspect",
"--format='timeout={{.Config.Healthcheck.Timeout}} "+
"--format=timeout={{.Config.Healthcheck.Timeout}} "+
"interval={{.Config.Healthcheck.Interval}} "+
"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")
// Start

View file

@ -85,7 +85,7 @@ func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
formatStr := "--format='{{.State.Running}}'"
formatStr := "--format={{.State.Running}}"
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
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))
//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)
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
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))
//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)
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
c.Assert(err, checker.IsNil)
@ -289,7 +289,7 @@ func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) {
runSleepingContainer(c, "--name=busybox", "-d")
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}"
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))
}
@ -333,7 +333,7 @@ func (s *DockerSuite) TestInspectTemplateError(c *check.C) {
func (s *DockerSuite) TestInspectJSONFields(c *check.C) {
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(out, checker.Equals, "[]\n")

View file

@ -63,7 +63,7 @@ func (s *DockerSuite) TestRenameCheckNames(c *check.C) {
name, err := inspectFieldWithError("first_name", "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) {
@ -129,7 +129,7 @@ func (s *DockerSuite) TestRenameContainerWithLinkedContainer(c *check.C) {
db1, _ := dockerCmd(c, "run", "--name", "db1", "-d", "busybox", "top")
dockerCmd(c, "run", "--name", "app1", "-d", "--link", "db1:/mysql", "busybox", "top")
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(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")
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))
// 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')