Browse code

Move run tests out of unix files

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2015/09/02 01:42:19
Showing 2 changed files
... ...
@@ -2786,3 +2786,197 @@ func (s *DockerSuite) TestRunNamedVolume(c *check.C) {
2786 2786
 	out, _ = dockerCmd(c, "run", "-v", "testing:/foo", "busybox", "sh", "-c", "cat /foo/bar")
2787 2787
 	c.Assert(strings.TrimSpace(out), check.Equals, "hello")
2788 2788
 }
2789
+
2790
+func (s *DockerSuite) TestRunWithUlimits(c *check.C) {
2791
+	testRequires(c, NativeExecDriver)
2792
+
2793
+	out, _ := dockerCmd(c, "run", "--name=testulimits", "--ulimit", "nofile=42", "busybox", "/bin/sh", "-c", "ulimit -n")
2794
+	ul := strings.TrimSpace(out)
2795
+	if ul != "42" {
2796
+		c.Fatalf("expected `ulimit -n` to be 42, got %s", ul)
2797
+	}
2798
+}
2799
+
2800
+func (s *DockerSuite) TestRunContainerWithCgroupParent(c *check.C) {
2801
+	testRequires(c, NativeExecDriver)
2802
+
2803
+	cgroupParent := "test"
2804
+	name := "cgroup-test"
2805
+
2806
+	out, _, err := dockerCmdWithError("run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup")
2807
+	if err != nil {
2808
+		c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
2809
+	}
2810
+	cgroupPaths := parseCgroupPaths(string(out))
2811
+	if len(cgroupPaths) == 0 {
2812
+		c.Fatalf("unexpected output - %q", string(out))
2813
+	}
2814
+	id, err := getIDByName(name)
2815
+	c.Assert(err, check.IsNil)
2816
+	expectedCgroup := path.Join(cgroupParent, id)
2817
+	found := false
2818
+	for _, path := range cgroupPaths {
2819
+		if strings.HasSuffix(path, expectedCgroup) {
2820
+			found = true
2821
+			break
2822
+		}
2823
+	}
2824
+	if !found {
2825
+		c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths)
2826
+	}
2827
+}
2828
+
2829
+func (s *DockerSuite) TestRunContainerWithCgroupParentAbsPath(c *check.C) {
2830
+	testRequires(c, NativeExecDriver)
2831
+
2832
+	cgroupParent := "/cgroup-parent/test"
2833
+	name := "cgroup-test"
2834
+	out, _, err := dockerCmdWithError("run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup")
2835
+	if err != nil {
2836
+		c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
2837
+	}
2838
+	cgroupPaths := parseCgroupPaths(string(out))
2839
+	if len(cgroupPaths) == 0 {
2840
+		c.Fatalf("unexpected output - %q", string(out))
2841
+	}
2842
+	id, err := getIDByName(name)
2843
+	c.Assert(err, check.IsNil)
2844
+	expectedCgroup := path.Join(cgroupParent, id)
2845
+	found := false
2846
+	for _, path := range cgroupPaths {
2847
+		if strings.HasSuffix(path, expectedCgroup) {
2848
+			found = true
2849
+			break
2850
+		}
2851
+	}
2852
+	if !found {
2853
+		c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths)
2854
+	}
2855
+}
2856
+
2857
+func (s *DockerSuite) TestRunContainerWithCgroupMountRO(c *check.C) {
2858
+	testRequires(c, NativeExecDriver)
2859
+
2860
+	filename := "/sys/fs/cgroup/devices/test123"
2861
+	out, _, err := dockerCmdWithError("run", "busybox", "touch", filename)
2862
+	if err == nil {
2863
+		c.Fatal("expected cgroup mount point to be read-only, touch file should fail")
2864
+	}
2865
+	expected := "Read-only file system"
2866
+	if !strings.Contains(out, expected) {
2867
+		c.Fatalf("expected output from failure to contain %s but contains %s", expected, out)
2868
+	}
2869
+}
2870
+
2871
+func (s *DockerSuite) TestRunContainerNetworkModeToSelf(c *check.C) {
2872
+	out, _, err := dockerCmdWithError("run", "--name=me", "--net=container:me", "busybox", "true")
2873
+	if err == nil || !strings.Contains(out, "cannot join own network") {
2874
+		c.Fatalf("using container net mode to self should result in an error")
2875
+	}
2876
+}
2877
+
2878
+func (s *DockerSuite) TestRunContainerNetModeWithDnsMacHosts(c *check.C) {
2879
+	out, _, err := dockerCmdWithError("run", "-d", "--name", "parent", "busybox", "top")
2880
+	if err != nil {
2881
+		c.Fatalf("failed to run container: %v, output: %q", err, out)
2882
+	}
2883
+
2884
+	out, _, err = dockerCmdWithError("run", "--dns", "1.2.3.4", "--net=container:parent", "busybox")
2885
+	if err == nil || !strings.Contains(out, "Conflicting options: --dns and the network mode") {
2886
+		c.Fatalf("run --net=container with --dns should error out")
2887
+	}
2888
+
2889
+	out, _, err = dockerCmdWithError("run", "--mac-address", "92:d0:c6:0a:29:33", "--net=container:parent", "busybox")
2890
+	if err == nil || !strings.Contains(out, "--mac-address and the network mode") {
2891
+		c.Fatalf("run --net=container with --mac-address should error out")
2892
+	}
2893
+
2894
+	out, _, err = dockerCmdWithError("run", "--add-host", "test:192.168.2.109", "--net=container:parent", "busybox")
2895
+	if err == nil || !strings.Contains(out, "--add-host and the network mode") {
2896
+		c.Fatalf("run --net=container with --add-host should error out")
2897
+	}
2898
+}
2899
+
2900
+func (s *DockerSuite) TestRunContainerNetModeWithExposePort(c *check.C) {
2901
+	dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top")
2902
+
2903
+	out, _, err := dockerCmdWithError("run", "-p", "5000:5000", "--net=container:parent", "busybox")
2904
+	if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
2905
+		c.Fatalf("run --net=container with -p should error out")
2906
+	}
2907
+
2908
+	out, _, err = dockerCmdWithError("run", "-P", "--net=container:parent", "busybox")
2909
+	if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
2910
+		c.Fatalf("run --net=container with -P should error out")
2911
+	}
2912
+
2913
+	out, _, err = dockerCmdWithError("run", "--expose", "5000", "--net=container:parent", "busybox")
2914
+	if err == nil || !strings.Contains(out, "Conflicting options: --expose and the network mode (--expose)") {
2915
+		c.Fatalf("run --net=container with --expose should error out")
2916
+	}
2917
+}
2918
+
2919
+func (s *DockerSuite) TestRunLinkToContainerNetMode(c *check.C) {
2920
+	dockerCmd(c, "run", "--name", "test", "-d", "busybox", "top")
2921
+	dockerCmd(c, "run", "--name", "parent", "-d", "--net=container:test", "busybox", "top")
2922
+	dockerCmd(c, "run", "-d", "--link=parent:parent", "busybox", "top")
2923
+	dockerCmd(c, "run", "--name", "child", "-d", "--net=container:parent", "busybox", "top")
2924
+	dockerCmd(c, "run", "-d", "--link=child:child", "busybox", "top")
2925
+}
2926
+
2927
+func (s *DockerSuite) TestRunLoopbackOnlyExistsWhenNetworkingDisabled(c *check.C) {
2928
+	out, _ := dockerCmd(c, "run", "--net=none", "busybox", "ip", "-o", "-4", "a", "show", "up")
2929
+
2930
+	var (
2931
+		count = 0
2932
+		parts = strings.Split(out, "\n")
2933
+	)
2934
+
2935
+	for _, l := range parts {
2936
+		if l != "" {
2937
+			count++
2938
+		}
2939
+	}
2940
+
2941
+	if count != 1 {
2942
+		c.Fatalf("Wrong interface count in container %d", count)
2943
+	}
2944
+
2945
+	if !strings.HasPrefix(out, "1: lo") {
2946
+		c.Fatalf("Wrong interface in test container: expected [1: lo], got %s", out)
2947
+	}
2948
+}
2949
+
2950
+// Issue #4681
2951
+func (s *DockerSuite) TestRunLoopbackWhenNetworkDisabled(c *check.C) {
2952
+	dockerCmd(c, "run", "--net=none", "busybox", "ping", "-c", "1", "127.0.0.1")
2953
+}
2954
+
2955
+func (s *DockerSuite) TestRunModeNetContainerHostname(c *check.C) {
2956
+	testRequires(c, ExecSupport)
2957
+
2958
+	dockerCmd(c, "run", "-i", "-d", "--name", "parent", "busybox", "top")
2959
+	out, _ := dockerCmd(c, "exec", "parent", "cat", "/etc/hostname")
2960
+	out1, _ := dockerCmd(c, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname")
2961
+
2962
+	if out1 != out {
2963
+		c.Fatal("containers with shared net namespace should have same hostname")
2964
+	}
2965
+}
2966
+
2967
+func (s *DockerSuite) TestRunNetworkNotInitializedNoneMode(c *check.C) {
2968
+	out, _, err := dockerCmdWithError("run", "-d", "--net=none", "busybox", "top")
2969
+	id := strings.TrimSpace(out)
2970
+	res, err := inspectField(id, "NetworkSettings.IPAddress")
2971
+	c.Assert(err, check.IsNil)
2972
+	if res != "" {
2973
+		c.Fatalf("For 'none' mode network must not be initialized, but container got IP: %s", res)
2974
+	}
2975
+}
2976
+
2977
+func (s *DockerSuite) TestTwoContainersInNetHost(c *check.C) {
2978
+	dockerCmd(c, "run", "-d", "--net=host", "--name=first", "busybox", "top")
2979
+	dockerCmd(c, "run", "-d", "--net=host", "--name=second", "busybox", "top")
2980
+	dockerCmd(c, "stop", "first")
2981
+	dockerCmd(c, "stop", "second")
2982
+}
... ...
@@ -8,7 +8,6 @@ import (
8 8
 	"io/ioutil"
9 9
 	"os"
10 10
 	"os/exec"
11
-	"path"
12 11
 	"path/filepath"
13 12
 	"strings"
14 13
 	"time"
... ...
@@ -86,87 +85,6 @@ func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *check.C) {
86 86
 	}
87 87
 }
