Skip to content

Conversation

@euanh
Copy link
Contributor

@euanh euanh commented May 31, 2018

This pull adds some unit tests for the changes to reject overlapping pool allocations in #2148.

@euanh
Copy link
Contributor Author

euanh commented May 31, 2018

I generated the test data with a simple Python script which does a brute force search for overlapping subnets in various configurations. I can add the script to this PR, but I'm not sure where it should go in the repo.

Generating the overlaps in this way in the test itself is likely to be too slow - the chance of two random subnets overlapping seems to be about 12% in IPv4 space and 3% in IPv6 space, so you would need lots of trials which would make the test very slow.

@codecov-io
Copy link

codecov-io commented May 31, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@809efce). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2173   +/-   ##
=========================================
  Coverage          ?   40.58%           
=========================================
  Files             ?      139           
  Lines             ?    22496           
  Branches          ?        0           
=========================================
  Hits              ?     9129           
  Misses            ?    12044           
  Partials          ?     1323
Impacted Files Coverage Δ
ipam/allocator.go 74.36% <ø> (ø)
ipam/structures.go 86.31% <ø> (ø)
types/types.go 40.78% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 809efce...a9ae874. Read the comment docs.

@fcrisciani
Copy link

@euanh the base PR got merged, can you rebase?

@euanh
Copy link
Contributor Author

euanh commented Jun 19, 2018

@fcrisciani Rebased.

@fcrisciani
Copy link

@abhi PTAL

Copy link
Contributor

@abhi abhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. Thanks for adding the comments. Its nice to test every combination in the test.
But I feel that the input testing table can be compressed considerably since its testing similar things.

ok bool
}{
// Ok: Non-overlapping left and right
{[]string{"10.0.0.0/8"}, "11.0.0.0/8", true},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some of these lists can be compressed because they test the same aspect of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for eg {[]string{"10.0.0.0/8"}, "11.0.0.0/8", true}, and {[]string{"10.0.0.0/8"}, "9.0.0.0/8", true}, are pretty much same and so are the rest of rows in "ok" .

{[]string{"10.0.0.0/8"}, "10.0.0.0/7", false}, // superset
{[]string{"10.0.0.0/8"}, "10.0.0.0/6", false}, // superset, non-canonical
{[]string{"10.0.0.0/8"}, "8.0.0.0/6", false}, // superset, canonical
{[]string{"10.0.0.0/8"}, "10.0.0.0/9", false}, // subset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{[]string{"10.0.0.0/8"}, "10.0.0.0/9", false}, and {[]string{"10.0.0.0/8"}, "10.0.0.0/16", false}, and {[]string{"10.0.0.0/8"}, "10.0.0.0/24", false} are verifying similar things ?


// IPv4
// Previously allocated network does not overlap with request
{[]string{"74.0.0.0/7"}, "9.111.99.72/30", true},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are these different from the "ok" section ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are script-generated test cases which cover the same property. I can combine them with the earlier ones and keep some of both - the 10.0.0.0 examples are easier to read and understand.

{[]string{"30.0.0.0/7"}, "31.56.203.32/27", false},
{[]string{"135.0.0.0/9"}, "135.48.0.0/16", false},

// Previously allocated network overlaps beginning of request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same this section is similar to "not ok" section ?

@fcrisciani
Copy link

@euanh can you reply/address the comments so to make progress with this PR?

@euanh
Copy link
Contributor Author

euanh commented Jun 26, 2018

@fcrisciani Yup, I took a look at @abhi's comments on Friday but then got sidetracked on #2193 yesterday. I can condense the test cases, but I still want to have a couple of point tests per category.

Originally I wanted to have a couple of point tests and a property-based test for each category, but generating suitable test data efficiently isn't straightforward.

@fcrisciani
Copy link

ping @abhi

Copy link
Contributor

@abhi abhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please squash commits

euanh added 2 commits July 4, 2018 09:50
Signed-off-by: Euan Harris <euan.harris@docker.com>
TestOverlappingRequests checks that pool requests which are supersets or
subsets of existing allocations, and those which overlap with existing
allocations at the beginning or the end.

Multiple allocation is now tested by TestOverlappingRequests, so
TestDoublePoolRelease only needs to test double releasing.

Signed-off-by: Euan Harris <euan.harris@docker.com>
@euanh
Copy link
Contributor Author

euanh commented Jul 5, 2018

@abhi I've squashed to two commits, one for comment changes and the other for test changes.

@abhi abhi merged commit 63823c6 into moby:master Jul 5, 2018
@euanh euanh deleted the ipam-check branch July 6, 2018 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants