|
@@ -28,8 +28,6 @@ import (
|
|
|
"github.com/sirupsen/logrus"
|
|
|
)
|
|
|
|
|
|
-var controller libnetwork.NetworkController
|
|
|
-
|
|
|
func TestMain(m *testing.M) {
|
|
|
if runtime.GOOS == "windows" {
|
|
|
logrus.Info("Test suite does not currently support windows")
|
|
@@ -39,39 +37,33 @@ func TestMain(m *testing.M) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if err := createController(); err != nil {
|
|
|
- logrus.Errorf("Error creating controller: %v", err)
|
|
|
- os.Exit(1)
|
|
|
- }
|
|
|
+ // Cleanup local datastore file
|
|
|
+ _ = os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
|
|
|
|
|
|
- x := m.Run()
|
|
|
- controller.Stop()
|
|
|
- os.Exit(x)
|
|
|
+ os.Exit(m.Run())
|
|
|
}
|
|
|
|
|
|
-func createController() error {
|
|
|
- var err error
|
|
|
-
|
|
|
- // Cleanup local datastore file
|
|
|
- os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
|
|
|
-
|
|
|
- option := options.Generic{
|
|
|
- "EnableIPForwarding": true,
|
|
|
+func newController(t *testing.T) libnetwork.NetworkController {
|
|
|
+ t.Helper()
|
|
|
+ genericOption := map[string]interface{}{
|
|
|
+ netlabel.GenericData: options.Generic{
|
|
|
+ "EnableIPForwarding": true,
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
- genericOption := make(map[string]interface{})
|
|
|
- genericOption[netlabel.GenericData] = option
|
|
|
-
|
|
|
- cfgOptions, err := libnetwork.OptionBoltdbWithRandomDBFile()
|
|
|
+ c, err := libnetwork.New(
|
|
|
+ libnetwork.OptionBoltdbWithRandomDBFile(t),
|
|
|
+ config.OptionDriverConfig(bridgeNetType, genericOption),
|
|
|
+ )
|
|
|
if err != nil {
|
|
|
- return err
|
|
|
+ t.Fatal(err)
|
|
|
}
|
|
|
- controller, err = libnetwork.New(append(cfgOptions, config.OptionDriverConfig(bridgeNetType, genericOption))...)
|
|
|
- return err
|
|
|
+ t.Cleanup(c.Stop)
|
|
|
+ return c
|
|
|
}
|
|
|
|
|
|
-func createTestNetwork(networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (libnetwork.Network, error) {
|
|
|
- return controller.NewNetwork(networkType, networkName, "",
|
|
|
+func createTestNetwork(c libnetwork.NetworkController, networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (libnetwork.Network, error) {
|
|
|
+ return c.NewNetwork(networkType, networkName, "",
|
|
|
libnetwork.NetworkOptionGeneric(netOption),
|
|
|
libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", ipamV4Configs, ipamV6Configs, nil))
|
|
|
}
|
|
@@ -98,6 +90,9 @@ func isNotFound(err error) bool {
|
|
|
}
|
|
|
|
|
|
func TestNull(t *testing.T) {
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
+
|
|
|
cnt, err := controller.NewSandbox("null_container",
|
|
|
libnetwork.OptionHostname("test"),
|
|
|
libnetwork.OptionDomainname("docker.io"),
|
|
@@ -106,7 +101,7 @@ func TestNull(t *testing.T) {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
|
- network, err := createTestNetwork("null", "testnull", options.Generic{}, nil, nil)
|
|
|
+ network, err := createTestNetwork(controller, "null", "testnull", options.Generic{}, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -145,11 +140,10 @@ func TestNull(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestUnknownDriver(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
- _, err := createTestNetwork("unknowndriver", "testnetwork", options.Generic{}, nil, nil)
|
|
|
+ _, err := createTestNetwork(controller, "unknowndriver", "testnetwork", options.Generic{}, nil, nil)
|
|
|
if err == nil {
|
|
|
t.Fatal("Expected to fail. But instead succeeded")
|
|
|
}
|
|
@@ -160,6 +154,9 @@ func TestUnknownDriver(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestNilRemoteDriver(t *testing.T) {
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
+
|
|
|
_, err := controller.NewNetwork("framerelay", "dummy", "",
|
|
|
libnetwork.NetworkOptionGeneric(getEmptyGenericOption()))
|
|
|
if err == nil {
|
|
@@ -172,9 +169,8 @@ func TestNilRemoteDriver(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestNetworkName(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
netOption := options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
@@ -182,7 +178,7 @@ func TestNetworkName(t *testing.T) {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- _, err := createTestNetwork(bridgeNetType, "", netOption, nil, nil)
|
|
|
+ _, err := createTestNetwork(controller, bridgeNetType, "", netOption, nil, nil)
|
|
|
if err == nil {
|
|
|
t.Fatal("Expected to fail. But instead succeeded")
|
|
|
}
|
|
@@ -192,7 +188,7 @@ func TestNetworkName(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
networkName := "testnetwork"
|
|
|
- n, err := createTestNetwork(bridgeNetType, networkName, netOption, nil, nil)
|
|
|
+ n, err := createTestNetwork(controller, bridgeNetType, networkName, netOption, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -208,9 +204,8 @@ func TestNetworkName(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestNetworkType(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
netOption := options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
@@ -218,7 +213,7 @@ func TestNetworkType(t *testing.T) {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- n, err := createTestNetwork(bridgeNetType, "testnetwork", netOption, nil, nil)
|
|
|
+ n, err := createTestNetwork(controller, bridgeNetType, "testnetwork", netOption, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -234,9 +229,8 @@ func TestNetworkType(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestNetworkID(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
netOption := options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
@@ -244,7 +238,7 @@ func TestNetworkID(t *testing.T) {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- n, err := createTestNetwork(bridgeNetType, "testnetwork", netOption, nil, nil)
|
|
|
+ n, err := createTestNetwork(controller, bridgeNetType, "testnetwork", netOption, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -260,9 +254,8 @@ func TestNetworkID(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestDeleteNetworkWithActiveEndpoints(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
netOption := options.Generic{
|
|
|
"BridgeName": "testnetwork",
|
|
@@ -271,7 +264,7 @@ func TestDeleteNetworkWithActiveEndpoints(t *testing.T) {
|
|
|
netlabel.GenericData: netOption,
|
|
|
}
|
|
|
|
|
|
- network, err := createTestNetwork(bridgeNetType, "testnetwork", option, nil, nil)
|
|
|
+ network, err := createTestNetwork(controller, bridgeNetType, "testnetwork", option, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -301,9 +294,8 @@ func TestDeleteNetworkWithActiveEndpoints(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestNetworkConfig(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
// Verify config network cannot inherit another config network
|
|
|
_, err := controller.NewNetwork("bridge", "config_network0", "",
|
|
@@ -403,9 +395,8 @@ func TestNetworkConfig(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestUnknownNetwork(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
netOption := options.Generic{
|
|
|
"BridgeName": "testnetwork",
|
|
@@ -414,7 +405,7 @@ func TestUnknownNetwork(t *testing.T) {
|
|
|
netlabel.GenericData: netOption,
|
|
|
}
|
|
|
|
|
|
- network, err := createTestNetwork(bridgeNetType, "testnetwork", option, nil, nil)
|
|
|
+ network, err := createTestNetwork(controller, bridgeNetType, "testnetwork", option, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -435,9 +426,8 @@ func TestUnknownNetwork(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestUnknownEndpoint(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
netOption := options.Generic{
|
|
|
"BridgeName": "testnetwork",
|
|
@@ -447,7 +437,7 @@ func TestUnknownEndpoint(t *testing.T) {
|
|
|
}
|
|
|
ipamV4ConfList := []*libnetwork.IpamConf{{PreferredPool: "192.168.100.0/24"}}
|
|
|
|
|
|
- network, err := createTestNetwork(bridgeNetType, "testnetwork", option, ipamV4ConfList, nil)
|
|
|
+ network, err := createTestNetwork(controller, bridgeNetType, "testnetwork", option, ipamV4ConfList, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -477,9 +467,8 @@ func TestUnknownEndpoint(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestNetworkEndpointsWalkers(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
// Create network 1 and add 2 endpoint: ep11, ep12
|
|
|
netOption := options.Generic{
|
|
@@ -488,7 +477,7 @@ func TestNetworkEndpointsWalkers(t *testing.T) {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- net1, err := createTestNetwork(bridgeNetType, "network1", netOption, nil, nil)
|
|
|
+ net1, err := createTestNetwork(controller, bridgeNetType, "network1", netOption, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -560,7 +549,7 @@ func TestNetworkEndpointsWalkers(t *testing.T) {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- net2, err := createTestNetwork(bridgeNetType, "network2", netOption, nil, nil)
|
|
|
+ net2, err := createTestNetwork(controller, bridgeNetType, "network2", netOption, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -607,16 +596,15 @@ func TestNetworkEndpointsWalkers(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestDuplicateEndpoint(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
netOption := options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
|
"BridgeName": "testnetwork",
|
|
|
},
|
|
|
}
|
|
|
- n, err := createTestNetwork(bridgeNetType, "testnetwork", netOption, nil, nil)
|
|
|
+ n, err := createTestNetwork(controller, bridgeNetType, "testnetwork", netOption, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -656,9 +644,8 @@ func TestDuplicateEndpoint(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestControllerQuery(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
// Create network 1
|
|
|
netOption := options.Generic{
|
|
@@ -666,7 +653,7 @@ func TestControllerQuery(t *testing.T) {
|
|
|
"BridgeName": "network1",
|
|
|
},
|
|
|
}
|
|
|
- net1, err := createTestNetwork(bridgeNetType, "network1", netOption, nil, nil)
|
|
|
+ net1, err := createTestNetwork(controller, bridgeNetType, "network1", netOption, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -682,7 +669,7 @@ func TestControllerQuery(t *testing.T) {
|
|
|
"BridgeName": "network2",
|
|
|
},
|
|
|
}
|
|
|
- net2, err := createTestNetwork(bridgeNetType, "network2", netOption, nil, nil)
|
|
|
+ net2, err := createTestNetwork(controller, bridgeNetType, "network2", netOption, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -758,9 +745,8 @@ func TestControllerQuery(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestNetworkQuery(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
// Create network 1 and add 2 endpoint: ep11, ep12
|
|
|
netOption := options.Generic{
|
|
@@ -768,7 +754,7 @@ func TestNetworkQuery(t *testing.T) {
|
|
|
"BridgeName": "network1",
|
|
|
},
|
|
|
}
|
|
|
- net1, err := createTestNetwork(bridgeNetType, "network1", netOption, nil, nil)
|
|
|
+ net1, err := createTestNetwork(controller, bridgeNetType, "network1", netOption, nil, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -907,11 +893,10 @@ func (f *fakeSandbox) DisableService() error {
|
|
|
}
|
|
|
|
|
|
func TestEndpointDeleteWithActiveContainer(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
- n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
|
|
|
+ n, err := createTestNetwork(controller, bridgeNetType, "testnetwork", options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
|
"BridgeName": "testnetwork",
|
|
|
},
|
|
@@ -925,7 +910,7 @@ func TestEndpointDeleteWithActiveContainer(t *testing.T) {
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- n2, err := createTestNetwork(bridgeNetType, "testnetwork2", options.Generic{
|
|
|
+ n2, err := createTestNetwork(controller, bridgeNetType, "testnetwork2", options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
|
"BridgeName": "testnetwork2",
|
|
|
},
|
|
@@ -982,11 +967,10 @@ func TestEndpointDeleteWithActiveContainer(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestEndpointMultipleJoins(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
- n, err := createTestNetwork(bridgeNetType, "testmultiple", options.Generic{
|
|
|
+ n, err := createTestNetwork(controller, bridgeNetType, "testmultiple", options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
|
"BridgeName": "testmultiple",
|
|
|
},
|
|
@@ -1056,11 +1040,10 @@ func TestEndpointMultipleJoins(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestLeaveAll(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
- n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
|
|
|
+ n, err := createTestNetwork(controller, bridgeNetType, "testnetwork", options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
|
"BridgeName": "testnetwork",
|
|
|
},
|
|
@@ -1075,7 +1058,7 @@ func TestLeaveAll(t *testing.T) {
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- n2, err := createTestNetwork(bridgeNetType, "testnetwork2", options.Generic{
|
|
|
+ n2, err := createTestNetwork(controller, bridgeNetType, "testnetwork2", options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
|
"BridgeName": "testnetwork2",
|
|
|
},
|
|
@@ -1121,11 +1104,10 @@ func TestLeaveAll(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestContainerInvalidLeave(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
- n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
|
|
|
+ n, err := createTestNetwork(controller, bridgeNetType, "testnetwork", options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
|
"BridgeName": "testnetwork",
|
|
|
},
|
|
@@ -1187,11 +1169,10 @@ func TestContainerInvalidLeave(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestEndpointUpdateParent(t *testing.T) {
|
|
|
- if !testutils.IsRunningInContainer() {
|
|
|
- defer testutils.SetupTestOSContext(t)()
|
|
|
- }
|
|
|
+ defer testutils.SetupTestOSContext(t)()
|
|
|
+ controller := newController(t)
|
|
|
|
|
|
- n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
|
|
|
+ n, err := createTestNetwork(controller, bridgeNetType, "testnetwork", options.Generic{
|
|
|
netlabel.GenericData: options.Generic{
|
|
|
"BridgeName": "testnetwork",
|
|
|
},
|
|
@@ -1334,6 +1315,7 @@ func TestValidRemoteDriver(t *testing.T) {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
|
+ controller := newController(t)
|
|
|
n, err := controller.NewNetwork("valid-network-driver", "dummy", "",
|
|
|
libnetwork.NetworkOptionGeneric(getEmptyGenericOption()))
|
|
|
if err != nil {
|
|
@@ -1349,23 +1331,3 @@ func TestValidRemoteDriver(t *testing.T) {
|
|
|
}
|
|
|
}()
|
|
|
}
|
|
|
-
|
|
|
-var (
|
|
|
- start = make(chan struct{})
|
|
|
- done = make(chan chan struct{}, numThreads-1)
|
|
|
- sboxes = make([]libnetwork.Sandbox, numThreads)
|
|
|
-)
|
|
|
-
|
|
|
-const (
|
|
|
- iterCnt = 25
|
|
|
- numThreads = 3
|
|
|
- first = 1
|
|
|
- last = numThreads
|
|
|
- debug = false
|
|
|
-)
|
|
|
-
|
|
|
-func debugf(format string, a ...interface{}) {
|
|
|
- if debug {
|
|
|
- fmt.Printf(format, a...)
|
|
|
- }
|
|
|
-}
|