88 88
 
89
-func (s *DockerSuite) TestRunWithUlimits(c *check.C) {
90
-	testRequires(c, NativeExecDriver)
91
-
92
-	out, _ := dockerCmd(c, "run", "--name=testulimits", "--ulimit", "nofile=42", "busybox", "/bin/sh", "-c", "ulimit -n")
93
-	ul := strings.TrimSpace(out)
94
-	if ul != "42" {
95
-		c.Fatalf("expected `ulimit -n` to be 42, got %s", ul)
96
-	}
97
-}
98
-
99
-func (s *DockerSuite) TestRunContainerWithCgroupParent(c *check.C) {
100
-	testRequires(c, NativeExecDriver)
101
-
102
-	cgroupParent := "test"
103
-	name := "cgroup-test"
104
-
105
-	out, _, err := dockerCmdWithError("run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup")
106
-	if err != nil {
107
-		c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
108
-	}
109
-	cgroupPaths := parseCgroupPaths(string(out))
110
-	if len(cgroupPaths) == 0 {
111
-		c.Fatalf("unexpected output - %q", string(out))
112
-	}
113
-	id, err := getIDByName(name)
114
-	c.Assert(err, check.IsNil)
115
-	expectedCgroup := path.Join(cgroupParent, id)
116
-	found := false
117
-	for _, path := range cgroupPaths {
118
-		if strings.HasSuffix(path, expectedCgroup) {
119
-			found = true
120
-			break
121
-		}
122
-	}
123
-	if !found {
124
-		c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths)
125
-	}
126
-}
127
-
128
-func (s *DockerSuite) TestRunContainerWithCgroupParentAbsPath(c *check.C) {
129
-	testRequires(c, NativeExecDriver)
130
-
131
-	cgroupParent := "/cgroup-parent/test"
132
-	name := "cgroup-test"
133
-	out, _, err := dockerCmdWithError("run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup")
134
-	if err != nil {
135
-		c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
136
-	}
137
-	cgroupPaths := parseCgroupPaths(string(out))
138
-	if len(cgroupPaths) == 0 {
139
-		c.Fatalf("unexpected output - %q", string(out))
140
-	}
141
-	id, err := getIDByName(name)
142
-	c.Assert(err, check.IsNil)
143
-	expectedCgroup := path.Join(cgroupParent, id)
144
-	found := false
145
-	for _, path := range cgroupPaths {
146
-		if strings.HasSuffix(path, expectedCgroup) {
147
-			found = true
148
-			break
149
-		}
150
-	}
151
-	if !found {
152
-		c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths)
153
-	}
154
-}
155
-
156
-func (s *DockerSuite) TestRunContainerWithCgroupMountRO(c *check.C) {
157
-	testRequires(c, NativeExecDriver)
158
-
159
-	filename := "/sys/fs/cgroup/devices/test123"
160
-	out, _, err := dockerCmdWithError("run", "busybox", "touch", filename)
161
-	if err == nil {
162
-		c.Fatal("expected cgroup mount point to be read-only, touch file should fail")
163
-	}
164
-	expected := "Read-only file system"
165
-	if !strings.Contains(out, expected) {
166
-		c.Fatalf("expected output from failure to contain %s but contains %s", expected, out)
167
-	}
168
-}
169
-
170 89
 func (s *DockerSuite) TestRunDeviceDirectory(c *check.C) {
171 90
 	testRequires(c, NativeExecDriver)
172 91
 
... ...
@@ -366,119 +284,6 @@ func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
366 366
 	}
