From 8a2f96096aaaf91258da3a4d145095a6488a63a6 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 12 Jun 2019 16:00:07 -0400 Subject: [PATCH] For ipvlan tests check that the ipvlan module is enabled (instead of just ensuring the kernel version is greater than 4.2) Co-Authored-By: Jim Ehrismann Co-Authored-By: Sebastiaan van Stijn Signed-off-by: Jim Ehrismann (cherry picked from commit a77e147d322c153ae1c2ae0ee45c1835c109e231) Signed-off-by: Sebastiaan van Stijn --- integration/network/ipvlan/ipvlan_test.go | 29 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/integration/network/ipvlan/ipvlan_test.go b/integration/network/ipvlan/ipvlan_test.go index 9b98ace41d..e0b2b4eb83 100644 --- a/integration/network/ipvlan/ipvlan_test.go +++ b/integration/network/ipvlan/ipvlan_test.go @@ -4,7 +4,10 @@ package ipvlan import ( "context" + "os" + "os/exec" "strings" + "sync" "testing" "time" @@ -21,7 +24,7 @@ func TestDockerNetworkIpvlanPersistance(t *testing.T) { // verify the driver automatically provisions the 802.1q link (di-dummy0.70) skip.If(t, testEnv.DaemonInfo.OSType == "windows") skip.If(t, testEnv.IsRemoteDaemon) - skip.If(t, !ipvlanKernelSupport(), "Kernel doesn't support ipvlan") + skip.If(t, !ipvlanKernelSupport(t), "Kernel doesn't support ipvlan") d := daemon.New(t, daemon.WithExperimental) d.StartWithBusybox(t) @@ -49,7 +52,7 @@ func TestDockerNetworkIpvlanPersistance(t *testing.T) { func TestDockerNetworkIpvlan(t *testing.T) { skip.If(t, testEnv.DaemonInfo.OSType == "windows") skip.If(t, testEnv.IsRemoteDaemon) - skip.If(t, !ipvlanKernelSupport(), "Kernel doesn't support ipvlan") + skip.If(t, !ipvlanKernelSupport(t), "Kernel doesn't support ipvlan") for _, tc := range []struct { name string @@ -425,7 +428,23 @@ func testIpvlanAddressing(client dclient.APIClient) func(*testing.T) { } } -// ensure Kernel version is >= v4.2 for ipvlan support -func ipvlanKernelSupport() bool { - return n.CheckKernelMajorVersionGreaterOrEqualThen(4, 2) +var ( + once sync.Once + ipvlanSupported bool +) + +// figure out if ipvlan is supported by the kernel +func ipvlanKernelSupport(t *testing.T) bool { + once.Do(func() { + // this may have the side effect of enabling the ipvlan module + exec.Command("modprobe", "ipvlan").Run() + _, err := os.Stat("/sys/module/ipvlan") + if err == nil { + ipvlanSupported = true + } else if !os.IsNotExist(err) { + t.Logf("WARNING: ipvlanKernelSupport: stat failed: %v\n", err) + } + }) + + return ipvlanSupported }