Browse code

Various fixes

Signed-off-by: Christopher Crone <christopher.crone@docker.com>

Christopher Crone authored on 2017/09/15 22:16:38
Showing 4 changed files
... ...
@@ -16,16 +16,27 @@ import (
16 16
 
17 17
 func (s *DockerSuite) TestVolumesAPIList(c *check.C) {
18 18
 	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
19
-	dockerCmd(c, "run", "-v", prefix+"/foo", "busybox")
19
+	cid, _ := dockerCmd(c, "run", "-d", "-v", prefix+"/foo", "busybox")
20 20
 
21 21
 	cli, err := client.NewEnvClient()
22 22
 	c.Assert(err, checker.IsNil)
23 23
 	defer cli.Close()
24 24
 
25
+	container, err := cli.ContainerInspect(context.Background(), strings.TrimSpace(cid))
26
+	c.Assert(err, checker.IsNil)
27
+	vname := container.Mounts[0].Name
28
+
25 29
 	volumes, err := cli.VolumeList(context.Background(), filters.Args{})
26 30
 	c.Assert(err, checker.IsNil)
27 31
 
28
-	c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
32
+	found := false
33
+	for _, vol := range volumes.Volumes {
34
+		if vol.Name == vname {
35
+			found = true
36
+			break
37
+		}
38
+	}
39
+	c.Assert(found, checker.Equals, true)
29 40
 }
30 41
 
31 42
 func (s *DockerSuite) TestVolumesAPICreate(c *check.C) {
... ...
@@ -45,21 +56,21 @@ func (s *DockerSuite) TestVolumesAPICreate(c *check.C) {
45 45
 
46 46
 func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) {
47 47
 	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
48
-	dockerCmd(c, "run", "-v", prefix+"/foo", "--name=test", "busybox")
48
+	cid, _ := dockerCmd(c, "run", "-d", "-v", prefix+"/foo", "--name=test", "busybox")
49 49
 
50 50
 	cli, err := client.NewEnvClient()
51 51
 	c.Assert(err, checker.IsNil)
52 52
 	defer cli.Close()
53 53
 
54
-	volumes, err := cli.VolumeList(context.Background(), filters.Args{})
54
+	container, err := cli.ContainerInspect(context.Background(), strings.TrimSpace(cid))
55 55
 	c.Assert(err, checker.IsNil)
56
+	vname := container.Mounts[0].Name
56 57
 
57
-	v := volumes.Volumes[0]
58
-	err = cli.VolumeRemove(context.Background(), v.Name, false)
58
+	err = cli.VolumeRemove(context.Background(), vname, false)
59 59
 	c.Assert(err.Error(), checker.Contains, "volume is in use")
60 60
 
61 61
 	dockerCmd(c, "rm", "-f", "test")
62
-	err = cli.VolumeRemove(context.Background(), v.Name, false)
62
+	err = cli.VolumeRemove(context.Background(), vname, false)
63 63
 	c.Assert(err, checker.IsNil)
64 64
 }
65 65
 
... ...
@@ -78,10 +89,6 @@ func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) {
78 78
 	_, err = cli.VolumeCreate(context.Background(), config)
79 79
 	c.Assert(err, check.IsNil)
80 80
 
81
-	volumes, err := cli.VolumeList(context.Background(), filters.Args{})
82
-	c.Assert(err, checker.IsNil)
83
-	c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
84
-
85 81
 	vol, err := cli.VolumeInspect(context.Background(), config.Name)
86 82
 	c.Assert(err, checker.IsNil)
87 83
 	c.Assert(vol.Name, checker.Equals, config.Name)
... ...
@@ -231,6 +231,7 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
231 231
 }
232 232
 
233 233
 func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
234
+	existingContainers := ExistingContainerIDs(c)
234 235
 	// Test legacy no health check
235 236
 	out := runSleepingContainer(c, "--name=none_legacy")
236 237
 	containerID := strings.TrimSpace(out)
... ...
@@ -268,7 +269,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
268 268
 	waitForHealthStatus(c, "passing_container", "starting", "healthy")
269 269
 
270 270
 	out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy").Combined()
271
-	containerOut = strings.TrimSpace(out)
271
+	containerOut = strings.TrimSpace(RemoveOutputForExistingElements(out, existingContainers))
272 272
 	c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out))
273 273
 }
274 274
 
