Parcourir la source

Merge pull request #563 from mavenugo/adb

Fixes in bridge and overlay drivers
Jana Radhakrishnan il y a 9 ans
Parent
commit
e6340940b0

+ 1 - 1
libnetwork/controller.go

@@ -163,7 +163,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
 			log.Debugf("Failed to Initialize Discovery : %v", err)
 			log.Debugf("Failed to Initialize Discovery : %v", err)
 		}
 		}
 		if err := c.initLocalStore(); err != nil {
 		if err := c.initLocalStore(); err != nil {
-			return nil, fmt.Errorf("Failed to Initialize LocalDatastore due to %v.", err)
+			log.Debugf("Failed to Initialize LocalDatastore due to %v.", err)
 		}
 		}
 	}
 	}
 
 

+ 21 - 18
libnetwork/drivers/bridge/bridge.go

@@ -48,18 +48,18 @@ type configuration struct {
 
 
 // networkConfiguration for network specific configuration
 // networkConfiguration for network specific configuration
 type networkConfiguration struct {
 type networkConfiguration struct {
-	BridgeName            string
-	AddressIPv4           *net.IPNet
-	FixedCIDR             *net.IPNet
-	FixedCIDRv6           *net.IPNet
-	EnableIPv6            bool
-	EnableIPMasquerade    bool
-	EnableICC             bool
-	Mtu                   int
-	DefaultGatewayIPv4    net.IP
-	DefaultGatewayIPv6    net.IP
-	DefaultBindingIP      net.IP
-	DisableBridgeCreation bool
+	BridgeName         string
+	AddressIPv4        *net.IPNet
+	FixedCIDR          *net.IPNet
+	FixedCIDRv6        *net.IPNet
+	EnableIPv6         bool
+	EnableIPMasquerade bool
+	EnableICC          bool
+	Mtu                int
+	DefaultGatewayIPv4 net.IP
+	DefaultGatewayIPv6 net.IP
+	DefaultBindingIP   net.IP
+	DefaultBridge      bool
 }
 }
 
 
 // endpointConfiguration represents the user specified configuration for the sandbox endpoint
 // endpointConfiguration represents the user specified configuration for the sandbox endpoint
@@ -249,13 +249,13 @@ func (c *networkConfiguration) fromMap(data map[string]interface{}) error {
 		}
 		}
 	}
 	}
 
 
-	if i, ok := data["DisableBridgeCreation"]; ok && i != nil {
+	if i, ok := data["DefaultBridge"]; ok && i != nil {
 		if s, ok := i.(string); ok {
 		if s, ok := i.(string); ok {
-			if c.DisableBridgeCreation, err = strconv.ParseBool(s); err != nil {
-				return types.BadRequestErrorf("failed to parse DisableBridgeCreation value: %s", err.Error())
+			if c.DefaultBridge, err = strconv.ParseBool(s); err != nil {
+				return types.BadRequestErrorf("failed to parse DefaultBridge value: %s", err.Error())
 			}
 			}
 		} else {
 		} else {
-			return types.BadRequestErrorf("invalid type for DisableBridgeCreation value")
+			return types.BadRequestErrorf("invalid type for DefaultBridge value")
 		}
 		}
 	}
 	}
 
 
@@ -516,7 +516,7 @@ func parseNetworkGenericOptions(data interface{}) (*networkConfiguration, error)
 	return config, err
 	return config, err
 }
 }
 
 
-func parseNetworkOptions(option options.Generic) (*networkConfiguration, error) {
+func parseNetworkOptions(id string, option options.Generic) (*networkConfiguration, error) {
 	var err error
 	var err error
 	config := &networkConfiguration{}
 	config := &networkConfiguration{}
 
 
@@ -537,6 +537,9 @@ func parseNetworkOptions(option options.Generic) (*networkConfiguration, error)
 		return nil, err
 		return nil, err
 	}
 	}
 
 
+	if config.BridgeName == "" && config.DefaultBridge == false {
+		config.BridgeName = "br-" + id[:12]
+	}
 	return config, nil
 	return config, nil
 }
 }
 
 
@@ -580,7 +583,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}) error {
 	d.Unlock()
 	d.Unlock()
 
 
 	// Parse and validate the config. It should not conflict with existing networks' config
 	// Parse and validate the config. It should not conflict with existing networks' config
-	config, err := parseNetworkOptions(option)
+	config, err := parseNetworkOptions(id, option)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}

+ 1 - 1
libnetwork/drivers/bridge/bridge_test.go

