This will help when extracting suites in their own package.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
... | ... |
@@ -1665,7 +1665,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *check.C) { |
1665 | 1665 |
}, |
1666 | 1666 |
} |
1667 | 1667 |
|
1668 |
- if SameHostDaemon.Condition() { |
|
1668 |
+ if SameHostDaemon() { |
|
1669 | 1669 |
tmpDir, err := ioutils.TempDir("", "test-mounts-api") |
1670 | 1670 |
c.Assert(err, checker.IsNil) |
1671 | 1671 |
defer os.RemoveAll(tmpDir) |
... | ... |
@@ -1696,7 +1696,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *check.C) { |
1696 | 1696 |
}...) |
1697 | 1697 |
} |
1698 | 1698 |
|
1699 |
- if DaemonIsLinux.Condition() { |
|
1699 |
+ if DaemonIsLinux() { |
|
1700 | 1700 |
cases = append(cases, []testCase{ |
1701 | 1701 |
{ |
1702 | 1702 |
config: cfg{ |
... | ... |
@@ -1823,7 +1823,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) { |
1823 | 1823 |
{mounttypes.Mount{Type: "volume", Target: destPath, Source: "test3", VolumeOptions: &mounttypes.VolumeOptions{DriverConfig: &mounttypes.Driver{Name: volume.DefaultDriverName}}}, types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", Name: "test3", RW: true, Destination: destPath}}, |
1824 | 1824 |
} |
1825 | 1825 |
|
1826 |
- if SameHostDaemon.Condition() { |
|
1826 |
+ if SameHostDaemon() { |
|
1827 | 1827 |
// setup temp dir for testing binds |
1828 | 1828 |
tmpDir1, err := ioutil.TempDir("", "test-mounts-api-1") |
1829 | 1829 |
c.Assert(err, checker.IsNil) |
... | ... |
@@ -1834,7 +1834,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) { |
1834 | 1834 |
}...) |
1835 | 1835 |
|
1836 | 1836 |
// for modes only supported on Linux |
1837 |
- if DaemonIsLinux.Condition() { |
|
1837 |
+ if DaemonIsLinux() { |
|
1838 | 1838 |
tmpDir3, err := ioutils.TempDir("", "test-mounts-api-3") |
1839 | 1839 |
c.Assert(err, checker.IsNil) |
1840 | 1840 |
defer os.RemoveAll(tmpDir3) |
... | ... |
@@ -289,7 +289,7 @@ func containerStartOutputEquals(c *check.C, containerID, contents string) (err e |
289 | 289 |
} |
290 | 290 |
|
291 | 291 |
func defaultVolumes(tmpDir string) []string { |
292 |
- if SameHostDaemon.Condition() { |
|
292 |
+ if SameHostDaemon() { |
|
293 | 293 |
return []string{ |
294 | 294 |
"/vol1", |
295 | 295 |
fmt.Sprintf("%s:/vol2", tmpDir), |
... | ... |
@@ -40,7 +40,7 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) { |
40 | 40 |
stringsToCheck = append(stringsToCheck, "Init Binary:", "Security Options:", "containerd version:", "runc version:", "init version:") |
41 | 41 |
} |
42 | 42 |
|
43 |
- if DaemonIsLinux.Condition() { |
|
43 |
+ if DaemonIsLinux() { |
|
44 | 44 |
stringsToCheck = append(stringsToCheck, "Runtimes:", "Default Runtime: runc") |
45 | 45 |
} |
46 | 46 |
|
... | ... |
@@ -749,7 +749,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) { |
749 | 749 |
// bind mount container |
750 | 750 |
var bindMountSource string |
751 | 751 |
var bindMountDestination string |
752 |
- if DaemonIsWindows.Condition() { |
|
752 |
+ if DaemonIsWindows() { |
|
753 | 753 |
bindMountSource = "c:\\" |
754 | 754 |
bindMountDestination = "c:\\t" |
755 | 755 |
} else { |
... | ... |
@@ -13,44 +13,37 @@ import ( |
13 | 13 |
"github.com/go-check/check" |
14 | 14 |
) |
15 | 15 |
|
16 |
-var ( |
|
17 |
- MacvlanKernelSupport = testRequirement{ |
|
18 |
- func() bool { |
|
19 |
- const macvlanKernelVer = 3 // minimum macvlan kernel support |
|
20 |
- const macvlanMajorVer = 9 // minimum macvlan major kernel support |
|
21 |
- kv, err := kernel.GetKernelVersion() |
|
22 |
- if err != nil { |
|
23 |
- return false |
|
24 |
- } |
|
25 |
- // ensure Kernel version is >= v3.9 for macvlan support |
|
26 |
- if kv.Kernel < macvlanKernelVer || (kv.Kernel == macvlanKernelVer && kv.Major < macvlanMajorVer) { |
|
27 |
- return false |
|
28 |
- } |
|
29 |
- return true |
|
30 |
- }, |
|
31 |
- "kernel version failed to meet the minimum macvlan kernel requirement of 3.9", |
|
16 |
+func macvlanKernelSupport() bool { |
|
17 |
+ const macvlanKernelVer = 3 // minimum macvlan kernel support |
|
18 |
+ const macvlanMajorVer = 9 // minimum macvlan major kernel support |
|
19 |
+ kv, err := kernel.GetKernelVersion() |
|
20 |
+ if err != nil { |
|
21 |
+ return false |
|
32 | 22 |
} |
33 |
- IpvlanKernelSupport = testRequirement{ |
|
34 |
- func() bool { |
|
35 |
- const ipvlanKernelVer = 4 // minimum ipvlan kernel support |
|
36 |
- const ipvlanMajorVer = 2 // minimum ipvlan major kernel support |
|
37 |
- kv, err := kernel.GetKernelVersion() |
|
38 |
- if err != nil { |
|
39 |
- return false |
|
40 |
- } |
|
41 |
- // ensure Kernel version is >= v4.2 for ipvlan support |
|
42 |
- if kv.Kernel < ipvlanKernelVer || (kv.Kernel == ipvlanKernelVer && kv.Major < ipvlanMajorVer) { |
|
43 |
- return false |
|
44 |
- } |
|
45 |
- return true |
|
46 |
- }, |
|
47 |
- "kernel version failed to meet the minimum ipvlan kernel requirement of 4.0.0", |
|
23 |
+ // ensure Kernel version is >= v3.9 for macvlan support |
|
24 |
+ if kv.Kernel < macvlanKernelVer || (kv.Kernel == macvlanKernelVer && kv.Major < macvlanMajorVer) { |
|
25 |
+ return false |
|
48 | 26 |
} |
49 |
-) |
|
27 |
+ return true |
|
28 |
+} |
|
29 |
+ |
|
30 |
+func ipvlanKernelSupport() bool { |
|
31 |
+ const ipvlanKernelVer = 4 // minimum ipvlan kernel support |
|
32 |
+ const ipvlanMajorVer = 2 // minimum ipvlan major kernel support |
|
33 |
+ kv, err := kernel.GetKernelVersion() |
|
34 |
+ if err != nil { |
|
35 |
+ return false |
|
36 |
+ } |
|
37 |
+ // ensure Kernel version is >= v4.2 for ipvlan support |
|
38 |
+ if kv.Kernel < ipvlanKernelVer || (kv.Kernel == ipvlanKernelVer && kv.Major < ipvlanMajorVer) { |
|
39 |
+ return false |
|
40 |
+ } |
|
41 |
+ return true |
|
42 |
+} |
|
50 | 43 |
|
51 | 44 |
func (s *DockerNetworkSuite) TestDockerNetworkMacvlanPersistance(c *check.C) { |
52 | 45 |
// verify the driver automatically provisions the 802.1q link (dm-dummy0.60) |
53 |
- testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
46 |
+ testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
54 | 47 |
|
55 | 48 |
// master dummy interface 'dm' abbreviation represents 'docker macvlan' |
56 | 49 |
master := "dm-dummy0" |
... | ... |
@@ -70,7 +63,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMacvlanPersistance(c *check.C) { |
70 | 70 |
|
71 | 71 |
func (s *DockerNetworkSuite) TestDockerNetworkIpvlanPersistance(c *check.C) { |
72 | 72 |
// verify the driver automatically provisions the 802.1q link (di-dummy0.70) |
73 |
- testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
73 |
+ testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
74 | 74 |
// master dummy interface 'di' notation represent 'docker ipvlan' |
75 | 75 |
master := "di-dummy0" |
76 | 76 |
// simulate the master link the vlan tagged subinterface parent link will use |
... | ... |
@@ -89,7 +82,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanPersistance(c *check.C) { |
89 | 89 |
|
90 | 90 |
func (s *DockerNetworkSuite) TestDockerNetworkMacvlanSubIntCreate(c *check.C) { |
91 | 91 |
// verify the driver automatically provisions the 802.1q link (dm-dummy0.50) |
92 |
- testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
92 |
+ testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
93 | 93 |
// master dummy interface 'dm' abbreviation represents 'docker macvlan' |
94 | 94 |
master := "dm-dummy0" |
95 | 95 |
// simulate the master link the vlan tagged subinterface parent link will use |
... | ... |
@@ -104,7 +97,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMacvlanSubIntCreate(c *check.C) { |
104 | 104 |
|
105 | 105 |
func (s *DockerNetworkSuite) TestDockerNetworkIpvlanSubIntCreate(c *check.C) { |
106 | 106 |
// verify the driver automatically provisions the 802.1q link (di-dummy0.50) |
107 |
- testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
107 |
+ testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
108 | 108 |
// master dummy interface 'dm' abbreviation represents 'docker ipvlan' |
109 | 109 |
master := "di-dummy0" |
110 | 110 |
// simulate the master link the vlan tagged subinterface parent link will use |
... | ... |
@@ -119,7 +112,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanSubIntCreate(c *check.C) { |
119 | 119 |
|
120 | 120 |
func (s *DockerNetworkSuite) TestDockerNetworkMacvlanOverlapParent(c *check.C) { |
121 | 121 |
// verify the same parent interface cannot be used if already in use by an existing network |
122 |
- testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
122 |
+ testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
123 | 123 |
// master dummy interface 'dm' abbreviation represents 'docker macvlan' |
124 | 124 |
master := "dm-dummy0" |
125 | 125 |
out, err := createMasterDummy(c, master) |
... | ... |
@@ -139,7 +132,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMacvlanOverlapParent(c *check.C) { |
139 | 139 |
|
140 | 140 |
func (s *DockerNetworkSuite) TestDockerNetworkIpvlanOverlapParent(c *check.C) { |
141 | 141 |
// verify the same parent interface cannot be used if already in use by an existing network |
142 |
- testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
142 |
+ testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
143 | 143 |
// master dummy interface 'dm' abbreviation represents 'docker ipvlan' |
144 | 144 |
master := "di-dummy0" |
145 | 145 |
out, err := createMasterDummy(c, master) |
... | ... |
@@ -159,7 +152,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanOverlapParent(c *check.C) { |
159 | 159 |
|
160 | 160 |
func (s *DockerNetworkSuite) TestDockerNetworkMacvlanMultiSubnet(c *check.C) { |
161 | 161 |
// create a dual stack multi-subnet Macvlan bridge mode network and validate connectivity between four containers, two on each subnet |
162 |
- testRequires(c, DaemonIsLinux, IPv6, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
162 |
+ testRequires(c, DaemonIsLinux, IPv6, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
163 | 163 |
dockerCmd(c, "network", "create", "--driver=macvlan", "--ipv6", "--subnet=172.28.100.0/24", "--subnet=172.28.102.0/24", "--gateway=172.28.102.254", |
164 | 164 |
"--subnet=2001:db8:abc2::/64", "--subnet=2001:db8:abc4::/64", "--gateway=2001:db8:abc4::254", "dualstackbridge") |
165 | 165 |
// Ensure the network was created |
... | ... |
@@ -214,7 +207,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMacvlanMultiSubnet(c *check.C) { |
214 | 214 |
|
215 | 215 |
func (s *DockerNetworkSuite) TestDockerNetworkIpvlanL2MultiSubnet(c *check.C) { |
216 | 216 |
// create a dual stack multi-subnet Ipvlan L2 network and validate connectivity within the subnets, two on each subnet |
217 |
- testRequires(c, DaemonIsLinux, IPv6, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
217 |
+ testRequires(c, DaemonIsLinux, IPv6, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
218 | 218 |
dockerCmd(c, "network", "create", "--driver=ipvlan", "--ipv6", "--subnet=172.28.200.0/24", "--subnet=172.28.202.0/24", "--gateway=172.28.202.254", |
219 | 219 |
"--subnet=2001:db8:abc8::/64", "--subnet=2001:db8:abc6::/64", "--gateway=2001:db8:abc6::254", "dualstackl2") |
220 | 220 |
// Ensure the network was created |
... | ... |
@@ -268,7 +261,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanL2MultiSubnet(c *check.C) { |
268 | 268 |
|
269 | 269 |
func (s *DockerNetworkSuite) TestDockerNetworkIpvlanL3MultiSubnet(c *check.C) { |
270 | 270 |
// create a dual stack multi-subnet Ipvlan L3 network and validate connectivity between all four containers per L3 mode |
271 |
- testRequires(c, DaemonIsLinux, IPv6, IpvlanKernelSupport, NotUserNamespace, NotArm, IPv6, ExperimentalDaemon) |
|
271 |
+ testRequires(c, DaemonIsLinux, IPv6, ipvlanKernelSupport, NotUserNamespace, NotArm, IPv6, ExperimentalDaemon) |
|
272 | 272 |
dockerCmd(c, "network", "create", "--driver=ipvlan", "--ipv6", "--subnet=172.28.10.0/24", "--subnet=172.28.12.0/24", "--gateway=172.28.12.254", |
273 | 273 |
"--subnet=2001:db8:abc9::/64", "--subnet=2001:db8:abc7::/64", "--gateway=2001:db8:abc7::254", "-o", "ipvlan_mode=l3", "dualstackl3") |
274 | 274 |
// Ensure the network was created |
... | ... |
@@ -327,7 +320,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanL3MultiSubnet(c *check.C) { |
327 | 327 |
|
328 | 328 |
func (s *DockerNetworkSuite) TestDockerNetworkIpvlanAddressing(c *check.C) { |
329 | 329 |
// Ensure the default gateways, next-hops and default dev devices are properly set |
330 |
- testRequires(c, DaemonIsLinux, IPv6, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
330 |
+ testRequires(c, DaemonIsLinux, IPv6, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
331 | 331 |
dockerCmd(c, "network", "create", "--driver=macvlan", "--ipv6", "--subnet=172.28.130.0/24", |
332 | 332 |
"--subnet=2001:db8:abca::/64", "--gateway=2001:db8:abca::254", "-o", "macvlan_mode=bridge", "dualstackbridge") |
333 | 333 |
assertNwIsAvailable(c, "dualstackbridge") |
... | ... |
@@ -373,7 +366,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanAddressing(c *check.C) { |
373 | 373 |
|
374 | 374 |
func (s *DockerSuite) TestDockerNetworkMacVlanBridgeNilParent(c *check.C) { |
375 | 375 |
// macvlan bridge mode - dummy parent interface is provisioned dynamically |
376 |
- testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
376 |
+ testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
377 | 377 |
dockerCmd(c, "network", "create", "--driver=macvlan", "dm-nil-parent") |
378 | 378 |
assertNwIsAvailable(c, "dm-nil-parent") |
379 | 379 |
|
... | ... |
@@ -390,7 +383,7 @@ func (s *DockerSuite) TestDockerNetworkMacVlanBridgeNilParent(c *check.C) { |
390 | 390 |
|
391 | 391 |
func (s *DockerSuite) TestDockerNetworkMacVlanBridgeInternalMode(c *check.C) { |
392 | 392 |
// macvlan bridge mode --internal containers can communicate inside the network but not externally |
393 |
- testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
393 |
+ testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
394 | 394 |
dockerCmd(c, "network", "create", "--driver=macvlan", "--internal", "dm-internal") |
395 | 395 |
assertNwIsAvailable(c, "dm-internal") |
396 | 396 |
nr := getNetworkResource(c, "dm-internal") |
... | ... |
@@ -413,7 +406,7 @@ func (s *DockerSuite) TestDockerNetworkMacVlanBridgeInternalMode(c *check.C) { |
413 | 413 |
|
414 | 414 |
func (s *DockerSuite) TestDockerNetworkIpvlanL2NilParent(c *check.C) { |
415 | 415 |
// ipvlan l2 mode - dummy parent interface is provisioned dynamically |
416 |
- testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
416 |
+ testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
417 | 417 |
dockerCmd(c, "network", "create", "--driver=ipvlan", "di-nil-parent") |
418 | 418 |
assertNwIsAvailable(c, "di-nil-parent") |
419 | 419 |
|
... | ... |
@@ -430,7 +423,7 @@ func (s *DockerSuite) TestDockerNetworkIpvlanL2NilParent(c *check.C) { |
430 | 430 |
|
431 | 431 |
func (s *DockerSuite) TestDockerNetworkIpvlanL2InternalMode(c *check.C) { |
432 | 432 |
// ipvlan l2 mode --internal containers can communicate inside the network but not externally |
433 |
- testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
433 |
+ testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
434 | 434 |
dockerCmd(c, "network", "create", "--driver=ipvlan", "--internal", "di-internal") |
435 | 435 |
assertNwIsAvailable(c, "di-internal") |
436 | 436 |
nr := getNetworkResource(c, "di-internal") |
... | ... |
@@ -452,7 +445,7 @@ func (s *DockerSuite) TestDockerNetworkIpvlanL2InternalMode(c *check.C) { |
452 | 452 |
|
453 | 453 |
func (s *DockerSuite) TestDockerNetworkIpvlanL3NilParent(c *check.C) { |
454 | 454 |
// ipvlan l3 mode - dummy parent interface is provisioned dynamically |
455 |
- testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
455 |
+ testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
456 | 456 |
dockerCmd(c, "network", "create", "--driver=ipvlan", "--subnet=172.28.230.0/24", |
457 | 457 |
"--subnet=172.28.220.0/24", "-o", "ipvlan_mode=l3", "di-nil-parent-l3") |
458 | 458 |
assertNwIsAvailable(c, "di-nil-parent-l3") |
... | ... |
@@ -470,7 +463,7 @@ func (s *DockerSuite) TestDockerNetworkIpvlanL3NilParent(c *check.C) { |
470 | 470 |
|
471 | 471 |
func (s *DockerSuite) TestDockerNetworkIpvlanL3InternalMode(c *check.C) { |
472 | 472 |
// ipvlan l3 mode --internal containers can communicate inside the network but not externally |
473 |
- testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
473 |
+ testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
474 | 474 |
dockerCmd(c, "network", "create", "--driver=ipvlan", "--subnet=172.28.230.0/24", |
475 | 475 |
"--subnet=172.28.220.0/24", "-o", "ipvlan_mode=l3", "--internal", "di-internal-l3") |
476 | 476 |
assertNwIsAvailable(c, "di-internal-l3") |
... | ... |
@@ -493,7 +486,7 @@ func (s *DockerSuite) TestDockerNetworkIpvlanL3InternalMode(c *check.C) { |
493 | 493 |
|
494 | 494 |
func (s *DockerSuite) TestDockerNetworkMacVlanExistingParent(c *check.C) { |
495 | 495 |
// macvlan bridge mode - empty parent interface containers can reach each other internally but not externally |
496 |
- testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
496 |
+ testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
497 | 497 |
netName := "dm-parent-exists" |
498 | 498 |
out, err := createMasterDummy(c, "dm-dummy0") |
499 | 499 |
//out, err := createVlanInterface(c, "dm-parent", "dm-slave", "macvlan", "bridge") |
... | ... |
@@ -513,7 +506,7 @@ func (s *DockerSuite) TestDockerNetworkMacVlanExistingParent(c *check.C) { |
513 | 513 |
|
514 | 514 |
func (s *DockerSuite) TestDockerNetworkMacVlanSubinterface(c *check.C) { |
515 | 515 |
// macvlan bridge mode - empty parent interface containers can reach each other internally but not externally |
516 |
- testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
516 |
+ testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
|
517 | 517 |
netName := "dm-subinterface" |
518 | 518 |
out, err := createMasterDummy(c, "dm-dummy0") |
519 | 519 |
c.Assert(err, check.IsNil, check.Commentf(out)) |
520 | 520 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,26 @@ |
0 |
+package requirement |
|
1 |
+ |
|
2 |
+import ( |
|
3 |
+ "fmt" |
|
4 |
+ "reflect" |
|
5 |
+ "runtime" |
|
6 |
+) |
|
7 |
+ |
|
8 |
+type skipT interface { |
|
9 |
+ Skip(reason string) |
|
10 |
+} |
|
11 |
+ |
|
12 |
+// Test represent a function that can be used as a requirement validation. |
|
13 |
+type Test func() bool |
|
14 |
+ |
|
15 |
+// Is checks if the environment satisfies the requirements |
|
16 |
+// for the test to run or skips the tests. |
|
17 |
+func Is(s skipT, requirements ...Test) { |
|
18 |
+ for _, r := range requirements { |
|
19 |
+ isValid := r() |
|
20 |
+ if !isValid { |
|
21 |
+ requirementFunc := runtime.FuncForPC(reflect.ValueOf(r).Pointer()).Name() |
|
22 |
+ s.Skip(fmt.Sprintf("unmatched requirement %s", requirementFunc)) |
|
23 |
+ } |
|
24 |
+ } |
|
25 |
+} |
0 | 26 |
deleted file mode 100644 |
... | ... |
@@ -1,237 +0,0 @@ |
1 |
-package main |
|
2 |
- |
|
3 |
-import ( |
|
4 |
- "fmt" |
|
5 |
- "io/ioutil" |
|
6 |
- "net/http" |
|
7 |
- "os" |
|
8 |
- "os/exec" |
|
9 |
- "strings" |
|
10 |
- "time" |
|
11 |
- |
|
12 |
- "github.com/go-check/check" |
|
13 |
-) |
|
14 |
- |
|
15 |
-type testCondition func() bool |
|
16 |
- |
|
17 |
-type testRequirement struct { |
|
18 |
- Condition testCondition |
|
19 |
- SkipMessage string |
|
20 |
-} |
|
21 |
- |
|
22 |
-// List test requirements |
|
23 |
-var ( |
|
24 |
- DaemonIsWindows = testRequirement{ |
|
25 |
- func() bool { return daemonPlatform == "windows" }, |
|
26 |
- "Test requires a Windows daemon", |
|
27 |
- } |
|
28 |
- DaemonIsLinux = testRequirement{ |
|
29 |
- func() bool { return daemonPlatform == "linux" }, |
|
30 |
- "Test requires a Linux daemon", |
|
31 |
- } |
|
32 |
- ExperimentalDaemon = testRequirement{ |
|
33 |
- func() bool { return experimentalDaemon }, |
|
34 |
- "Test requires an experimental daemon", |
|
35 |
- } |
|
36 |
- NotExperimentalDaemon = testRequirement{ |
|
37 |
- func() bool { return !experimentalDaemon }, |
|
38 |
- "Test requires a non experimental daemon", |
|
39 |
- } |
|
40 |
- IsAmd64 = testRequirement{ |
|
41 |
- func() bool { return os.Getenv("DOCKER_ENGINE_GOARCH") == "amd64" }, |
|
42 |
- "Test requires a daemon running on amd64", |
|
43 |
- } |
|
44 |
- NotArm = testRequirement{ |
|
45 |
- func() bool { return os.Getenv("DOCKER_ENGINE_GOARCH") != "arm" }, |
|
46 |
- "Test requires a daemon not running on ARM", |
|
47 |
- } |
|
48 |
- NotArm64 = testRequirement{ |
|
49 |
- func() bool { return os.Getenv("DOCKER_ENGINE_GOARCH") != "arm64" }, |
|
50 |
- "Test requires a daemon not running on arm64", |
|
51 |
- } |
|
52 |
- NotPpc64le = testRequirement{ |
|
53 |
- func() bool { return os.Getenv("DOCKER_ENGINE_GOARCH") != "ppc64le" }, |
|
54 |
- "Test requires a daemon not running on ppc64le", |
|
55 |
- } |
|
56 |
- NotS390X = testRequirement{ |
|
57 |
- func() bool { return os.Getenv("DOCKER_ENGINE_GOARCH") != "s390x" }, |
|
58 |
- "Test requires a daemon not running on s390x", |
|
59 |
- } |
|
60 |
- SameHostDaemon = testRequirement{ |
|
61 |
- func() bool { return isLocalDaemon }, |
|
62 |
- "Test requires docker daemon to run on the same machine as CLI", |
|
63 |
- } |
|
64 |
- UnixCli = testRequirement{ |
|
65 |
- func() bool { return isUnixCli }, |
|
66 |
- "Test requires posix utilities or functionality to run.", |
|
67 |
- } |
|
68 |
- ExecSupport = testRequirement{ |
|
69 |
- func() bool { return supportsExec }, |
|
70 |
- "Test requires 'docker exec' capabilities on the tested daemon.", |
|
71 |
- } |
|
72 |
- Network = testRequirement{ |
|
73 |
- func() bool { |
|
74 |
- // Set a timeout on the GET at 15s |
|
75 |
- var timeout = time.Duration(15 * time.Second) |
|
76 |
- var url = "https://hub.docker.com" |
|
77 |
- |
|
78 |
- client := http.Client{ |
|
79 |
- Timeout: timeout, |
|
80 |
- } |
|
81 |
- |
|
82 |
- resp, err := client.Get(url) |
|
83 |
- if err != nil && strings.Contains(err.Error(), "use of closed network connection") { |
|
84 |
- panic(fmt.Sprintf("Timeout for GET request on %s", url)) |
|
85 |
- } |
|
86 |
- if resp != nil { |
|
87 |
- resp.Body.Close() |
|
88 |
- } |
|
89 |
- return err == nil |
|
90 |
- }, |
|
91 |
- "Test requires network availability, environment variable set to none to run in a non-network enabled mode.", |
|
92 |
- } |
|
93 |
- Apparmor = testRequirement{ |
|
94 |
- func() bool { |
|
95 |
- buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled") |
|
96 |
- return err == nil && len(buf) > 1 && buf[0] == 'Y' |
|
97 |
- }, |
|
98 |
- "Test requires apparmor is enabled.", |
|
99 |
- } |
|
100 |
- RegistryHosting = testRequirement{ |
|
101 |
- func() bool { |
|
102 |
- // for now registry binary is built only if we're running inside |
|
103 |
- // container through `make test`. Figure that out by testing if |
|
104 |
- // registry binary is in PATH. |
|
105 |
- _, err := exec.LookPath(v2binary) |
|
106 |
- return err == nil |
|
107 |
- }, |
|
108 |
- fmt.Sprintf("Test requires an environment that can host %s in the same host", v2binary), |
|
109 |
- } |
|
110 |
- NotaryHosting = testRequirement{ |
|
111 |
- func() bool { |
|
112 |
- // for now notary binary is built only if we're running inside |
|
113 |
- // container through `make test`. Figure that out by testing if |
|
114 |
- // notary-server binary is in PATH. |
|
115 |
- _, err := exec.LookPath(notaryServerBinary) |
|
116 |
- return err == nil |
|
117 |
- }, |
|
118 |
- fmt.Sprintf("Test requires an environment that can host %s in the same host", notaryServerBinary), |
|
119 |
- } |
|
120 |
- NotaryServerHosting = testRequirement{ |
|
121 |
- func() bool { |
|
122 |
- // for now notary-server binary is built only if we're running inside |
|
123 |
- // container through `make test`. Figure that out by testing if |
|
124 |
- // notary-server binary is in PATH. |
|
125 |
- _, err := exec.LookPath(notaryServerBinary) |
|
126 |
- return err == nil |
|
127 |
- }, |
|
128 |
- fmt.Sprintf("Test requires an environment that can host %s in the same host", notaryServerBinary), |
|
129 |
- } |
|
130 |
- NotOverlay = testRequirement{ |
|
131 |
- func() bool { |
|
132 |
- return !strings.HasPrefix(daemonStorageDriver, "overlay") |
|
133 |
- }, |
|
134 |
- "Test requires underlying root filesystem not be backed by overlay.", |
|
135 |
- } |
|
136 |
- |
|
137 |
- Devicemapper = testRequirement{ |
|
138 |
- func() bool { |
|
139 |
- return strings.HasPrefix(daemonStorageDriver, "devicemapper") |
|
140 |
- }, |
|
141 |
- "Test requires underlying root filesystem to be backed by devicemapper.", |
|
142 |
- } |
|
143 |
- |
|
144 |
- IPv6 = testRequirement{ |
|
145 |
- func() bool { |
|
146 |
- cmd := exec.Command("test", "-f", "/proc/net/if_inet6") |
|
147 |
- |
|
148 |
- if err := cmd.Run(); err != nil { |
|
149 |
- return true |
|
150 |
- } |
|
151 |
- return false |
|
152 |
- }, |
|
153 |
- "Test requires support for IPv6", |
|
154 |
- } |
|
155 |
- UserNamespaceROMount = testRequirement{ |
|
156 |
- func() bool { |
|
157 |
- // quick case--userns not enabled in this test run |
|
158 |
- if os.Getenv("DOCKER_REMAP_ROOT") == "" { |
|
159 |
- return true |
|
160 |
- } |
|
161 |
- if _, _, err := dockerCmdWithError("run", "--rm", "--read-only", "busybox", "date"); err != nil { |
|
162 |
- return false |
|
163 |
- } |
|
164 |
- return true |
|
165 |
- }, |
|
166 |
- "Test cannot be run if user namespaces enabled but readonly mounts fail on this kernel.", |
|
167 |
- } |
|
168 |
- UserNamespaceInKernel = testRequirement{ |
|
169 |
- func() bool { |
|
170 |
- if _, err := os.Stat("/proc/self/uid_map"); os.IsNotExist(err) { |
|
171 |
- /* |
|
172 |
- * This kernel-provided file only exists if user namespaces are |
|
173 |
- * supported |
|
174 |
- */ |
|
175 |
- return false |
|
176 |
- } |
|
177 |
- |
|
178 |
- // We need extra check on redhat based distributions |
|
179 |
- if f, err := os.Open("/sys/module/user_namespace/parameters/enable"); err == nil { |
|
180 |
- defer f.Close() |
|
181 |
- b := make([]byte, 1) |
|
182 |
- _, _ = f.Read(b) |
|
183 |
- return string(b) != "N" |
|
184 |
- } |
|
185 |
- |
|
186 |
- return true |
|
187 |
- }, |
|
188 |
- "Kernel must have user namespaces configured and enabled.", |
|
189 |
- } |
|
190 |
- NotUserNamespace = testRequirement{ |
|
191 |
- func() bool { |
|
192 |
- root := os.Getenv("DOCKER_REMAP_ROOT") |
|
193 |
- return root == "" |
|
194 |
- }, |
|
195 |
- "Test cannot be run when remapping root", |
|
196 |
- } |
|
197 |
- IsPausable = testRequirement{ |
|
198 |
- func() bool { |
|
199 |
- if daemonPlatform == "windows" { |
|
200 |
- return isolation == "hyperv" |
|
201 |
- } |
|
202 |
- return true |
|
203 |
- }, |
|
204 |
- "Test requires containers are pausable.", |
|
205 |
- } |
|
206 |
- NotPausable = testRequirement{ |
|
207 |
- func() bool { |
|
208 |
- if daemonPlatform == "windows" { |
|
209 |
- return isolation == "process" |
|
210 |
- } |
|
211 |
- return false |
|
212 |
- }, |
|
213 |
- "Test requires containers are not pausable.", |
|
214 |
- } |
|
215 |
- IsolationIsHyperv = testRequirement{ |
|
216 |
- func() bool { |
|
217 |
- return daemonPlatform == "windows" && isolation == "hyperv" |
|
218 |
- }, |
|
219 |
- "Test requires a Windows daemon running default isolation mode of hyperv.", |
|
220 |
- } |
|
221 |
- IsolationIsProcess = testRequirement{ |
|
222 |
- func() bool { |
|
223 |
- return daemonPlatform == "windows" && isolation == "process" |
|
224 |
- }, |
|
225 |
- "Test requires a Windows daemon running default isolation mode of process.", |
|
226 |
- } |
|
227 |
-) |
|
228 |
- |
|
229 |
-// testRequires checks if the environment satisfies the requirements |
|
230 |
-// for the test to run or skips the tests. |
|
231 |
-func testRequires(c *check.C, requirements ...testRequirement) { |
|
232 |
- for _, r := range requirements { |
|
233 |
- if !r.Condition() { |
|
234 |
- c.Skip(r.SkipMessage) |
|
235 |
- } |
|
236 |
- } |
|
237 |
-} |
238 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,211 @@ |
0 |
+package main |
|
1 |
+ |
|
2 |
+import ( |
|
3 |
+ "fmt" |
|
4 |
+ "io/ioutil" |
|
5 |
+ "net/http" |
|
6 |
+ "os" |
|
7 |
+ "os/exec" |
|
8 |
+ "strings" |
|
9 |
+ "time" |
|
10 |
+ |
|
11 |
+ "github.com/docker/docker/integration-cli/requirement" |
|
12 |
+ "github.com/go-check/check" |
|
13 |
+) |
|
14 |
+ |
|
15 |
+func PlatformIs(platform string) bool { |
|
16 |
+ return daemonPlatform == platform |
|
17 |
+} |
|
18 |
+ |
|
19 |
+func ArchitectureIs(arch string) bool { |
|
20 |
+ return os.Getenv("DOCKER_ENGINE_GOARCH") == arch |
|
21 |
+} |
|
22 |
+ |
|
23 |
+func ArchitectureIsNot(arch string) bool { |
|
24 |
+ return os.Getenv("DOCKER_ENGINE_GOARCH") != arch |
|
25 |
+} |
|
26 |
+ |
|
27 |
+func StorageDriverIs(storageDriver string) bool { |
|
28 |
+ return strings.HasPrefix(daemonStorageDriver, storageDriver) |
|
29 |
+} |
|
30 |
+ |
|
31 |
+func StorageDriverIsNot(storageDriver string) bool { |
|
32 |
+ return !strings.HasPrefix(daemonStorageDriver, storageDriver) |
|
33 |
+} |
|
34 |
+ |
|
35 |
+func DaemonIsWindows() bool { |
|
36 |
+ return PlatformIs("windows") |
|
37 |
+} |
|
38 |
+ |
|
39 |
+func DaemonIsLinux() bool { |
|
40 |
+ return PlatformIs("linux") |
|
41 |
+} |
|
42 |
+ |
|
43 |
+func ExperimentalDaemon() bool { |
|
44 |
+ return experimentalDaemon |
|
45 |
+} |
|
46 |
+ |
|
47 |
+func NotExperimentalDaemon() bool { |
|
48 |
+ return !experimentalDaemon |
|
49 |
+} |
|
50 |
+ |
|
51 |
+func IsAmd64() bool { |
|
52 |
+ return ArchitectureIs("amd64") |
|
53 |
+} |
|
54 |
+ |
|
55 |
+func NotArm() bool { |
|
56 |
+ return ArchitectureIsNot("arm") |
|
57 |
+} |
|
58 |
+ |
|
59 |
+func NotArm64() bool { |
|
60 |
+ return ArchitectureIsNot("arm64") |
|
61 |
+} |
|
62 |
+ |
|
63 |
+func NotPpc64le() bool { |
|
64 |
+ return ArchitectureIsNot("ppc64le") |
|
65 |
+} |
|
66 |
+ |
|
67 |
+func NotS390X() bool { |
|
68 |
+ return ArchitectureIsNot("s390x") |
|
69 |
+} |
|
70 |
+ |
|
71 |
+func SameHostDaemon() bool { |
|
72 |
+ return isLocalDaemon |
|
73 |
+} |
|
74 |
+ |
|
75 |
+func UnixCli() bool { |
|
76 |
+ return isUnixCli |
|
77 |
+} |
|
78 |
+ |
|
79 |
+func ExecSupport() bool { |
|
80 |
+ return supportsExec |
|
81 |
+} |
|
82 |
+ |
|
83 |
+func Network() bool { |
|
84 |
+ // Set a timeout on the GET at 15s |
|
85 |
+ var timeout = time.Duration(15 * time.Second) |
|
86 |
+ var url = "https://hub.docker.com" |
|
87 |
+ |
|
88 |
+ client := http.Client{ |
|
89 |
+ Timeout: timeout, |
|
90 |
+ } |
|
91 |
+ |
|
92 |
+ resp, err := client.Get(url) |
|
93 |
+ if err != nil && strings.Contains(err.Error(), "use of closed network connection") { |
|
94 |
+ panic(fmt.Sprintf("Timeout for GET request on %s", url)) |
|
95 |
+ } |
|
96 |
+ if resp != nil { |
|
97 |
+ resp.Body.Close() |
|
98 |
+ } |
|
99 |
+ return err == nil |
|
100 |
+} |
|
101 |
+ |
|
102 |
+func Apparmor() bool { |
|
103 |
+ buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled") |
|
104 |
+ return err == nil && len(buf) > 1 && buf[0] == 'Y' |
|
105 |
+} |
|
106 |
+ |
|
107 |
+func RegistryHosting() bool { |
|
108 |
+ // for now registry binary is built only if we're running inside |
|
109 |
+ // container through `make test`. Figure that out by testing if |
|
110 |
+ // registry binary is in PATH. |
|
111 |
+ _, err := exec.LookPath(v2binary) |
|
112 |
+ return err == nil |
|
113 |
+} |
|
114 |
+ |
|
115 |
+func NotaryHosting() bool { |
|
116 |
+ // for now notary binary is built only if we're running inside |
|
117 |
+ // container through `make test`. Figure that out by testing if |
|
118 |
+ // notary-server binary is in PATH. |
|
119 |
+ _, err := exec.LookPath(notaryServerBinary) |
|
120 |
+ return err == nil |
|
121 |
+} |
|
122 |
+ |
|
123 |
+func NotaryServerHosting() bool { |
|
124 |
+ // for now notary-server binary is built only if we're running inside |
|
125 |
+ // container through `make test`. Figure that out by testing if |
|
126 |
+ // notary-server binary is in PATH. |
|
127 |
+ _, err := exec.LookPath(notaryServerBinary) |
|
128 |
+ return err == nil |
|
129 |
+} |
|
130 |
+ |
|
131 |
+func NotOverlay() bool { |
|
132 |
+ return StorageDriverIsNot("overlay") |
|
133 |
+} |
|
134 |
+ |
|
135 |
+func Devicemapper() bool { |
|
136 |
+ return StorageDriverIs("devicemapper") |
|
137 |
+} |
|
138 |
+ |
|
139 |
+func IPv6() bool { |
|
140 |
+ cmd := exec.Command("test", "-f", "/proc/net/if_inet6") |
|
141 |
+ return cmd.Run() != nil |
|
142 |
+} |
|
143 |
+ |
|
144 |
+func UserNamespaceROMount() bool { |
|
145 |
+ // quick case--userns not enabled in this test run |
|
146 |
+ if os.Getenv("DOCKER_REMAP_ROOT") == "" { |
|
147 |
+ return true |
|
148 |
+ } |
|
149 |
+ if _, _, err := dockerCmdWithError("run", "--rm", "--read-only", "busybox", "date"); err != nil { |
|
150 |
+ return false |
|
151 |
+ } |
|
152 |
+ return true |
|
153 |
+} |
|
154 |
+ |
|
155 |
+func NotUserNamespace() bool { |
|
156 |
+ root := os.Getenv("DOCKER_REMAP_ROOT") |
|
157 |
+ return root == "" |
|
158 |
+} |
|
159 |
+ |
|
160 |
+func UserNamespaceInKernel() bool { |
|
161 |
+ if _, err := os.Stat("/proc/self/uid_map"); os.IsNotExist(err) { |
|
162 |
+ /* |
|
163 |
+ * This kernel-provided file only exists if user namespaces are |
|
164 |
+ * supported |
|
165 |
+ */ |
|
166 |
+ return false |
|
167 |
+ } |
|
168 |
+ |
|
169 |
+ // We need extra check on redhat based distributions |
|
170 |
+ if f, err := os.Open("/sys/module/user_namespace/parameters/enable"); err == nil { |
|
171 |
+ defer f.Close() |
|
172 |
+ b := make([]byte, 1) |
|
173 |
+ _, _ = f.Read(b) |
|
174 |
+ return string(b) != "N" |
|
175 |
+ } |
|
176 |
+ |
|
177 |
+ return true |
|
178 |
+} |
|
179 |
+ |
|
180 |
+func IsPausable() bool { |
|
181 |
+ if daemonPlatform == "windows" { |
|
182 |
+ return isolation == "hyperv" |
|
183 |
+ } |
|
184 |
+ return true |
|
185 |
+} |
|
186 |
+ |
|
187 |
+func NotPausable() bool { |
|
188 |
+ if daemonPlatform == "windows" { |
|
189 |
+ return isolation == "process" |
|
190 |
+ } |
|
191 |
+ return false |
|
192 |
+} |
|
193 |
+ |
|
194 |
+func IsolationIs(expectedIsolation string) bool { |
|
195 |
+ return daemonPlatform == "windows" && string(isolation) == expectedIsolation |
|
196 |
+} |
|
197 |
+ |
|
198 |
+func IsolationIsHyperv() bool { |
|
199 |
+ return IsolationIs("hyperv") |
|
200 |
+} |
|
201 |
+ |
|
202 |
+func IsolationIsProcess() bool { |
|
203 |
+ return IsolationIs("process") |
|
204 |
+} |
|
205 |
+ |
|
206 |
+// testRequires checks if the environment satisfies the requirements |
|
207 |
+// for the test to run or skips the tests. |
|
208 |
+func testRequires(c *check.C, requirements ...requirement.Test) { |
|
209 |
+ requirement.Is(c, requirements...) |
|
210 |
+} |
0 | 211 |
deleted file mode 100644 |
... | ... |
@@ -1,159 +0,0 @@ |
1 |
-// +build !windows |
|
2 |
- |
|
3 |
-package main |
|
4 |
- |
|
5 |
-import ( |
|
6 |
- "bytes" |
|
7 |
- "io/ioutil" |
|
8 |
- "os/exec" |
|
9 |
- "strings" |
|
10 |
- |
|
11 |
- "github.com/docker/docker/pkg/parsers/kernel" |
|
12 |
- "github.com/docker/docker/pkg/sysinfo" |
|
13 |
-) |
|
14 |
- |
|
15 |
-var ( |
|
16 |
- // SysInfo stores information about which features a kernel supports. |
|
17 |
- SysInfo *sysinfo.SysInfo |
|
18 |
- cpuCfsPeriod = testRequirement{ |
|
19 |
- func() bool { |
|
20 |
- return SysInfo.CPUCfsPeriod |
|
21 |
- }, |
|
22 |
- "Test requires an environment that supports cgroup cfs period.", |
|
23 |
- } |
|
24 |
- cpuCfsQuota = testRequirement{ |
|
25 |
- func() bool { |
|
26 |
- return SysInfo.CPUCfsQuota |
|
27 |
- }, |
|
28 |
- "Test requires an environment that supports cgroup cfs quota.", |
|
29 |
- } |
|
30 |
- cpuShare = testRequirement{ |
|
31 |
- func() bool { |
|
32 |
- return SysInfo.CPUShares |
|
33 |
- }, |
|
34 |
- "Test requires an environment that supports cgroup cpu shares.", |
|
35 |
- } |
|
36 |
- oomControl = testRequirement{ |
|
37 |
- func() bool { |
|
38 |
- return SysInfo.OomKillDisable |
|
39 |
- }, |
|
40 |
- "Test requires Oom control enabled.", |
|
41 |
- } |
|
42 |
- pidsLimit = testRequirement{ |
|
43 |
- func() bool { |
|
44 |
- return SysInfo.PidsLimit |
|
45 |
- }, |
|
46 |
- "Test requires pids limit enabled.", |
|
47 |
- } |
|
48 |
- kernelMemorySupport = testRequirement{ |
|
49 |
- func() bool { |
|
50 |
- return SysInfo.KernelMemory |
|
51 |
- }, |
|
52 |
- "Test requires an environment that supports cgroup kernel memory.", |
|
53 |
- } |
|
54 |
- memoryLimitSupport = testRequirement{ |
|
55 |
- func() bool { |
|
56 |
- return SysInfo.MemoryLimit |
|
57 |
- }, |
|
58 |
- "Test requires an environment that supports cgroup memory limit.", |
|
59 |
- } |
|
60 |
- memoryReservationSupport = testRequirement{ |
|
61 |
- func() bool { |
|
62 |
- return SysInfo.MemoryReservation |
|
63 |
- }, |
|
64 |
- "Test requires an environment that supports cgroup memory reservation.", |
|
65 |
- } |
|
66 |
- swapMemorySupport = testRequirement{ |
|
67 |
- func() bool { |
|
68 |
- return SysInfo.SwapLimit |
|
69 |
- }, |
|
70 |
- "Test requires an environment that supports cgroup swap memory limit.", |
|
71 |
- } |
|
72 |
- memorySwappinessSupport = testRequirement{ |
|
73 |
- func() bool { |
|
74 |
- return SysInfo.MemorySwappiness |
|
75 |
- }, |
|
76 |
- "Test requires an environment that supports cgroup memory swappiness.", |
|
77 |
- } |
|
78 |
- blkioWeight = testRequirement{ |
|
79 |
- func() bool { |
|
80 |
- return SysInfo.BlkioWeight |
|
81 |
- }, |
|
82 |
- "Test requires an environment that supports blkio weight.", |
|
83 |
- } |
|
84 |
- cgroupCpuset = testRequirement{ |
|
85 |
- func() bool { |
|
86 |
- return SysInfo.Cpuset |
|
87 |
- }, |
|
88 |
- "Test requires an environment that supports cgroup cpuset.", |
|
89 |
- } |
|
90 |
- seccompEnabled = testRequirement{ |
|
91 |
- func() bool { |
|
92 |
- return supportsSeccomp && SysInfo.Seccomp |
|
93 |
- }, |
|
94 |
- "Test requires that seccomp support be enabled in the daemon.", |
|
95 |
- } |
|
96 |
- bridgeNfIptables = testRequirement{ |
|
97 |
- func() bool { |
|
98 |
- return !SysInfo.BridgeNFCallIPTablesDisabled |
|
99 |
- }, |
|
100 |
- "Test requires that bridge-nf-call-iptables support be enabled in the daemon.", |
|
101 |
- } |
|
102 |
- bridgeNfIP6tables = testRequirement{ |
|
103 |
- func() bool { |
|
104 |
- return !SysInfo.BridgeNFCallIP6TablesDisabled |
|
105 |
- }, |
|
106 |
- "Test requires that bridge-nf-call-ip6tables support be enabled in the daemon.", |
|
107 |
- } |
|
108 |
- unprivilegedUsernsClone = testRequirement{ |
|
109 |
- func() bool { |
|
110 |
- content, err := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone") |
|
111 |
- if err == nil && strings.Contains(string(content), "0") { |
|
112 |
- return false |
|
113 |
- } |
|
114 |
- return true |
|
115 |
- }, |
|
116 |
- "Test cannot be run with 'sysctl kernel.unprivileged_userns_clone' = 0", |
|
117 |
- } |
|
118 |
- ambientCapabilities = testRequirement{ |
|
119 |
- func() bool { |
|
120 |
- content, err := ioutil.ReadFile("/proc/self/status") |
|
121 |
- if err == nil && strings.Contains(string(content), "CapAmb:") { |
|
122 |
- return true |
|
123 |
- } |
|
124 |
- return false |
|
125 |
- }, |
|
126 |
- "Test cannot be run without a kernel (4.3+) supporting ambient capabilities", |
|
127 |
- } |
|
128 |
- overlayFSSupported = testRequirement{ |
|
129 |
- func() bool { |
|
130 |
- cmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "/bin/sh", "-c", "cat /proc/filesystems") |
|
131 |
- out, err := cmd.CombinedOutput() |
|
132 |
- if err != nil { |
|
133 |
- return false |
|
134 |
- } |
|
135 |
- return bytes.Contains(out, []byte("overlay\n")) |
|
136 |
- }, |
|
137 |
- "Test cannot be run without suppport for overlayfs", |
|
138 |
- } |
|
139 |
- overlay2Supported = testRequirement{ |
|
140 |
- func() bool { |
|
141 |
- if !overlayFSSupported.Condition() { |
|
142 |
- return false |
|
143 |
- } |
|
144 |
- |
|
145 |
- daemonV, err := kernel.ParseRelease(daemonKernelVersion) |
|
146 |
- if err != nil { |
|
147 |
- return false |
|
148 |
- } |
|
149 |
- requiredV := kernel.VersionInfo{Kernel: 4} |
|
150 |
- return kernel.CompareKernelVersion(*daemonV, requiredV) > -1 |
|
151 |
- |
|
152 |
- }, |
|
153 |
- "Test cannot be run without overlay2 support (kernel 4.0+)", |
|
154 |
- } |
|
155 |
-) |
|
156 |
- |
|
157 |
-func init() { |
|
158 |
- SysInfo = sysinfo.New(true) |
|
159 |
-} |
160 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,115 @@ |
0 |
+// +build !windows |
|
1 |
+ |
|
2 |
+package main |
|
3 |
+ |
|
4 |
+import ( |
|
5 |
+ "bytes" |
|
6 |
+ "io/ioutil" |
|
7 |
+ "os/exec" |
|
8 |
+ "strings" |
|
9 |
+ |
|
10 |
+ "github.com/docker/docker/pkg/parsers/kernel" |
|
11 |
+ "github.com/docker/docker/pkg/sysinfo" |
|
12 |
+) |
|
13 |
+ |
|
14 |
+var ( |
|
15 |
+ // SysInfo stores information about which features a kernel supports. |
|
16 |
+ SysInfo *sysinfo.SysInfo |
|
17 |
+) |
|
18 |
+ |
|
19 |
+func cpuCfsPeriod() bool { |
|
20 |
+ return SysInfo.CPUCfsPeriod |
|
21 |
+} |
|
22 |
+ |
|
23 |
+func cpuCfsQuota() bool { |
|
24 |
+ return SysInfo.CPUCfsQuota |
|
25 |
+} |
|
26 |
+ |
|
27 |
+func cpuShare() bool { |
|
28 |
+ return SysInfo.CPUShares |
|
29 |
+} |
|
30 |
+ |
|
31 |
+func oomControl() bool { |
|
32 |
+ return SysInfo.OomKillDisable |
|
33 |
+} |
|
34 |
+ |
|
35 |
+func pidsLimit() bool { |
|
36 |
+ return SysInfo.PidsLimit |
|
37 |
+} |
|
38 |
+ |
|
39 |
+func kernelMemorySupport() bool { |
|
40 |
+ return SysInfo.KernelMemory |
|
41 |
+} |
|
42 |
+ |
|
43 |
+func memoryLimitSupport() bool { |
|
44 |
+ return SysInfo.MemoryLimit |
|
45 |
+} |
|
46 |
+ |
|
47 |
+func memoryReservationSupport() bool { |
|
48 |
+ return SysInfo.MemoryReservation |
|
49 |
+} |
|
50 |
+ |
|
51 |
+func swapMemorySupport() bool { |
|
52 |
+ return SysInfo.SwapLimit |
|
53 |
+} |
|
54 |
+ |
|
55 |
+func memorySwappinessSupport() bool { |
|
56 |
+ return SysInfo.MemorySwappiness |
|
57 |
+} |
|
58 |
+ |
|
59 |
+func blkioWeight() bool { |
|
60 |
+ return SysInfo.BlkioWeight |
|
61 |
+} |
|
62 |
+ |
|
63 |
+func cgroupCpuset() bool { |
|
64 |
+ return SysInfo.Cpuset |
|
65 |
+} |
|
66 |
+ |
|
67 |
+func seccompEnabled() bool { |
|
68 |
+ return supportsSeccomp && SysInfo.Seccomp |
|
69 |
+} |
|
70 |
+ |
|
71 |
+func bridgeNfIptables() bool { |
|
72 |
+ return !SysInfo.BridgeNFCallIPTablesDisabled |
|
73 |
+} |
|
74 |
+ |
|
75 |
+func bridgeNfIP6tables() bool { |
|
76 |
+ return !SysInfo.BridgeNFCallIP6TablesDisabled |
|
77 |
+} |
|
78 |
+ |
|
79 |
+func unprivilegedUsernsClone() bool { |
|
80 |
+ content, err := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone") |
|
81 |
+ return err != nil || !strings.Contains(string(content), "0") |
|
82 |
+} |
|
83 |
+ |
|
84 |
+func ambientCapabilities() bool { |
|
85 |
+ content, err := ioutil.ReadFile("/proc/self/status") |
|
86 |
+ return err != nil || strings.Contains(string(content), "CapAmb:") |
|
87 |
+} |
|
88 |
+ |
|
89 |
+func overlayFSSupported() bool { |
|
90 |
+ cmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "/bin/sh", "-c", "cat /proc/filesystems") |
|
91 |
+ out, err := cmd.CombinedOutput() |
|
92 |
+ if err != nil { |
|
93 |
+ return false |
|
94 |
+ } |
|
95 |
+ return bytes.Contains(out, []byte("overlay\n")) |
|
96 |
+} |
|
97 |
+ |
|
98 |
+func overlay2Supported() bool { |
|
99 |
+ if !overlayFSSupported() { |
|
100 |
+ return false |
|
101 |
+ } |
|
102 |
+ |
|
103 |
+ daemonV, err := kernel.ParseRelease(daemonKernelVersion) |
|
104 |
+ if err != nil { |
|
105 |
+ return false |
|
106 |
+ } |
|
107 |
+ requiredV := kernel.VersionInfo{Kernel: 4} |
|
108 |
+ return kernel.CompareKernelVersion(*daemonV, requiredV) > -1 |
|
109 |
+ |
|
110 |
+} |
|
111 |
+ |
|
112 |
+func init() { |
|
113 |
+ SysInfo = sysinfo.New(true) |
|
114 |
+} |