Skip to content

Test overlapping pool allocation - #2173

Merged
abhi merged 2 commits into
moby:masterfrom
euanh:ipam-check
Jul 5, 2018
Merged

Test overlapping pool allocation#2173
abhi merged 2 commits into
moby:masterfrom
euanh:ipam-check

Conversation

@euanh

Copy link
Copy Markdown
Contributor

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

@euanh

euanh commented May 31, 2018

Copy link
Copy Markdown
ContributorAuthor

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

codecov-io commented May 31, 2018

Copy link
Copy Markdown

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 FilesCoverage Δ
ipam/allocator.go74.36% <ø> (ø)
ipam/structures.go86.31% <ø> (ø)
types/types.go40.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
Copy Markdown

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

@euanh

Copy link
Copy Markdown
ContributorAuthor

@fcrisciani Rebased.

@fcrisciani

Copy link
Copy Markdown

@abhi PTAL

@abhiabhi left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadipam/allocator_test.go Outdated
ok bool
}{
// Ok: Non-overlapping left and right
{[]string{"10.0.0.0/8"}, "11.0.0.0/8", true},

Copy link
Copy Markdown
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
Copy Markdown
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" .

Comment threadipam/allocator_test.go Outdated
{[]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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown

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

@euanh

Copy link
Copy Markdown
ContributorAuthor

@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
Copy Markdown

ping @abhi

abhi
abhi approved these changes Jul 3, 2018

@abhiabhi left a comment

Copy link
Copy Markdown
Contributor

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

euanh commented Jul 5, 2018

Copy link
Copy Markdown
ContributorAuthor

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

abhi
abhi approved these changes Jul 5, 2018
@abhi
abhi merged commit 63823c6 into moby:masterJul 5, 2018
@euanh
euanh deleted the ipam-check branch July 6, 2018 09:04
Sign up for freeto 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

@euanh@codecov-io@fcrisciani@abhi