@@ -123,7 +123,7 @@ func TestCreateFail(t *testing.T) {
 		t.Fatalf("Failed to setup driver config: %v", err)
 		t.Fatalf("Failed to setup driver config: %v", err)
 	}
 	}
 
 
-	netconfig := &networkConfiguration{BridgeName: "dummy0", DisableBridgeCreation: true}
+	netconfig := &networkConfiguration{BridgeName: "dummy0", DefaultBridge: true}
 	genericOption := make(map[string]interface{})
 	genericOption := make(map[string]interface{})
 	genericOption[netlabel.GenericData] = netconfig
 	genericOption[netlabel.GenericData] = netconfig
 
 

+ 1 - 1
libnetwork/drivers/bridge/setup_device.go

@@ -15,7 +15,7 @@ func setupDevice(config *networkConfiguration, i *bridgeInterface) error {
 
 
 	// We only attempt to create the bridge when the requested device name is
 	// We only attempt to create the bridge when the requested device name is
 	// the default one.
 	// the default one.
-	if config.BridgeName != DefaultBridgeName && config.DisableBridgeCreation {
+	if config.BridgeName != DefaultBridgeName && config.DefaultBridge {
 		return NonDefaultBridgeExistError(config.BridgeName)
 		return NonDefaultBridgeExistError(config.BridgeName)
 	}
 	}
 
 

+ 1 - 1
libnetwork/drivers/bridge/setup_device_test.go

@@ -33,7 +33,7 @@ func TestSetupNewBridge(t *testing.T) {
 func TestSetupNewNonDefaultBridge(t *testing.T) {
 func TestSetupNewNonDefaultBridge(t *testing.T) {
 	defer testutils.SetupTestOSContext(t)()
 	defer testutils.SetupTestOSContext(t)()
 
 
-	config := &networkConfiguration{BridgeName: "test0", DisableBridgeCreation: true}
+	config := &networkConfiguration{BridgeName: "test0", DefaultBridge: true}
 	br := &bridgeInterface{}
 	br := &bridgeInterface{}
 
 
 	err := setupDevice(config, br)
 	err := setupDevice(config, br)

+ 1 - 1
libnetwork/drivers/bridge/setup_ipv4.go

@@ -53,7 +53,7 @@ func setupBridgeIPv4(config *networkConfiguration, i *bridgeInterface) error {
 
 
 	// Do not try to configure IPv4 on a non-default bridge unless you are
 	// Do not try to configure IPv4 on a non-default bridge unless you are
 	// specifically asked to do so.
 	// specifically asked to do so.
-	if config.BridgeName != DefaultBridgeName && config.DisableBridgeCreation {
+	if config.BridgeName != DefaultBridgeName && config.DefaultBridge {
 		return NonDefaultBridgeNeedsIPError(config.BridgeName)
 		return NonDefaultBridgeNeedsIPError(config.BridgeName)
 	}
 	}
 
 

+ 4 - 0
libnetwork/drivers/overlay/ov_network.go

@@ -40,6 +40,10 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}) error {
 		return fmt.Errorf("invalid network id")
 		return fmt.Errorf("invalid network id")
 	}
 	}
 
 
+	if err := d.configure(); err != nil {
+		return err
+	}
+
 	n := &network{
 	n := &network{
 		id:        id,
 		id:        id,
 		driver:    d,
 		driver:    d,

+ 9 - 15
libnetwork/drivers/overlay/overlay.go

@@ -31,6 +31,7 @@ type driver struct {
 	exitCh       chan chan struct{}
 	exitCh       chan chan struct{}
 	ifaceName    string
 	ifaceName    string
 	neighIP      string
 	neighIP      string
+	config       map[string]interface{}
 	peerDb       peerNetworkMap
 	peerDb       peerNetworkMap
 	serfInstance *serf.Serf
 	serfInstance *serf.Serf
 	networks     networkTable
 	networks     networkTable
@@ -80,10 +81,7 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
 		peerDb: peerNetworkMap{
 		peerDb: peerNetworkMap{
 			mp: map[string]peerMap{},
 			mp: map[string]peerMap{},
 		},
 		},
-	}
-
-	if err := d.configure(config); err != nil {
-		return err
+		config: config,
 	}
 	}
 
 
 	return dc.RegisterDriver(networkType, d, c)
 	return dc.RegisterDriver(networkType, d, c)
@@ -102,27 +100,27 @@ func Fini(drv driverapi.Driver) {
 	}
 	}
 }
 }
 
 
