Browse Source

libnetwork_test: remove in-container special case

The SetupTestOSContext calls were made conditional in
https://github.com/moby/libnetwork/pull/148 to work around limitations
in runtime.LockOSThread() which existed before Go 1.10. This workaround
is no longer necessary now that runtime.UnlockOSThread() needs to be
called an equal number of times before the goroutine is unlocked from
the OS thread.

Unfortunately some tests break when SetupTestOSContext is not skipped.
(Evidently this code path has not been exercised in a long time.) A
newly-created network namespace is very barebones: it contains a
loopback interface in the down state and little else. Even pinging
localhost does not work inside of a brand new namespace. Set the
loopback interface to up during namespace setup so that tests which
need to use the loopback interface can do so.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider 2 years ago
parent
commit
07be7b087d

+ 11 - 33
libnetwork/drivers/bridge/bridge_test.go

@@ -180,9 +180,7 @@ func getIPv4Data(t *testing.T, iface string) []driverapi.IPAMData {
 }
 }
 
 
 func TestCreateFullOptions(t *testing.T) {
 func TestCreateFullOptions(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 	d := newDriver()
 	d := newDriver()
 
 
 	config := &configuration{
 	config := &configuration{
@@ -236,9 +234,7 @@ func TestCreateFullOptions(t *testing.T) {
 }
 }
 
 
 func TestCreateNoConfig(t *testing.T) {
 func TestCreateNoConfig(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 	d := newDriver()
 	d := newDriver()
 
 
 	netconfig := &networkConfiguration{BridgeName: DefaultBridgeName}
 	netconfig := &networkConfiguration{BridgeName: DefaultBridgeName}
@@ -251,9 +247,7 @@ func TestCreateNoConfig(t *testing.T) {
 }
 }
 
 
 func TestCreateFullOptionsLabels(t *testing.T) {
 func TestCreateFullOptionsLabels(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 	d := newDriver()
 	d := newDriver()
 
 
 	config := &configuration{
 	config := &configuration{
@@ -359,9 +353,7 @@ func TestCreateFullOptionsLabels(t *testing.T) {
 }
 }
 
 
 func TestCreate(t *testing.T) {
 func TestCreate(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	d := newDriver()
 	d := newDriver()
 
 
@@ -387,9 +379,7 @@ func TestCreate(t *testing.T) {
 }
 }
 
 
 func TestCreateFail(t *testing.T) {
 func TestCreateFail(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	d := newDriver()
 	d := newDriver()
 
 
@@ -407,9 +397,7 @@ func TestCreateFail(t *testing.T) {
 }
 }
 
 
 func TestCreateMultipleNetworks(t *testing.T) {
 func TestCreateMultipleNetworks(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	d := newDriver()
 	d := newDriver()
 
 
@@ -617,9 +605,7 @@ func TestQueryEndpointInfoHairpin(t *testing.T) {
 }
 }
 
 
 func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) {
 func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 	d := newDriver()
 	d := newDriver()
 
 
 	config := &configuration{
 	config := &configuration{
@@ -720,9 +706,7 @@ func getPortMapping() []types.PortBinding {
 }
 }
 
 
 func TestLinkContainers(t *testing.T) {
 func TestLinkContainers(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	d := newDriver()
 	d := newDriver()
 	iptable := iptables.GetIptable(iptables.IPv4)
 	iptable := iptables.GetIptable(iptables.IPv4)
@@ -876,9 +860,7 @@ func TestLinkContainers(t *testing.T) {
 }
 }
 
 
 func TestValidateConfig(t *testing.T) {
 func TestValidateConfig(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	// Test mtu
 	// Test mtu
 	c := networkConfiguration{Mtu: -2}
 	c := networkConfiguration{Mtu: -2}
@@ -949,9 +931,7 @@ func TestValidateConfig(t *testing.T) {
 }
 }
 
 
 func TestSetDefaultGw(t *testing.T) {
 func TestSetDefaultGw(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	d := newDriver()
 	d := newDriver()
 
 
@@ -1095,9 +1075,7 @@ func TestCreateWithExistingBridge(t *testing.T) {
 }
 }
 
 
 func TestCreateParallel(t *testing.T) {
 func TestCreateParallel(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	d := newDriver()
 	d := newDriver()
 
 

+ 1 - 3
libnetwork/endpoint_test.go

@@ -13,9 +13,7 @@ import (
 )
 )
 
 
 func TestHostsEntries(t *testing.T) {
 func TestHostsEntries(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	expectedHostsFile := `127.0.0.1	localhost
 	expectedHostsFile := `127.0.0.1	localhost
 ::1	localhost ip6-localhost ip6-loopback
 ::1	localhost ip6-localhost ip6-loopback

+ 1 - 3
libnetwork/libnetwork_internal_test.go

@@ -562,9 +562,7 @@ func TestServiceVIPReuse(t *testing.T) {
 func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
 func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
 	skip.If(t, runtime.GOOS == "windows", "test only works on linux")
 	skip.If(t, runtime.GOOS == "windows", "test only works on linux")
 
 
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	cfgOptions, err := OptionBoltdbWithRandomDBFile()
 	cfgOptions, err := OptionBoltdbWithRandomDBFile()
 	if err != nil {
 	if err != nil {

+ 10 - 28
libnetwork/libnetwork_linux_test.go

@@ -62,13 +62,9 @@ func createGlobalInstance(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if testutils.IsRunningInContainer() {
-		testns = origins
-	} else {
-		testns, err = netns.New()
-		if err != nil {
-			t.Fatal(err)
-		}
+	testns, err = netns.New()
+	if err != nil {
+		t.Fatal(err)
 	}
 	}
 
 
 	netOption := options.Generic{
 	netOption := options.Generic{
@@ -207,9 +203,7 @@ func TestHost(t *testing.T) {
 
 
 // Testing IPV6 from MAC address
 // Testing IPV6 from MAC address
 func TestBridgeIpv6FromMac(t *testing.T) {
 func TestBridgeIpv6FromMac(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	netOption := options.Generic{
 	netOption := options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{
@@ -283,9 +277,7 @@ func checkSandbox(t *testing.T, info libnetwork.EndpointInfo) {
 }
 }
 
 
 func TestEndpointJoin(t *testing.T) {
 func TestEndpointJoin(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	// Create network 1 and add 2 endpoint: ep11, ep12
 	// Create network 1 and add 2 endpoint: ep11, ep12
 	netOption := options.Generic{
 	netOption := options.Generic{
@@ -459,9 +451,7 @@ func TestExternalKey(t *testing.T) {
 }
 }
 
 
 func externalKeyTest(t *testing.T, reexec bool) {
 func externalKeyTest(t *testing.T, reexec bool) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
 	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{
@@ -621,9 +611,7 @@ func reexecSetKey(key string, containerID string, controllerID string) error {
 }
 }
 
 
 func TestEnableIPv6(t *testing.T) {
 func TestEnableIPv6(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	tmpResolvConf := []byte("search pommesfrites.fr\nnameserver 12.34.56.78\nnameserver 2001:4860:4860::8888\n")
 	tmpResolvConf := []byte("search pommesfrites.fr\nnameserver 12.34.56.78\nnameserver 2001:4860:4860::8888\n")
 	expectedResolvConf := []byte("search pommesfrites.fr\nnameserver 127.0.0.11\nnameserver 2001:4860:4860::8888\noptions ndots:0\n")
 	expectedResolvConf := []byte("search pommesfrites.fr\nnameserver 127.0.0.11\nnameserver 2001:4860:4860::8888\noptions ndots:0\n")
@@ -699,9 +687,7 @@ func TestEnableIPv6(t *testing.T) {
 }
 }
 
 
 func TestResolvConfHost(t *testing.T) {
 func TestResolvConfHost(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	tmpResolvConf := []byte("search localhost.net\nnameserver 127.0.0.1\nnameserver 2001:4860:4860::8888\n")
 	tmpResolvConf := []byte("search localhost.net\nnameserver 127.0.0.1\nnameserver 2001:4860:4860::8888\n")
 
 
@@ -775,9 +761,7 @@ func TestResolvConfHost(t *testing.T) {
 }
 }
 
 
 func TestResolvConf(t *testing.T) {
 func TestResolvConf(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	tmpResolvConf1 := []byte("search pommesfrites.fr\nnameserver 12.34.56.78\nnameserver 2001:4860:4860::8888\n")
 	tmpResolvConf1 := []byte("search pommesfrites.fr\nnameserver 12.34.56.78\nnameserver 2001:4860:4860::8888\n")
 	tmpResolvConf2 := []byte("search pommesfrites.fr\nnameserver 112.34.56.78\nnameserver 2001:4860:4860::8888\n")
 	tmpResolvConf2 := []byte("search pommesfrites.fr\nnameserver 112.34.56.78\nnameserver 2001:4860:4860::8888\n")
@@ -1069,9 +1053,7 @@ func TestParallel2(t *testing.T) {
 }
 }
 
 
 func TestBridge(t *testing.T) {
 func TestBridge(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	netOption := options.Generic{
 	netOption := options.Generic{
 		netlabel.EnableIPv6: true,
 		netlabel.EnableIPv6: true,

+ 17 - 51
libnetwork/libnetwork_test.go

@@ -145,9 +145,7 @@ func TestNull(t *testing.T) {
 }
 }
 
 
 func TestUnknownDriver(t *testing.T) {
 func TestUnknownDriver(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	_, err := createTestNetwork("unknowndriver", "testnetwork", options.Generic{}, nil, nil)
 	_, err := createTestNetwork("unknowndriver", "testnetwork", options.Generic{}, nil, nil)
 	if err == nil {
 	if err == nil {
@@ -172,9 +170,7 @@ func TestNilRemoteDriver(t *testing.T) {
 }
 }
 
 
 func TestNetworkName(t *testing.T) {
 func TestNetworkName(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	netOption := options.Generic{
 	netOption := options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{
@@ -208,9 +204,7 @@ func TestNetworkName(t *testing.T) {
 }
 }
 
 
 func TestNetworkType(t *testing.T) {
 func TestNetworkType(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	netOption := options.Generic{
 	netOption := options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{
@@ -234,9 +228,7 @@ func TestNetworkType(t *testing.T) {
 }
 }
 
 
 func TestNetworkID(t *testing.T) {
 func TestNetworkID(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	netOption := options.Generic{
 	netOption := options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{
@@ -260,9 +252,7 @@ func TestNetworkID(t *testing.T) {
 }
 }
 
 
 func TestDeleteNetworkWithActiveEndpoints(t *testing.T) {
 func TestDeleteNetworkWithActiveEndpoints(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	netOption := options.Generic{
 	netOption := options.Generic{
 		"BridgeName": "testnetwork",
 		"BridgeName": "testnetwork",
@@ -301,9 +291,7 @@ func TestDeleteNetworkWithActiveEndpoints(t *testing.T) {
 }
 }
 
 
 func TestNetworkConfig(t *testing.T) {
 func TestNetworkConfig(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	// Verify config network cannot inherit another config network
 	// Verify config network cannot inherit another config network
 	_, err := controller.NewNetwork("bridge", "config_network0", "",
 	_, err := controller.NewNetwork("bridge", "config_network0", "",
@@ -403,9 +391,7 @@ func TestNetworkConfig(t *testing.T) {
 }
 }
 
 
 func TestUnknownNetwork(t *testing.T) {
 func TestUnknownNetwork(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	netOption := options.Generic{
 	netOption := options.Generic{
 		"BridgeName": "testnetwork",
 		"BridgeName": "testnetwork",
@@ -435,9 +421,7 @@ func TestUnknownNetwork(t *testing.T) {
 }
 }
 
 
 func TestUnknownEndpoint(t *testing.T) {
 func TestUnknownEndpoint(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	netOption := options.Generic{
 	netOption := options.Generic{
 		"BridgeName": "testnetwork",
 		"BridgeName": "testnetwork",
@@ -477,9 +461,7 @@ func TestUnknownEndpoint(t *testing.T) {
 }
 }
 
 
 func TestNetworkEndpointsWalkers(t *testing.T) {
 func TestNetworkEndpointsWalkers(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	// Create network 1 and add 2 endpoint: ep11, ep12
 	// Create network 1 and add 2 endpoint: ep11, ep12
 	netOption := options.Generic{
 	netOption := options.Generic{
@@ -607,9 +589,7 @@ func TestNetworkEndpointsWalkers(t *testing.T) {
 }
 }
 
 
 func TestDuplicateEndpoint(t *testing.T) {
 func TestDuplicateEndpoint(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	netOption := options.Generic{
 	netOption := options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{
@@ -656,9 +636,7 @@ func TestDuplicateEndpoint(t *testing.T) {
 }
 }
 
 
 func TestControllerQuery(t *testing.T) {
 func TestControllerQuery(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	// Create network 1
 	// Create network 1
 	netOption := options.Generic{
 	netOption := options.Generic{
@@ -758,9 +736,7 @@ func TestControllerQuery(t *testing.T) {
 }
 }
 
 
 func TestNetworkQuery(t *testing.T) {
 func TestNetworkQuery(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	// Create network 1 and add 2 endpoint: ep11, ep12
 	// Create network 1 and add 2 endpoint: ep11, ep12
 	netOption := options.Generic{
 	netOption := options.Generic{
@@ -907,9 +883,7 @@ func (f *fakeSandbox) DisableService() error {
 }
 }
 
 
 func TestEndpointDeleteWithActiveContainer(t *testing.T) {
 func TestEndpointDeleteWithActiveContainer(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
 	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{
@@ -982,9 +956,7 @@ func TestEndpointDeleteWithActiveContainer(t *testing.T) {
 }
 }
 
 
 func TestEndpointMultipleJoins(t *testing.T) {
 func TestEndpointMultipleJoins(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	n, err := createTestNetwork(bridgeNetType, "testmultiple", options.Generic{
 	n, err := createTestNetwork(bridgeNetType, "testmultiple", options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{
@@ -1056,9 +1028,7 @@ func TestEndpointMultipleJoins(t *testing.T) {
 }
 }
 
 
 func TestLeaveAll(t *testing.T) {
 func TestLeaveAll(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
 	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{
@@ -1121,9 +1091,7 @@ func TestLeaveAll(t *testing.T) {
 }
 }
 
 
 func TestContainerInvalidLeave(t *testing.T) {
 func TestContainerInvalidLeave(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
 	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{
@@ -1187,9 +1155,7 @@ func TestContainerInvalidLeave(t *testing.T) {
 }
 }
 
 
 func TestEndpointUpdateParent(t *testing.T) {
 func TestEndpointUpdateParent(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
 	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
 		netlabel.GenericData: options.Generic{
 		netlabel.GenericData: options.Generic{

+ 2 - 6
libnetwork/sandbox_test.go

@@ -82,9 +82,7 @@ func TestSandboxAddEmpty(t *testing.T) {
 
 
 // // If different priorities are specified, internal option and ipv6 addresses mustn't influence endpoint order
 // // If different priorities are specified, internal option and ipv6 addresses mustn't influence endpoint order
 func TestSandboxAddMultiPrio(t *testing.T) {
 func TestSandboxAddMultiPrio(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	opts := [][]NetworkOption{
 	opts := [][]NetworkOption{
 		{NetworkOptionEnableIPv6(true), NetworkOptionIpam(ipamapi.DefaultIPAM, "", nil, []*IpamConf{{PreferredPool: "fe90::/64"}}, nil)},
 		{NetworkOptionEnableIPv6(true), NetworkOptionIpam(ipamapi.DefaultIPAM, "", nil, []*IpamConf{{PreferredPool: "fe90::/64"}}, nil)},
@@ -169,9 +167,7 @@ func TestSandboxAddMultiPrio(t *testing.T) {
 }
 }
 
 
 func TestSandboxAddSamePrio(t *testing.T) {
 func TestSandboxAddSamePrio(t *testing.T) {
-	if !testutils.IsRunningInContainer() {
-		defer testutils.SetupTestOSContext(t)()
-	}
+	defer testutils.SetupTestOSContext(t)()
 
 
 	opts := [][]NetworkOption{
 	opts := [][]NetworkOption{
 		{},
 		{},

+ 11 - 0
libnetwork/testutils/context_unix.go

@@ -47,6 +47,17 @@ func SetupTestOSContext(t *testing.T) func() {
 	// sure to re-initialize initNs context
 	// sure to re-initialize initNs context
 	ns.Init()
 	ns.Init()
 
 
+	nl := ns.NlHandle()
+	lo, err := nl.LinkByName("lo")
+	if err != nil {
+		restore()
+		t.Fatalf("Failed to get handle to loopback interface 'lo' in new netns: %v", err)
+	}
+	if err := nl.LinkSetUp(lo); err != nil {
+		restore()
+		t.Fatalf("Failed to enable loopback interface in new netns: %v", err)
+	}
+
 	return func() {
 	return func() {
 		if err := newNS.Close(); err != nil {
 		if err := newNS.Close(); err != nil {
 			t.Logf("Warning: netns closing failed (%v)", err)
 			t.Logf("Warning: netns closing failed (%v)", err)

+ 0 - 11
libnetwork/testutils/net.go

@@ -1,11 +0,0 @@
-package testutils
-
-import (
-	"os"
-)
-
-// IsRunningInContainer returns whether the test is running inside a container.
-func IsRunningInContainer() bool {
-	_, err := os.Stat("/.dockerenv")
-	return err == nil
-}