367 367
 }
368 368
 
369
-func (s *DockerSuite) TestContainerNetworkModeToSelf(c *check.C) {
370
-	out, _, err := dockerCmdWithError("run", "--name=me", "--net=container:me", "busybox", "true")
371
-	if err == nil || !strings.Contains(out, "cannot join own network") {
372
-		c.Fatalf("using container net mode to self should result in an error")
373
-	}
374
-}
375
-
376
-func (s *DockerSuite) TestRunContainerNetModeWithDnsMacHosts(c *check.C) {
377
-	out, _, err := dockerCmdWithError("run", "-d", "--name", "parent", "busybox", "top")
378
-	if err != nil {
379
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
380
-	}
381
-
382
-	out, _, err = dockerCmdWithError("run", "--dns", "1.2.3.4", "--net=container:parent", "busybox")
383
-	if err == nil || !strings.Contains(out, "Conflicting options: --dns and the network mode") {
384
-		c.Fatalf("run --net=container with --dns should error out")
385
-	}
386
-
387
-	out, _, err = dockerCmdWithError("run", "--mac-address", "92:d0:c6:0a:29:33", "--net=container:parent", "busybox")
388
-	if err == nil || !strings.Contains(out, "--mac-address and the network mode") {
389
-		c.Fatalf("run --net=container with --mac-address should error out")
390
-	}
391
-
392
-	out, _, err = dockerCmdWithError("run", "--add-host", "test:192.168.2.109", "--net=container:parent", "busybox")
393
-	if err == nil || !strings.Contains(out, "--add-host and the network mode") {
394
-		c.Fatalf("run --net=container with --add-host should error out")
395
-	}
396
-}
397
-
398
-func (s *DockerSuite) TestRunContainerNetModeWithExposePort(c *check.C) {
399
-	dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top")
400
-
401
-	out, _, err := dockerCmdWithError("run", "-p", "5000:5000", "--net=container:parent", "busybox")
402
-	if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
403
-		c.Fatalf("run --net=container with -p should error out")
404
-	}
405
-
406
-	out, _, err = dockerCmdWithError("run", "-P", "--net=container:parent", "busybox")
407
-	if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
408
-		c.Fatalf("run --net=container with -P should error out")
409
-	}
410
-
411
-	out, _, err = dockerCmdWithError("run", "--expose", "5000", "--net=container:parent", "busybox")
412
-	if err == nil || !strings.Contains(out, "Conflicting options: --expose and the network mode (--expose)") {
413
-		c.Fatalf("run --net=container with --expose should error out")
414
-	}
415
-}
416
-
417
-func (s *DockerSuite) TestRunLinkToContainerNetMode(c *check.C) {
418
-	dockerCmd(c, "run", "--name", "test", "-d", "busybox", "top")
419
-	dockerCmd(c, "run", "--name", "parent", "-d", "--net=container:test", "busybox", "top")
420
-	dockerCmd(c, "run", "-d", "--link=parent:parent", "busybox", "top")
421
-	dockerCmd(c, "run", "--name", "child", "-d", "--net=container:parent", "busybox", "top")
422
-	dockerCmd(c, "run", "-d", "--link=child:child", "busybox", "top")
423
-}
424
-
425
-func (s *DockerSuite) TestRunLoopbackOnlyExistsWhenNetworkingDisabled(c *check.C) {
426
-	out, _ := dockerCmd(c, "run", "--net=none", "busybox", "ip", "-o", "-4", "a", "show", "up")
427
-
428
-	var (
429
-		count = 0
430
-		parts = strings.Split(out, "\n")
431
-	)
432
-
433
-	for _, l := range parts {
434
-		if l != "" {
435
-			count++
436
-		}
437
-	}
438
-
439
-	if count != 1 {
440
-		c.Fatalf("Wrong interface count in container %d", count)
441
-	}
442
-
443
-	if !strings.HasPrefix(out, "1: lo") {
444
-		c.Fatalf("Wrong interface in test container: expected [1: lo], got %s", out)
445
-	}
446
-}
447
-
448
-// Issue #4681
449
-func (s *DockerSuite) TestRunLoopbackWhenNetworkDisabled(c *check.C) {
450
-	dockerCmd(c, "run", "--net=none", "busybox", "ping", "-c", "1", "127.0.0.1")
451
-}
452
-
453
-func (s *DockerSuite) TestRunModeNetContainerHostname(c *check.C) {
454
-	testRequires(c, ExecSupport)
455
-
456
-	dockerCmd(c, "run", "-i", "-d", "--name", "parent", "busybox", "top")
457
-	out, _ := dockerCmd(c, "exec", "parent", "cat", "/etc/hostname")
458
-	out1, _ := dockerCmd(c, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname")
459
-
460
-	if out1 != out {
461
-		c.Fatal("containers with shared net namespace should have same hostname")
462
-	}
463
-}
464
-
465
-func (s *DockerSuite) TestRunNetworkNotInitializedNoneMode(c *check.C) {
466
-	out, _, err := dockerCmdWithError("run", "-d", "--net=none", "busybox", "top")
467
-	id := strings.TrimSpace(out)
468
-	res, err := inspectField(id, "NetworkSettings.IPAddress")
469
-	c.Assert(err, check.IsNil)
470
-	if res != "" {
471
-		c.Fatalf("For 'none' mode network must not be initialized, but container got IP: %s", res)
472
-	}
473
-}
474
-
475
-func (s *DockerSuite) TestTwoContainersInNetHost(c *check.C) {
476
-	dockerCmd(c, "run", "-d", "--net=host", "--name=first", "busybox", "top")
477
-	dockerCmd(c, "run", "-d", "--net=host", "--name=second", "busybox", "top")
478
-	dockerCmd(c, "stop", "first")
479
-	dockerCmd(c, "stop", "second")
480
-}
481
-
482 369
 // "test" should be printed
483 370
 func (s *DockerSuite) TestRunEchoStdoutWithMemoryLimit(c *check.C) {
484 371
 	testRequires(c, memoryLimitSupport)