-func (d *driver) configure(option map[string]interface{}) error {
+func (d *driver) configure() error {
 	var onceDone bool
 	var onceDone bool
 	var err error
 	var err error
 
 
-	if len(option) == 0 {
+	if len(d.config) == 0 {
 		return nil
 		return nil
 	}
 	}
 
 
 	d.Do(func() {
 	d.Do(func() {
 		onceDone = true
 		onceDone = true
 
 
-		if ifaceName, ok := option[netlabel.OverlayBindInterface]; ok {
+		if ifaceName, ok := d.config[netlabel.OverlayBindInterface]; ok {
 			d.ifaceName = ifaceName.(string)
 			d.ifaceName = ifaceName.(string)
 		}
 		}
 
 
-		if neighIP, ok := option[netlabel.OverlayNeighborIP]; ok {
+		if neighIP, ok := d.config[netlabel.OverlayNeighborIP]; ok {
 			d.neighIP = neighIP.(string)
 			d.neighIP = neighIP.(string)
 		}
 		}
 
 
-		provider, provOk := option[netlabel.KVProvider]
-		provURL, urlOk := option[netlabel.KVProviderURL]
+		provider, provOk := d.config[netlabel.KVProvider]
+		provURL, urlOk := d.config[netlabel.KVProviderURL]
 
 
 		if provOk && urlOk {
 		if provOk && urlOk {
 			cfg := &config.DatastoreCfg{
 			cfg := &config.DatastoreCfg{
@@ -131,7 +129,7 @@ func (d *driver) configure(option map[string]interface{}) error {
 					Address:  provURL.(string),
 					Address:  provURL.(string),
 				},
 				},
 			}
 			}
-			provConfig, confOk := option[netlabel.KVProviderConfig]
+			provConfig, confOk := d.config[netlabel.KVProviderConfig]
 			if confOk {
 			if confOk {
 				cfg.Client.Config = provConfig.(*store.Config)
 				cfg.Client.Config = provConfig.(*store.Config)
 			}
 			}
@@ -161,10 +159,6 @@ func (d *driver) configure(option map[string]interface{}) error {
 
 
 	})
 	})
 
 
-	if !onceDone {
-		return fmt.Errorf("config already applied to driver")
-	}
-
 	return err
 	return err
 }
 }
 
 

+ 4 - 1
libnetwork/drivers/overlay/overlay_test.go

@@ -24,6 +24,9 @@ func setupDriver(t *testing.T) *driverTester {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
+	if err := dt.d.configure(); err != nil {
+		t.Fatal(err)
+	}
 	return dt
 	return dt
 }
 }
 
 
@@ -78,7 +81,7 @@ func TestOverlayNilConfig(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if err := dt.d.configure(nil); err != nil {
+	if err := dt.d.configure(); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 

+ 1 - 1
libnetwork/sandbox_externalkey.go

@@ -138,7 +138,7 @@ func (c *controller) acceptClientConnections(sock string, l net.Listener) {
 		conn, err := l.Accept()
 		conn, err := l.Accept()
 		if err != nil {
 		if err != nil {
 			if _, err1 := os.Stat(sock); os.IsNotExist(err1) {
 			if _, err1 := os.Stat(sock); os.IsNotExist(err1) {
-				logrus.Warnf("Unix socket %s doesnt exist. cannot accept client connections", sock)
+				logrus.Debugf("Unix socket %s doesnt exist. cannot accept client connections", sock)
 				return
 				return
 			}
 			}
 			logrus.Errorf("Error accepting connection %v", err)
 			logrus.Errorf("Error accepting connection %v", err)

+ 9 - 5
libnetwork/store_test.go

@@ -133,14 +133,18 @@ func TestLocalStoreLockTimeout(t *testing.T) {
 	if err != nil {
 	if err != nil {
 		t.Fatalf("Error getting random boltdb configs %v", err)
 		t.Fatalf("Error getting random boltdb configs %v", err)
 	}
 	}
-	ctrl, err := New(cfgOptions...)
+	ctrl1, err := New(cfgOptions...)
 	if err != nil {
 	if err != nil {
 		t.Fatalf("Error new controller: %v", err)
 		t.Fatalf("Error new controller: %v", err)
 	}
 	}
-	defer ctrl.Stop()
+	defer ctrl1.Stop()
 	// Use the same boltdb file without closing the previous controller
 	// Use the same boltdb file without closing the previous controller
-	_, err = New(cfgOptions...)
-	if err == nil {
-		t.Fatalf("Multiple boldtdb connection must fail")
+	ctrl2, _ := New(cfgOptions...)
+	if err != nil {
+		t.Fatalf("Error new controller: %v", err)
+	}
+	store := ctrl2.(*controller).localStore
+	if store != nil {
+		t.Fatalf("localstore is expected to be nil")
 	}
 	}
 }
 }