From c721bad8ccddeb353e71d4b4b26ad878d1ae8bee Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Mon, 15 Nov 2021 00:34:40 +0100 Subject: [PATCH] Fix flaky TestPortMappingV6Config Since moby/libnetwork#2635 has been merged, allocatePortsInternal() checks if IPv6 is enabled by calling IsV6Listenable(). This function calls `net.Listen("tcp6", "[::1]:0")` and returns false when net.Listen() fails. TestPortMappingV6Config() starts by setting up a new net ns to run into it. The loopback interface is not bring up in this net ns, thus net.Listen() fails and IsV6Listenable() returns false. This change takes care of bringing loopback iface up right after moving to the new net ns. This test has been reported has flaky on s390x in #42468. For some reason, this test seems to be consistently green on the CI (on amd64 arch) and when running `hack/test/unit` locally. However it consistently fails when running `TESTFLAGS='-shuffle on' hack/test/unit` locally. Signed-off-by: Albin Kerouanton --- libnetwork/drivers/bridge/port_mapping_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libnetwork/drivers/bridge/port_mapping_test.go b/libnetwork/drivers/bridge/port_mapping_test.go index c5402cf13d04a..dab375e96b96a 100644 --- a/libnetwork/drivers/bridge/port_mapping_test.go +++ b/libnetwork/drivers/bridge/port_mapping_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/docker/docker/libnetwork/netlabel" + "github.com/docker/docker/libnetwork/ns" "github.com/docker/docker/libnetwork/testutils" "github.com/docker/docker/libnetwork/types" "github.com/docker/docker/pkg/reexec" @@ -101,6 +102,10 @@ func TestPortMappingConfig(t *testing.T) { func TestPortMappingV6Config(t *testing.T) { defer testutils.SetupTestOSContext(t)() + if err := loopbackUp(); err != nil { + t.Fatalf("Could not bring loopback iface up: %v", err) + } + d := newDriver() config := &configuration{ @@ -169,3 +174,12 @@ func TestPortMappingV6Config(t *testing.T) { t.Fatal(err) } } + +func loopbackUp() error { + nlHandle := ns.NlHandle() + iface, err := nlHandle.LinkByName("lo") + if err != nil { + return err + } + return nlHandle.LinkSetUp(iface) +}