Skip to content

Commit

Permalink
Adding test cases to test DNS options in RequestAddress
Browse files Browse the repository at this point in the history
Signed-off-by: Divya Vavili <[email protected]>
  • Loading branch information
dvavili committed Mar 3, 2016
1 parent f6ce465 commit 2c07c9c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36 deletions.
56 changes: 28 additions & 28 deletions ipam/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestSubnetsMarshal(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, _, err = a.RequestAddress(pid0, nil, nil)
_, _, _, _, err = a.RequestAddress(pid0, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -192,7 +192,7 @@ func TestSubnetsMarshal(t *testing.T) {
}

expIP := &net.IPNet{IP: net.IP{192, 168, 0, 2}, Mask: net.IPMask{255, 255, 0, 0}}
ip, _, err := a.RequestAddress(pid0, nil, nil)
ip, _, _, _, err := a.RequestAddress(pid0, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -201,7 +201,7 @@ func TestSubnetsMarshal(t *testing.T) {
}

expIP = &net.IPNet{IP: net.IP{192, 169, 0, 1}, Mask: net.IPMask{255, 255, 0, 0}}
ip, _, err = a.RequestAddress(pid1, nil, nil)
ip, _, _, _, err = a.RequestAddress(pid1, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -556,12 +556,12 @@ func TestGetSameAddress(t *testing.T) {
}

ip := net.ParseIP("192.168.100.250")
_, _, err = a.RequestAddress(pid, ip, nil)
_, _, _, _, err = a.RequestAddress(pid, ip, nil)
if err != nil {
t.Fatal(err)
}

_, _, err = a.RequestAddress(pid, ip, nil)
_, _, _, _, err = a.RequestAddress(pid, ip, nil)
if err == nil {
t.Fatal(err)
}
Expand All @@ -578,7 +578,7 @@ func TestGetAddressSubPoolEqualPool(t *testing.T) {
t.Fatal(err)
}

_, _, err = a.RequestAddress(pid, nil, nil)
_, _, _, _, err = a.RequestAddress(pid, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -606,7 +606,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) {
expected := &net.IPNet{IP: net.IP{172, 28, 30, 255}, Mask: net.IPMask{255, 255, 0, 0}}
for err == nil {
var c *net.IPNet
if c, _, err = a.RequestAddress(poolID, nil, nil); err == nil {
if c, _, _, _, err = a.RequestAddress(poolID, nil, nil); err == nil {
ip = c
}
}
Expand All @@ -620,7 +620,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) {
if err = a.ReleaseAddress(poolID, rp.IP); err != nil {
t.Fatal(err)
}
if ip, _, err = a.RequestAddress(poolID, nil, nil); err != nil {
if ip, _, _, _, err = a.RequestAddress(poolID, nil, nil); err != nil {
t.Fatal(err)
}
if !types.CompareIPNet(rp, ip) {
Expand All @@ -638,7 +638,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) {
expected = &net.IPNet{IP: net.IP{10, 0, 0, 255}, Mask: net.IPMask{255, 255, 0, 0}}
for err == nil {
var c *net.IPNet
if c, _, err = a.RequestAddress(poolID, nil, nil); err == nil {
if c, _, _, _, err = a.RequestAddress(poolID, nil, nil); err == nil {
ip = c
}
}
Expand All @@ -652,7 +652,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) {
if err = a.ReleaseAddress(poolID, rp.IP); err != nil {
t.Fatal(err)
}
if ip, _, err = a.RequestAddress(poolID, nil, nil); err != nil {
if ip, _, _, _, err = a.RequestAddress(poolID, nil, nil); err != nil {
t.Fatal(err)
}
if !types.CompareIPNet(rp, ip) {
Expand All @@ -666,23 +666,23 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) {
if poolID, _, _, err = a.RequestPool("rosso", "10.2.0.0/16", "10.2.2.0/24", nil, false); err != nil {
t.Fatal(err)
}
tre, _, err := a.RequestAddress(poolID, treExp.IP, nil)
tre, _, _, _, err := a.RequestAddress(poolID, treExp.IP, nil)
if err != nil {
t.Fatal(err)
}
if !types.CompareIPNet(tre, treExp) {
t.Fatalf("Unexpected address: %v", tre)
}

uno, _, err := a.RequestAddress(poolID, nil, nil)
uno, _, _, _, err := a.RequestAddress(poolID, nil, nil)
if err != nil {
t.Fatal(err)
}
if !types.CompareIPNet(uno, unoExp) {
t.Fatalf("Unexpected address: %v", uno)
}

due, _, err := a.RequestAddress(poolID, nil, nil)
due, _, _, _, err := a.RequestAddress(poolID, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -693,7 +693,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) {
if err = a.ReleaseAddress(poolID, uno.IP); err != nil {
t.Fatal(err)
}
uno, _, err = a.RequestAddress(poolID, nil, nil)
uno, _, _, _, err = a.RequestAddress(poolID, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -704,7 +704,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) {
if err = a.ReleaseAddress(poolID, tre.IP); err != nil {
t.Fatal(err)
}
tre, _, err = a.RequestAddress(poolID, nil, nil)
tre, _, _, _, err = a.RequestAddress(poolID, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -765,19 +765,19 @@ func TestRequestSyntaxCheck(t *testing.T) {
t.Fatalf("Unexpected failure: %v", err)
}

_, _, err = a.RequestAddress("", nil, nil)
_, _, _, _, err = a.RequestAddress("", nil, nil)
if err == nil {
t.Fatalf("Failed to detect wrong request: no pool id specified")
}

ip := net.ParseIP("172.17.0.23")
_, _, err = a.RequestAddress(pid, ip, nil)
_, _, _, _, err = a.RequestAddress(pid, ip, nil)
if err == nil {
t.Fatalf("Failed to detect wrong request: requested IP from different subnet")
}

ip = net.ParseIP("192.168.0.50")
_, _, err = a.RequestAddress(pid, ip, nil)
_, _, _, _, err = a.RequestAddress(pid, ip, nil)
if err != nil {
t.Fatalf("Unexpected failure: %v", err)
}
Expand Down Expand Up @@ -848,7 +848,7 @@ func TestRelease(t *testing.T) {

// Allocate all addresses
for err != ipamapi.ErrNoAvailableIPs {
_, _, err = a.RequestAddress(pid, nil, nil)
_, _, _, _, err = a.RequestAddress(pid, nil, nil)
}

toRelease := []struct {
Expand Down Expand Up @@ -887,7 +887,7 @@ func TestRelease(t *testing.T) {
t.Fatalf("Failed to update free address count after release. Expected %d, Found: %d", i+1, bm.Unselected())
}

nw, _, err := a.RequestAddress(pid, nil, nil)
nw, _, _, _, err := a.RequestAddress(pid, nil, nil)
if err != nil {
t.Fatalf("Failed to obtain the address: %s", err.Error())
}
Expand Down Expand Up @@ -954,7 +954,7 @@ func assertNRequests(t *testing.T, subnet string, numReq int, lastExpectedIP str
i := 0
start := time.Now()
for ; i < numReq; i++ {
nw, _, err = a.RequestAddress(pid, nil, nil)
nw, _, _, _, err = a.RequestAddress(pid, nil, nil)
}
if printTime {
fmt.Printf("\nTaken %v, to allocate %d addresses on %s\n", time.Since(start), numReq, subnet)
Expand All @@ -968,7 +968,7 @@ func assertNRequests(t *testing.T, subnet string, numReq int, lastExpectedIP str
func benchmarkRequest(b *testing.B, a *Allocator, subnet string) {
pid, _, _, err := a.RequestPool(localAddressSpace, subnet, "", nil, false)
for err != ipamapi.ErrNoAvailableIPs {
_, _, err = a.RequestAddress(pid, nil, nil)
_, _, _, _, err = a.RequestAddress(pid, nil, nil)
}
}

Expand Down Expand Up @@ -1019,7 +1019,7 @@ func testAllocateRandomDeallocate(t *testing.T, pool, subPool string, num int) {
indices := make(map[int]*net.IPNet, num)
allocated := make(map[string]bool, num)
for i := 0; i < num; i++ {
ip, _, err := a.RequestAddress(pid, nil, nil)
ip, _, _, _, err := a.RequestAddress(pid, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1052,7 +1052,7 @@ func testAllocateRandomDeallocate(t *testing.T, pool, subPool string, num int) {

// Request a quarter of addresses
for i := 0; i < num/2; i++ {
ip, _, err := a.RequestAddress(pid, nil, nil)
ip, _, _, _, err := a.RequestAddress(pid, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1082,7 +1082,7 @@ func TestRetrieveFromStore(t *testing.T) {
t.Fatal(err)
}
for i := 0; i < num; i++ {
if _, _, err := a.RequestAddress(pid, nil, nil); err != nil {
if _, _, _, _, err := a.RequestAddress(pid, nil, nil); err != nil {
t.Fatal(err)
}
}
Expand All @@ -1104,7 +1104,7 @@ func TestRetrieveFromStore(t *testing.T) {
t.Fatal(err)
}
for i := 0; i < num/2; i++ {
if _, _, err := a1.RequestAddress(pid, nil, nil); err != nil {
if _, _, _, _, err := a1.RequestAddress(pid, nil, nil); err != nil {
t.Fatal(err)
}
}
Expand All @@ -1121,7 +1121,7 @@ func TestRetrieveFromStore(t *testing.T) {
t.Fatal(err)
}
for i := 0; i < num/2; i++ {
if _, _, err := a2.RequestAddress(pid, nil, nil); err != nil {
if _, _, _, _, err := a2.RequestAddress(pid, nil, nil); err != nil {
t.Fatal(err)
}
}
Expand All @@ -1138,7 +1138,7 @@ func TestRetrieveFromStore(t *testing.T) {
t.Fatal(err)
}
for i := 0; i < num/2; i++ {
if _, _, err := a3.RequestAddress(pid, nil, nil); err != nil {
if _, _, _, _, err := a3.RequestAddress(pid, nil, nil); err != nil {
t.Fatal(err)
}
}
Expand Down
30 changes: 27 additions & 3 deletions ipams/remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,12 @@ func TestRemoteDriver(t *testing.T) {
ip = "172.20.0.34"
}
ip = fmt.Sprintf("%s/16", ip)
dnsList := []string{"172.20.0.1", "172.20.0.2"}
dnsSearchList := []string{"domain1", "domain2"}
return map[string]interface{}{
"Address": ip,
"Address": ip,
"DNSServers": dnsList,
"DNSSearchDomains": dnsSearchList,
}
})

Expand Down Expand Up @@ -267,16 +271,36 @@ func TestRemoteDriver(t *testing.T) {
}

// Request any address
addr, _, err := d.RequestAddress(poolID2, nil, nil)
addr, dnsList, dnsSearchDomains, _, err := d.RequestAddress(poolID2, nil, nil)
if err != nil {
t.Fatal(err)
}
if addr == nil || addr.String() != "172.20.0.34/16" {
t.Fatalf("Unexpected address: %s", addr)
}

expectedDNSList := []string{"172.20.0.1", "172.20.0.2"}
if dnsList == nil || len(dnsList) != len(expectedDNSList) {
t.Fatalf("Unexpected DNS list: %+v", dnsList)
}
for i, exp := range expectedDNSList {
if dnsList[i] != exp {
t.Fatalf("Expected DNS IP: %s, got %s", exp, dnsList[i])
}
}

expectedDNSSearchDomains := []string{"domain1", "domain2"}
if dnsSearchDomains == nil || len(dnsSearchDomains) != len(expectedDNSSearchDomains) {
t.Fatalf("Unexpected DNS Search Domains: %+v", dnsSearchDomains)
}
for i, exp := range expectedDNSSearchDomains {
if dnsSearchDomains[i] != exp {
t.Fatalf("Expected DNS Search domain: %s, got %s", exp, dnsSearchDomains[i])
}
}

// Request specific address
addr2, _, err := d.RequestAddress(poolID2, net.ParseIP("172.20.1.45"), nil)
addr2, _, _, _, err := d.RequestAddress(poolID2, net.ParseIP("172.20.1.45"), nil)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions ipams/windowsipam/windowsipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func (a *allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[s
_, ipNet, err := net.ParseCIDR(poolID)

if err != nil {
return nil, nil, err
return nil, nil, nil, nil, err
}
if prefAddress == nil {
return ipNet, nil, nil
return ipNet, nil, nil, nil, nil
}
return &net.IPNet{IP: prefAddress, Mask: ipNet.Mask}, nil, nil
return &net.IPNet{IP: prefAddress, Mask: ipNet.Mask}, nil, nil, nil, nil
}

// ReleaseAddress releases the address - always succeeds
Expand Down
4 changes: 2 additions & 2 deletions ipams/windowsipam/windowsipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestWindowsIPAM(t *testing.T) {
t.Fatal(err)
}

ip, _, err := a.RequestAddress(requestPool.String(), nil, map[string]string{})
ip, _, _, _, err := a.RequestAddress(requestPool.String(), nil, map[string]string{})
if err != nil {
t.Fatal(err)
}
Expand All @@ -55,7 +55,7 @@ func TestWindowsIPAM(t *testing.T) {
t.Fatalf("Unexpected data returned. Expected %v . Got: %v ", requestPool, ip)
}

ip, _, err = a.RequestAddress(requestPool.String(), requestAddress, map[string]string{})
ip, _, _, _, err = a.RequestAddress(requestPool.String(), requestAddress, map[string]string{})
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 2c07c9c

Please sign in to comment.