... ...
@@ -958,6 +959,7 @@ func (s *DockerSuite) TestPsFormatTemplateWithArg(c *check.C) {
958 958
 
959 959
 func (s *DockerSuite) TestPsListContainersFilterPorts(c *check.C) {
960 960
 	testRequires(c, DaemonIsLinux)
961
+	existingContainers := ExistingContainerIDs(c)
961 962
 
962 963
 	out, _ := dockerCmd(c, "run", "-d", "--publish=80", "busybox", "top")
963 964
 	id1 := strings.TrimSpace(out)
... ...
@@ -986,6 +988,7 @@ func (s *DockerSuite) TestPsListContainersFilterPorts(c *check.C) {
986 986
 	c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id2)
987 987
 
988 988
 	out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=8080/tcp")
989
+	out = RemoveOutputForExistingElements(out, existingContainers)
989 990
 	c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id1)
990 991
 	c.Assert(strings.TrimSpace(out), checker.Equals, id2)
991 992
 }
... ...
@@ -21,6 +21,7 @@ import (
21 21
 	"sync"
22 22
 	"time"
23 23
 
24
+	"github.com/docker/docker/client"
24 25
 	"github.com/docker/docker/integration-cli/checker"
25 26
 	"github.com/docker/docker/integration-cli/cli"
26 27
 	"github.com/docker/docker/integration-cli/cli/build"
... ...
@@ -35,6 +36,7 @@ import (
35 35
 	"github.com/go-check/check"
36 36
 	"github.com/gotestyourself/gotestyourself/icmd"
37 37
 	libcontainerUser "github.com/opencontainers/runc/libcontainer/user"
38
+	"golang.org/x/net/context"
38 39
 )
39 40
 
40 41
 // "test123" should be printed by docker run
... ...
@@ -3967,29 +3969,44 @@ func (s *DockerSuite) TestRunNamedVolumeNotRemoved(c *check.C) {
3967 3967
 	dockerCmd(c, "run", "--rm", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true")
3968 3968
 	dockerCmd(c, "volume", "inspect", "test")
3969 3969
 	out, _ := dockerCmd(c, "volume", "ls", "-q")
3970
-	c.Assert(strings.TrimSpace(out), checker.Equals, "test")
3970
+	c.Assert(strings.TrimSpace(out), checker.Contains, "test")
3971 3971
 
3972 3972
 	dockerCmd(c, "run", "--name=test", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true")
3973 3973
 	dockerCmd(c, "rm", "-fv", "test")
3974 3974
 	dockerCmd(c, "volume", "inspect", "test")
3975 3975
 	out, _ = dockerCmd(c, "volume", "ls", "-q")
3976
-	c.Assert(strings.TrimSpace(out), checker.Equals, "test")
3976
+	c.Assert(strings.TrimSpace(out), checker.Contains, "test")
3977 3977
 }
3978 3978
 
3979 3979
 func (s *DockerSuite) TestRunNamedVolumesFromNotRemoved(c *check.C) {
3980 3980
 	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
3981 3981
 
3982 3982
 	dockerCmd(c, "volume", "create", "test")
3983
-	dockerCmd(c, "run", "--name=parent", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true")
3983
+	cid, _ := dockerCmd(c, "run", "-d", "--name=parent", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true")
3984 3984
 	dockerCmd(c, "run", "--name=child", "--volumes-from=parent", "busybox", "true")
3985 3985
 
3986
+	cli, err := client.NewEnvClient()
3987
+	c.Assert(err, checker.IsNil)
3988
+	defer cli.Close()
3989
+
3990
+	container, err := cli.ContainerInspect(context.Background(), strings.TrimSpace(cid))
3991
+	c.Assert(err, checker.IsNil)
3992
+	var vname string
3993
+	for _, v := range container.Mounts {
3994
+		if v.Name != "test" {
3995
+			vname = v.Name
3996
+		}
3997
+	}
3998
+	c.Assert(vname, checker.Not(checker.Equals), "")
3999
+
3986 4000
 	// Remove the parent so there are not other references to the volumes
3987 4001
 	dockerCmd(c, "rm", "-f", "parent")
3988 4002
 	// now remove the child and ensure the named volume (and only the named volume) still exists
3989 4003
 	dockerCmd(c, "rm", "-fv", "child")
3990 4004
 	dockerCmd(c, "volume", "inspect", "test")
3991 4005
 	out, _ := dockerCmd(c, "volume", "ls", "-q")
3992
-	c.Assert(strings.TrimSpace(out), checker.Equals, "test")
4006
+	c.Assert(strings.TrimSpace(out), checker.Contains, "test")
4007
+	c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), vname)
3993 4008
 }
3994 4009
 
3995 4010
 func (s *DockerSuite) TestRunAttachFailedNoLeak(c *check.C) {
... ...
@@ -64,9 +64,6 @@ func (s *DockerSuite) TestVolumeCLIInspectMulti(c *check.C) {
64 64
 	})
65 65
 
66 66
 	out := result.Stdout()
67
-	outArr := strings.Split(strings.TrimSpace(out), "\n")
68
-	c.Assert(len(outArr), check.Equals, 3, check.Commentf("\n%s", out))
69
-
70 67
 	c.Assert(out, checker.Contains, "test1")
71 68
 	c.Assert(out, checker.Contains, "test2")
72 69
 	c.Assert(out, checker.Contains, "test3")
... ...
@@ -81,11 +78,8 @@ func (s *DockerSuite) TestVolumeCLILs(c *check.C) {
81 81
 	dockerCmd(c, "volume", "create", "soo")
82 82
 	dockerCmd(c, "run", "-v", "soo:"+prefix+"/foo", "busybox", "ls", "/")
83 83
 
84
-	out, _ := dockerCmd(c, "volume", "ls")
85
-	outArr := strings.Split(strings.TrimSpace(out), "\n")
86
-	c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out))
87
-
88
-	assertVolList(c, out, []string{"aaa", "soo", "test"})
84
+	out, _ := dockerCmd(c, "volume", "ls", "-q")
85
+	assertVolumesInList(c, out, []string{"aaa", "soo", "test"})
89 86
 }
90 87
 
91 88
 func (s *DockerSuite) TestVolumeLsFormat(c *check.C) {
... ...
@@ -94,12 +88,7 @@ func (s *DockerSuite) TestVolumeLsFormat(c *check.C) {
94 94
 	dockerCmd(c, "volume", "create", "soo")
95 95
 
96 96
 	out, _ := dockerCmd(c, "volume", "ls", "--format", "{{.Name}}")
97
-	lines := strings.Split(strings.TrimSpace(string(out)), "\n")
98
-
99
-	expected := []string{"aaa", "soo", "test"}
100
-	var names []string
101
-	names = append(names, lines...)
102
-	c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names))
97
+	assertVolumesInList(c, out, []string{"aaa", "soo", "test"})
103 98
 }
