Skip to content

Commit

Permalink
remove restrictions on null driver
Browse files Browse the repository at this point in the history
  • Loading branch information
clinta committed Feb 14, 2018
1 parent 1ba8194 commit 6451143
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
25 changes: 15 additions & 10 deletions ipams/null/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@ func (a *allocator) GetDefaultAddressSpaces() (string, string, error) {
}

func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
if addressSpace != defaultAS {
return "", nil, nil, types.BadRequestErrorf("unknown address space: %s", addressSpace)
if addressSpace == "" {
addressSpace = defaultAS
}
if pool != "" {
return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address pool requests")
}
if subPool != "" {
return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address subpool requests")

if pool == "" && subPool != "" {
return "", nil, nil, fmt.Errorf("subpool requires a pool to be configured")
}
if v6 {
return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle IPv6 address pool pool requests")

retPool := defaultPool
if pool != "" {
var err error
retPool, err = types.ParseCIDR(pool)
if err != nil {
return "", nil, nil, err
}
}
return defaultPoolID, defaultPool, nil, nil
retPoolID := fmt.Sprintf("%s/%s", addressSpace, retPool.String())
return retPoolID, retPool, nil, nil
}

func (a *allocator) ReleasePool(poolID string) error {
Expand Down
36 changes: 28 additions & 8 deletions ipams/null/null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,44 @@ func TestPoolRequest(t *testing.T) {
t.Fatalf("Unexpected pool id returned. Expected: %s. Got: %s", defaultPoolID, pid)
}

_, _, _, err = a.RequestPool("default", "", "", nil, false)
if err == nil {
t.Fatal("Unexpected success")
id, _, _, err := a.RequestPool("foo", "", "", nil, false)
if err != nil {
t.Fatal("Unexpected error")
}
if id != "foo/0.0.0.0/0" {
t.Fatal("Wrong id")
}

_, _, _, err = a.RequestPool(defaultAS, "192.168.0.0/16", "", nil, false)
if err == nil {
t.Fatal("Unexpected success")
id, p, _, err := a.RequestPool(defaultAS, "192.168.0.0/16", "", nil, false)
if err != nil {
t.Fatal("Unexpected error")
}
if id != defaultAS+"/192.168.0.0/16" {
t.Fatalf("Wrong id")
}
if p.String() != "192.168.0.0/16" {
t.Fatalf("Wrong pool")
}

_, _, _, err = a.RequestPool(defaultAS, "", "192.168.0.0/24", nil, false)
if err == nil {
t.Fatal("Unexpected success")
}

id, p, _, err = a.RequestPool(defaultAS, "192.168.0.0/16", "192.168.0.0/24", nil, false)
if err != nil {
t.Fatal("Unexpected error")
}
if id != defaultAS+"/192.168.0.0/16" {
t.Fatalf("Wrong id")
}
if p.String() != "192.168.0.0/16" {
t.Fatalf("Wrong pool")
}

_, _, _, err = a.RequestPool(defaultAS, "", "", nil, true)
if err == nil {
t.Fatal("Unexpected success")
if err != nil {
t.Fatal("Unexpected error")
}
}

Expand Down

0 comments on commit 6451143

Please sign in to comment.