From 05426c80d991ab31593a47dba166ff41ca23e374 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Wed, 7 Dec 2016 07:38:18 -0800 Subject: [PATCH] Fix `docker plugin inspect ` issue on Windows This fix is a follow up for comment: https://github.com/docker/docker/pull/29186/files#r91277345 While #29186 addresses the issue of `docker inspect ` on Windows, it actually makes `docker plugin inspect ` out `object not found` on Windows as well. This is actually misleading as plugin is not supported on Windows. This fix reverted the change in #29186 while at the same time, checks `not supported` in `docker inspect ` so that - `docker plugin inspect ` returns `not supported` on Windows - `docker inspect ` returns `not found` on Windows This fix is related to #29186 and #29185. Signed-off-by: Yong Tang (cherry picked from commit 0b3c10ac4ddfe3655bac080440a8553269f2307f) --- cli/command/system/inspect.go | 6 +++++- integration-cli/docker_cli_plugins_test.go | 11 +++++++++++ plugin/backend_unsupported.go | 6 +----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cli/command/system/inspect.go b/cli/command/system/inspect.go index dee4efcfec..f7172ae3c6 100644 --- a/cli/command/system/inspect.go +++ b/cli/command/system/inspect.go @@ -121,6 +121,10 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool, return strings.Contains(err.Error(), "This node is not a swarm manager") } + isErrNotSupported := func(err error) bool { + return strings.Contains(err.Error(), "not supported") + } + return func(ref string) (interface{}, []byte, error) { for _, inspectData := range inspectAutodetect { if typeConstraint != "" && inspectData.ObjectType != typeConstraint { @@ -128,7 +132,7 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool, } v, raw, err := inspectData.ObjectInspector(ref) if err != nil { - if typeConstraint == "" && (apiclient.IsErrNotFound(err) || isErrNotSwarmManager(err)) { + if typeConstraint == "" && (apiclient.IsErrNotFound(err) || isErrNotSwarmManager(err) || isErrNotSupported(err)) { continue } return v, raw, err diff --git a/integration-cli/docker_cli_plugins_test.go b/integration-cli/docker_cli_plugins_test.go index cfc02518e4..385a58337d 100644 --- a/integration-cli/docker_cli_plugins_test.go +++ b/integration-cli/docker_cli_plugins_test.go @@ -251,3 +251,14 @@ func (s *DockerSuite) TestPluginInspect(c *check.C) { _, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5]) c.Assert(err, checker.NotNil) } + +// Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345 +func (s *DockerSuite) TestPluginInspectOnWindows(c *check.C) { + // This test should work on Windows only + testRequires(c, DaemonIsWindows) + + out, _, err := dockerCmdWithError("plugin", "inspect", "foobar") + c.Assert(err, checker.NotNil) + c.Assert(out, checker.Contains, "plugins are not supported on this platform") + c.Assert(err.Error(), checker.Contains, "plugins are not supported on this platform") +} diff --git a/plugin/backend_unsupported.go b/plugin/backend_unsupported.go index 2d4b365faf..0364f4876e 100644 --- a/plugin/backend_unsupported.go +++ b/plugin/backend_unsupported.go @@ -4,7 +4,6 @@ package plugin import ( "errors" - "fmt" "io" "net/http" @@ -26,10 +25,7 @@ func (pm *Manager) Enable(name string, config *types.PluginEnableConfig) error { // Inspect examines a plugin config func (pm *Manager) Inspect(refOrID string) (tp types.Plugin, err error) { - // Even though plugin is not supported, we still want to return `not found` - // error so that `docker inspect` (without `--type` specified) returns correct - // `not found` message - return tp, fmt.Errorf("no such plugin name or ID associated with %q", refOrID) + return tp, errNotSupported } // Privileges pulls a plugin config and computes the privileges required to install it.