mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
bridge/overlay driver should fail to create network with empty ip pool passed
Signed-off-by: Chun Chen <ramichen@tencent.com>
This commit is contained in:
parent
ac1ec348ff
commit
9ba3f70d8e
3 changed files with 13 additions and 0 deletions
|
@ -543,6 +543,9 @@ func (d *driver) getNetworks() []*bridgeNetwork {
|
||||||
|
|
||||||
// Create a new network using bridge plugin
|
// Create a new network using bridge plugin
|
||||||
func (d *driver) CreateNetwork(id string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error {
|
func (d *driver) CreateNetwork(id string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error {
|
||||||
|
if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" {
|
||||||
|
return types.BadRequestErrorf("ipv4 pool is empty")
|
||||||
|
}
|
||||||
// Sanity checks
|
// Sanity checks
|
||||||
d.Lock()
|
d.Lock()
|
||||||
if _, ok := d.networks[id]; ok {
|
if _, ok := d.networks[id]; ok {
|
||||||
|
|
|
@ -63,6 +63,9 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, ipV4Dat
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return fmt.Errorf("invalid network id")
|
return fmt.Errorf("invalid network id")
|
||||||
}
|
}
|
||||||
|
if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" {
|
||||||
|
return types.BadRequestErrorf("ipv4 pool is empty")
|
||||||
|
}
|
||||||
|
|
||||||
// Since we perform lazy configuration make sure we try
|
// Since we perform lazy configuration make sure we try
|
||||||
// configuring the driver when we enter CreateNetwork
|
// configuring the driver when we enter CreateNetwork
|
||||||
|
|
|
@ -2356,3 +2356,10 @@ func TestParallel2(t *testing.T) {
|
||||||
func TestParallel3(t *testing.T) {
|
func TestParallel3(t *testing.T) {
|
||||||
runParallelTests(t, 3)
|
runParallelTests(t, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNullIpam(t *testing.T) {
|
||||||
|
_, err := controller.NewNetwork(bridgeNetType, "testnetworkinternal", libnetwork.NetworkOptionIpam(ipamapi.NullIPAM, "", nil, nil, nil))
|
||||||
|
if err == nil || err.Error() != "ipv4 pool is empty" {
|
||||||
|
t.Fatal("bridge network should complain empty pool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue