Browse code

Fix `docker plugin inspect <unkown object>` 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 <unknown object>`
on Windows, it actually makes `docker plugin inspect <unknown object>`
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 <unknown object>` so that
- `docker plugin inspect <unknown object>` returns `not supported` on Windows
- `docker inspect <unknown object>` returns `not found` on Windows

This fix is related to #29186 and #29185.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 0b3c10ac4ddfe3655bac080440a8553269f2307f)

Yong Tang authored on 2016/12/08 00:38:18
Showing 3 changed files
... ...
@@ -121,6 +121,10 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool,
121 121
 		return strings.Contains(err.Error(), "This node is not a swarm manager")
122 122
 	}
123 123
 
124
+	isErrNotSupported := func(err error) bool {
125
+		return strings.Contains(err.Error(), "not supported")
126
+	}
127
+
124 128
 	return func(ref string) (interface{}, []byte, error) {
125 129
 		for _, inspectData := range inspectAutodetect {
126 130
 			if typeConstraint != "" && inspectData.ObjectType != typeConstraint {
... ...
@@ -128,7 +132,7 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool,
128 128
 			}
129 129
 			v, raw, err := inspectData.ObjectInspector(ref)
130 130
 			if err != nil {
131
-				if typeConstraint == "" && (apiclient.IsErrNotFound(err) || isErrNotSwarmManager(err)) {
131
+				if typeConstraint == "" && (apiclient.IsErrNotFound(err) || isErrNotSwarmManager(err) || isErrNotSupported(err)) {
132 132
 					continue
133 133
 				}
134 134
 				return v, raw, err
... ...
@@ -251,3 +251,14 @@ func (s *DockerSuite) TestPluginInspect(c *check.C) {
251 251
 	_, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
252 252
 	c.Assert(err, checker.NotNil)
253 253
 }
254
+
255
+// Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345
256
+func (s *DockerSuite) TestPluginInspectOnWindows(c *check.C) {
257
+	// This test should work on Windows only
258
+	testRequires(c, DaemonIsWindows)
259
+
260
+	out, _, err := dockerCmdWithError("plugin", "inspect", "foobar")
261
+	c.Assert(err, checker.NotNil)
262
+	c.Assert(out, checker.Contains, "plugins are not supported on this platform")
263
+	c.Assert(err.Error(), checker.Contains, "plugins are not supported on this platform")
264
+}
... ...
@@ -4,7 +4,6 @@ package plugin
4 4
 
5 5
 import (
6 6
 	"errors"
7
-	"fmt"
8 7
 	"io"
9 8
 	"net/http"
10 9
 
... ...
@@ -26,10 +25,7 @@ func (pm *Manager) Enable(name string, config *types.PluginEnableConfig) error {
26 26
 
27 27
 // Inspect examines a plugin config
28 28
 func (pm *Manager) Inspect(refOrID string) (tp types.Plugin, err error) {
29
-	// Even though plugin is not supported, we still want to return `not found`
30
-	// error so that `docker inspect` (without `--type` specified) returns correct
31
-	// `not found` message
32
-	return tp, fmt.Errorf("no such plugin name or ID associated with %q", refOrID)
29
+	return tp, errNotSupported
33 30
 }
34 31
 
35 32
 // Privileges pulls a plugin config and computes the privileges required to install it.