mirror of
https://github.com/clearlinux/libnetwork.git
synced 2026-10-04 07:48:30 +00:00
Merge pull request #563 from mavenugo/adb
Fixes in bridge and overlay drivers
This commit is contained in:
+1
-1
@@ -163,7 +163,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
|
||||
log.Debugf("Failed to Initialize Discovery : %v", err)
|
||||
}
|
||||
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
@@ -48,18 +48,18 @@ type configuration struct {
|
||||
|
||||
// networkConfiguration for network specific configuration
|
||||
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
|
||||
@@ -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 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 {
|
||||
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
|
||||
}
|
||||
|
||||
func parseNetworkOptions(option options.Generic) (*networkConfiguration, error) {
|
||||
func parseNetworkOptions(id string, option options.Generic) (*networkConfiguration, error) {
|
||||
var err error
|
||||
config := &networkConfiguration{}
|
||||
|
||||
@@ -537,6 +537,9 @@ func parseNetworkOptions(option options.Generic) (*networkConfiguration, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if config.BridgeName == "" && config.DefaultBridge == false {
|
||||
config.BridgeName = "br-" + id[:12]
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
@@ -580,7 +583,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}) error {
|
||||
d.Unlock()
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func TestCreateFail(t *testing.T) {
|
||||
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[netlabel.GenericData] = netconfig
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ func setupDevice(config *networkConfiguration, i *bridgeInterface) error {
|
||||
|
||||
// We only attempt to create the bridge when the requested device name is
|
||||
// the default one.
|
||||
if config.BridgeName != DefaultBridgeName && config.DisableBridgeCreation {
|
||||
if config.BridgeName != DefaultBridgeName && config.DefaultBridge {
|
||||
return NonDefaultBridgeExistError(config.BridgeName)
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestSetupNewBridge(t *testing.T) {
|
||||
func TestSetupNewNonDefaultBridge(t *testing.T) {
|
||||
defer testutils.SetupTestOSContext(t)()
|
||||
|
||||
config := &networkConfiguration{BridgeName: "test0", DisableBridgeCreation: true}
|
||||
config := &networkConfiguration{BridgeName: "test0", DefaultBridge: true}
|
||||
br := &bridgeInterface{}
|
||||
|
||||
err := setupDevice(config, br)
|
||||
|
||||
@@ -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
|
||||
// specifically asked to do so.
|
||||
if config.BridgeName != DefaultBridgeName && config.DisableBridgeCreation {
|
||||
if config.BridgeName != DefaultBridgeName && config.DefaultBridge {
|
||||
return NonDefaultBridgeNeedsIPError(config.BridgeName)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}) error {
|
||||
return fmt.Errorf("invalid network id")
|
||||
}
|
||||
|
||||
if err := d.configure(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n := &network{
|
||||
id: id,
|
||||
driver: d,
|
||||
|
||||
@@ -31,6 +31,7 @@ type driver struct {
|
||||
exitCh chan chan struct{}
|
||||
ifaceName string
|
||||
neighIP string
|
||||
config map[string]interface{}
|
||||
peerDb peerNetworkMap
|
||||
serfInstance *serf.Serf
|
||||
networks networkTable
|
||||
@@ -80,10 +81,7 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
|
||||
peerDb: peerNetworkMap{
|
||||
mp: map[string]peerMap{},
|
||||
},
|
||||
}
|
||||
|
||||
if err := d.configure(config); err != nil {
|
||||
return err
|
||||
config: config,
|
||||
}
|
||||
|
||||
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 err error
|
||||
|
||||
if len(option) == 0 {
|
||||
if len(d.config) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
d.Do(func() {
|
||||
onceDone = true
|
||||
|
||||
if ifaceName, ok := option[netlabel.OverlayBindInterface]; ok {
|
||||
if ifaceName, ok := d.config[netlabel.OverlayBindInterface]; ok {
|
||||
d.ifaceName = ifaceName.(string)
|
||||
}
|
||||
|
||||
if neighIP, ok := option[netlabel.OverlayNeighborIP]; ok {
|
||||
if neighIP, ok := d.config[netlabel.OverlayNeighborIP]; ok {
|
||||
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 {
|
||||
cfg := &config.DatastoreCfg{
|
||||
@@ -131,7 +129,7 @@ func (d *driver) configure(option map[string]interface{}) error {
|
||||
Address: provURL.(string),
|
||||
},
|
||||
}
|
||||
provConfig, confOk := option[netlabel.KVProviderConfig]
|
||||
provConfig, confOk := d.config[netlabel.KVProviderConfig]
|
||||
if confOk {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ func setupDriver(t *testing.T) *driverTester {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := dt.d.configure(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return dt
|
||||
}
|
||||
|
||||
@@ -78,7 +81,7 @@ func TestOverlayNilConfig(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := dt.d.configure(nil); err != nil {
|
||||
if err := dt.d.configure(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ func (c *controller) acceptClientConnections(sock string, l net.Listener) {
|
||||
conn, err := l.Accept()
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
logrus.Errorf("Error accepting connection %v", err)
|
||||
|
||||
+9
-5
@@ -133,14 +133,18 @@ func TestLocalStoreLockTimeout(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Error getting random boltdb configs %v", err)
|
||||
}
|
||||
ctrl, err := New(cfgOptions...)
|
||||
ctrl1, err := New(cfgOptions...)
|
||||
if err != nil {
|
||||
t.Fatalf("Error new controller: %v", err)
|
||||
}
|
||||
defer ctrl.Stop()
|
||||
defer ctrl1.Stop()
|
||||
// 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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user