mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
- Added initial test cases for libnetwork api
- Introduce delete api Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
parent
6e14090866
commit
4ac519f7b6
4 changed files with 76 additions and 3 deletions
|
@ -84,5 +84,5 @@ func (d *driver) CreateNetwork(name string, opaqueConfig interface{}) (libnetwor
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return &bridgeNetwork{NetworkName: name, Config: *config}, nil
|
||||
return &bridgeNetwork{NetworkName: name, bridge: bridgeIntfc}, nil
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package bridge
|
||||
|
||||
import "github.com/docker/libnetwork"
|
||||
import (
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
type bridgeNetwork struct {
|
||||
Config Configuration
|
||||
NetworkName string
|
||||
bridge *bridgeInterface
|
||||
}
|
||||
|
||||
func (b *bridgeNetwork) Name() string {
|
||||
|
@ -19,3 +22,7 @@ func (b *bridgeNetwork) Link(name string) ([]*libnetwork.Interface, error) {
|
|||
// TODO
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (b *bridgeNetwork) Delete() error {
|
||||
return netlink.LinkDel(b.bridge.Link)
|
||||
}
|
||||
|
|
64
libnetwork/libnetwork_test.go
Normal file
64
libnetwork/libnetwork_test.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
package libnetwork_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/libnetwork"
|
||||
_ "github.com/docker/libnetwork/drivers/bridge"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
var bridgeName = "docker0"
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
// Cleanup any existing docker0 bridge if needed. Ignore errors
|
||||
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: bridgeName}}
|
||||
netlink.LinkDel(bridge)
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestSimplebridge(t *testing.T) {
|
||||
|
||||
ip, subnet, err := net.ParseCIDR("192.168.100.1/24")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
subnet.IP = ip
|
||||
|
||||
ip, cidr, err := net.ParseCIDR("192.168.100.2/28")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cidr.IP = ip
|
||||
|
||||
ip, cidrv6, err := net.ParseCIDR("fe90::1/96")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cidrv6.IP = ip
|
||||
|
||||
log.Debug("Adding a simple bridge")
|
||||
options := libnetwork.DriverParams{
|
||||
"BridgeName": bridgeName,
|
||||
"AddressIPv4": subnet,
|
||||
"FixedCIDR": cidr,
|
||||
"FixedCIDRv6": cidrv6,
|
||||
"EnableIPv6": true,
|
||||
"EnableIPTables": true,
|
||||
"EnableIPMasquerade": true,
|
||||
"EnableICC": true,
|
||||
"EnableIPForwarding": true}
|
||||
|
||||
network, err := libnetwork.NewNetwork("simplebridge", "dummy", options)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := network.Delete(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
|
@ -76,6 +76,8 @@ type Network interface {
|
|||
// Create a new link to this network symbolically identified by the
|
||||
// specified unique name.
|
||||
Link(name string) ([]*Interface, error)
|
||||
|
||||
Delete() error
|
||||
}
|
||||
|
||||
// Namespace represents a network namespace, mounted on a specific Path. It
|
||||
|
|
Loading…
Add table
Reference in a new issue