Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/ip: Return correct error if container name provided exists, and test cases #280

Merged
merged 1 commit into from
Aug 12, 2016
Merged

Conversation

prateekgogia
Copy link
Contributor

@prateekgogia prateekgogia commented Aug 7, 2016

If interface name for a container provided by a user is already present,
Veth creation fails with incorrect error.
If os.IsExist error is returned by makeVethPair:

  • Check for peer name, if exists generate another random peer name,
  • else, IsExist error is due to container interface present, return error.

Fixes #155

@rosenhouse
Copy link
Contributor

@prateekgogia: Thank you for the fix. Could you please update it to follow our contribution guidelines?

Specifically:

  • Please add test coverage for your change.
  • Please format your commit message(s) according to the preferred style.

For this change, the test case is non-trivial. I'd suggest testing ip.SetupVeth by temporarily replacing rand.Reader in the BeforeEach block. You can replace it with a deterministic io.Reader (e.g. one that always returns 0s). In the It blocks you can then call SetupVeth repeatedly and write expectations on the resulting behavior. But rand.Reader is a process-global variable, so don't forget set it back to the original value (e.g. in the AfterEach() block) so as not to pollute other test cases that use it.

@prateekgogia
Copy link
Contributor Author

Hi @rosenhouse Thanks for the feedback. I am not familiar with Ginkgo testing framework. I will read about it and add the test cases soon.

@prateekgogia prateekgogia changed the title Return right error message, when veth provided by user is present pkg/ip: Return correct error for SetupVeth and test cases for SetupVeth Aug 10, 2016
@prateekgogia
Copy link
Contributor Author

Hi @rosenhouse - I have made the changes to commit message and added test cases, can you please review and let me know if anything else is required.

func peerExists(name string) bool {

link, err := netlink.LinkByName(name)
if link == nil || err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

The test suite still passes if I simplify this to

_, err := netlink.LinkByName(name)
if err != nil {
   ...

@rosenhouse
Copy link
Contributor

Hi @prateekgogia,

Thank you so much, this test coverage is a huge improvement.

I noticed a small code simplification and also left some suggestions for improving the readability of the tests. The Ginkgo / Gomega BDD style is most valuable when the Describe, Context and It blocks all read as clear sentences.

I'd ask that you fix these up, and then squash all of your commits together into a single commit that follows the aforementioned style guidelines.

Thanks!

@prateekgogia prateekgogia changed the title pkg/ip: Return correct error for SetupVeth and test cases for SetupVeth pkg/ip: Return correct error if container name provided exists, and test cases Aug 11, 2016
@prateekgogia
Copy link
Contributor Author

@rosenhouse: updated and squashed all commits in one commit. Thanks for the review :)

@@ -41,6 +41,15 @@ func makeVethPair(name, peer string, mtu int) (netlink.Link, error) {
return veth, nil
}

func peerExists(name string) bool {

Copy link
Member

Choose a reason for hiding this comment

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

Please remove this empty line.

…est cases

If interface name for a container provided by a user is already present,
Veth creation fails with incorrect error.
If os.IsExist error is returned by makeVethPair:
* Check for peer name, if exists generate another random peer name,
* else, IsExist error is due to container interface present, return error.

Fixes #155
@prateekgogia
Copy link
Contributor Author

@rosenhouse @jellonek addressed.

@rosenhouse
Copy link
Contributor

LGTM. Any other @containernetworking/cni-maintainers want to give the second 👍 ?

@jellonek
Copy link
Member

LGTM, but i'm not maintainer.

@tomdee
Copy link
Member

tomdee commented Aug 12, 2016

LGTM - merging.

@tomdee tomdee merged commit 113dfd6 into containernetworking:master Aug 12, 2016
@prateekgogia prateekgogia deleted the bug-fix-155 branch August 12, 2016 20:17
@tomdee tomdee mentioned this pull request Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants