Browse code

Merge pull request #17788 from haoshuwei/modify-volume-inspect-multi

Modify docker volume inspect to return existed volumes and the names of the unexsited volumes

Sebastiaan van Stijn authored on 2015/12/06 22:03:46
Showing 2 changed files
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"encoding/json"
6 6
 	"fmt"
7 7
 	"io"
8
+	"net/http"
8 9
 	"net/url"
9 10
 	"text/tabwriter"
10 11
 	"text/template"
... ...
@@ -128,7 +129,12 @@ func (cli *DockerCli) CmdVolumeInspect(args ...string) error {
128 128
 	for _, name := range cmd.Args() {
129 129
 		resp, err := cli.call("GET", "/volumes/"+name, nil, nil)
130 130
 		if err != nil {
131
-			return err
131
+			if resp.statusCode != http.StatusNotFound {
132
+				return err
133
+			}
134
+			status = 1
135
+			fmt.Fprintf(cli.err, "Error: No such volume: %s\n", name)
136
+			continue
132 137
 		}
133 138
 
134 139
 		var volume types.Volume
... ...
@@ -50,6 +50,19 @@ func (s *DockerSuite) TestVolumeCliInspect(c *check.C) {
50 50
 	c.Assert(strings.TrimSpace(out), check.Equals, "test")
51 51
 }
52 52
 
53
+func (s *DockerSuite) TestVolumeCliInspectMulti(c *check.C) {
54
+	dockerCmd(c, "volume", "create", "--name", "test1")
55
+	dockerCmd(c, "volume", "create", "--name", "test2")
56
+
57
+	out, _ := dockerCmd(c, "volume", "inspect", "--format='{{ .Name }}'", "test1", "test2", "doesntexist")
58
+	outArr := strings.Split(strings.TrimSpace(out), "\n")
59
+	c.Assert(len(outArr), check.Equals, 3, check.Commentf("\n%s", out))
60
+
61
+	c.Assert(strings.Contains(out, "test1\n"), check.Equals, true)
62
+	c.Assert(strings.Contains(out, "test2\n"), check.Equals, true)
63
+	c.Assert(strings.Contains(out, "Error: No such volume: doesntexist\n"), check.Equals, true)
64
+}
65
+
53 66
 func (s *DockerSuite) TestVolumeCliLs(c *check.C) {
54 67
 	prefix := ""
55 68
 	if daemonPlatform == "windows" {