104 99
 
105 100
 func (s *DockerSuite) TestVolumeLsFormatDefaultFormat(c *check.C) {
... ...
@@ -118,12 +107,7 @@ func (s *DockerSuite) TestVolumeLsFormatDefaultFormat(c *check.C) {
118 118
 	c.Assert(err, checker.IsNil)
119 119
 
120 120
 	out, _ := dockerCmd(c, "--config", d, "volume", "ls")
121
-	lines := strings.Split(strings.TrimSpace(string(out)), "\n")
122
-
123
-	expected := []string{"aaa default", "soo default", "test default"}
124
-	var names []string
125
-	names = append(names, lines...)
126
-	c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names))
121
+	assertVolumesInList(c, out, []string{"aaa default", "soo default", "test default"})
127 122
 }
128 123
 
129 124
 // assertVolList checks volume retrieved with ls command
... ...
@@ -142,6 +126,20 @@ func assertVolList(c *check.C, out string, expectVols []string) {
142 142
 	c.Assert(volList, checker.DeepEquals, expectVols)
143 143
 }
144 144
 
145
+func assertVolumesInList(c *check.C, out string, expected []string) {
146
+	lines := strings.Split(strings.TrimSpace(string(out)), "\n")
147
+	for _, expect := range expected {
148
+		found := false
149
+		for _, v := range lines {
150
+			found = v == expect
151
+			if found {
152
+				break
153
+			}
154
+		}
155
+		c.Assert(found, checker.Equals, true, check.Commentf("Expected volume not found: %v, got: %v", expect, lines))
156
+	}
157
+}
158
+
145 159
 func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *check.C) {
146 160
 	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
147 161
 	dockerCmd(c, "volume", "create", "testnotinuse1")
... ...
@@ -213,10 +211,6 @@ func (s *DockerSuite) TestVolumeCLIRm(c *check.C) {
213 213
 	dockerCmd(c, "volume", "rm", id)
214 214
 	dockerCmd(c, "volume", "rm", "test")
215 215
 
216
-	out, _ = dockerCmd(c, "volume", "ls")
217
-	outArr := strings.Split(strings.TrimSpace(out), "\n")
218
-	c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
219
-
220 216
 	volumeID := "testing"
221 217
 	dockerCmd(c, "run", "-v", volumeID+":"+prefix+"/foo", "--name=test", "busybox", "sh", "-c", "echo hello > /foo/bar")
222 218
 
... ...
@@ -407,10 +401,6 @@ func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *check.C) {
407 407
 
408 408
 	dockerCmd(c, "volume", "rm", "-f", id)
409 409
 	dockerCmd(c, "volume", "rm", "--force", "nonexist")
410
-
411
-	out, _ = dockerCmd(c, "volume", "ls")
412
-	outArr := strings.Split(strings.TrimSpace(out), "\n")
413
-	c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
414 410
 }
415 411
 
416 412
 func (s *DockerSuite) TestVolumeCLIRmForce(c *check.C) {