Co-Authored-By: Jim Ehrismann <jim-docker@users.noreply.github.com>
Co-Authored-By: Sebastiaan van Stijn <thaJeztah@users.noreply.github.com>
Signed-off-by: Jim Ehrismann <jim.ehrismann@docker.com>
| ... | ... |
@@ -4,7 +4,10 @@ package ipvlan |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 | 6 |
"context" |
| 7 |
+ "os" |
|
| 8 |
+ "os/exec" |
|
| 7 | 9 |
"strings" |
| 10 |
+ "sync" |
|
| 8 | 11 |
"testing" |
| 9 | 12 |
"time" |
| 10 | 13 |
|
| ... | ... |
@@ -21,7 +24,7 @@ func TestDockerNetworkIpvlanPersistance(t *testing.T) {
|
| 21 | 21 |
// verify the driver automatically provisions the 802.1q link (di-dummy0.70) |
| 22 | 22 |
skip.If(t, testEnv.DaemonInfo.OSType == "windows") |
| 23 | 23 |
skip.If(t, testEnv.IsRemoteDaemon) |
| 24 |
- skip.If(t, !ipvlanKernelSupport(), "Kernel doesn't support ipvlan") |
|
| 24 |
+ skip.If(t, !ipvlanKernelSupport(t), "Kernel doesn't support ipvlan") |
|
| 25 | 25 |
|
| 26 | 26 |
d := daemon.New(t, daemon.WithExperimental) |
| 27 | 27 |
d.StartWithBusybox(t) |
| ... | ... |
@@ -49,7 +52,7 @@ func TestDockerNetworkIpvlanPersistance(t *testing.T) {
|
| 49 | 49 |
func TestDockerNetworkIpvlan(t *testing.T) {
|
| 50 | 50 |
skip.If(t, testEnv.DaemonInfo.OSType == "windows") |
| 51 | 51 |
skip.If(t, testEnv.IsRemoteDaemon) |
| 52 |
- skip.If(t, !ipvlanKernelSupport(), "Kernel doesn't support ipvlan") |
|
| 52 |
+ skip.If(t, !ipvlanKernelSupport(t), "Kernel doesn't support ipvlan") |
|
| 53 | 53 |
|
| 54 | 54 |
for _, tc := range []struct {
|
| 55 | 55 |
name string |
| ... | ... |
@@ -425,7 +428,23 @@ func testIpvlanAddressing(client dclient.APIClient) func(*testing.T) {
|
| 425 | 425 |
} |
| 426 | 426 |
} |
| 427 | 427 |
|
| 428 |
-// ensure Kernel version is >= v4.2 for ipvlan support |
|
| 429 |
-func ipvlanKernelSupport() bool {
|
|
| 430 |
- return n.CheckKernelMajorVersionGreaterOrEqualThen(4, 2) |
|
| 428 |
+var ( |
|
| 429 |
+ once sync.Once |
|
| 430 |
+ ipvlanSupported bool |
|
| 431 |
+) |
|
| 432 |
+ |
|
| 433 |
+// figure out if ipvlan is supported by the kernel |
|
| 434 |
+func ipvlanKernelSupport(t *testing.T) bool {
|
|
| 435 |
+ once.Do(func() {
|
|
| 436 |
+ // this may have the side effect of enabling the ipvlan module |
|
| 437 |
+ exec.Command("modprobe", "ipvlan").Run()
|
|
| 438 |
+ _, err := os.Stat("/sys/module/ipvlan")
|
|
| 439 |
+ if err == nil {
|
|
| 440 |
+ ipvlanSupported = true |
|
| 441 |
+ } else if !os.IsNotExist(err) {
|
|
| 442 |
+ t.Logf("WARNING: ipvlanKernelSupport: stat failed: %v\n", err)
|
|
| 443 |
+ } |
|
| 444 |
+ }) |
|
| 445 |
+ |
|
| 446 |
+ return ipvlanSupported |
|
| 431 | 447 |
} |