-
Notifications
You must be signed in to change notification settings - Fork 22
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
add check that vnic with same name doesn't has the same network #109
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mgold1234 thank you for your continued work on this. Can I ask you to add tests for both positive and negative for this case? It would be useful to verify the behavior against the real oVirt engine as well as the mock facility.
hi @janosdebugs, I added test that check different network (if there is exist one, else check the same network) and same name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mgold1234 thank you so much for working on this. I know this is a tricky issue, I commented on a few corner cases that we may want to check on. Could you try and get those covered too? Thank you.
client_nic_test.go
Outdated
@@ -47,6 +47,19 @@ func assertCannotCreateNIC( | |||
} | |||
} | |||
|
|||
func assertCannotCreateNICWithSameNameDiffNetwork( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest renaming this to assertCannotCreateNICWithVNICProfile
since that more accurately covers what this function does and makes the function reusable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about assertCannotCreateNICWithSameVNICProfile?
it is not clear just with vnic profile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do that, however, we are trying to keep the assert functions reusable in other test cases. The naming should convey what the assert functions are doing rather than the current use case so future contributors feel that they can safely reuse the assert function. If the assert function alone does not convey the logic in the test case using the assert function we can always add comments explaining what's happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP
client_nic_test.go
Outdated
params ovirtclient.BuildableNICParameters, | ||
) { | ||
nic, _ := vm.CreateNIC(name, diffVNICProfile, params) | ||
if nic != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is preferable from a readability perspective to check the error, not the returned object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -34,7 +34,7 @@ func assertCanCreateNIC( | |||
return nic | |||
} | |||
|
|||
func assertCannotCreateNIC( | |||
func assertCannotCreateNICWithSameName( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name change is misleading. The error message below should also be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about -("create 2 NICs with same name %s (%v)", name, err)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janosdebugs , we have some functions for create nic:
- assertCanCreateNIC
- assertCannotCreateNICWithSameName
- assertCannotCreateNICWithVNICProfile
and more...
regarding 2 and 3 what do you suggest? if I change 2 as it was assertCannotCreateNIC, what is the differerent from 3?
maybe change it to 'assertCannotCreateNICWithName'?
and 3 will be assertCannotCreateNICWithVNICProfile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally prefer having two functions: assertCanCreateNICWithVNICProfile
and assertCannotCreateNICWithVNICProfile
. This should cover everything we need, right?
client_nic_create_test.go
Outdated
nicName, | ||
ovirtclient.CreateNICParams()) | ||
assertNICCount(t, vm, 1) | ||
DiffVNICProfile, _ := assertCanFindDiffVNICProfile(helper, helper.GetVNICProfileID()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if there is no second vnic profile? We cannot assume there is a secondary profile available. Can we create a second profile? What if the secondary profile is on the same network as the primary? Does it still work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janosdebugs , so I will change the function to catch the case that if there is no secondary profile then we will check the assertCannotCreateNICWithSameName and if we have more then 1 profile we will check this -assertCannotCreateNICWithVNICProfile.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Ideally, we'll skip the test if there is no secondary profile available. Later we can create a secondary profile to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mgold1234 thank you very much for your extensive work on this PR. There are several things to look at. The main points:
- Assert functions in this code base should use
t.Fatalf
to fail ort.Skipf
to skip a test. We skip tests if the preconditions are not met (e.g. a second network is not available), while we fail a test when an actual error happened (e.g. the engine didn't respond). - In Go please always check the returned
error
type instead of the return value. This makes the code more readable and less likely to introduce bugs. - It seems the mock implementation does not correctly implement the rules, it will fail if there is any name conflict. Since the test passes it means that there is at least one test missing. There should be a failing test on the current implementation. This test should check that you can create two NICs with the same name on different VNIC profiles or different networks (depending on your investigation). I would recommend always implementing the tests, checking if they fail, and then implementing the solution. (In this case the solution is fixing the mock.)
Since we don't know what the rules are, depending on your investigation of the naming conflict you need to implement one of the following two cases with 3 tests:
If the naming conflict applies to VNIC profiles:
- I cannot create two NICs with the same name on the VNIC profile.
- I can create two NICs with the same name on a different VNIC profile but the same network.
- I can create two NICs with the same name on different networks.
If the naming conflict applies to networks:
- I cannot create two NICs with the same name on the VNIC profile (which ever applies).
- I cannot create two NICs with the same name on a different VNIC profile but the same network.
- I can create two NICs with the same name on different networks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mgold1234 as indicated in the previous review, the test needs to fail if the correct implementation is removed. This is not the case, when removing the latest change the test still passes. Please add a test that tests this case.
@@ -21,8 +21,8 @@ func (m *mockClient) CreateNIC( | |||
return nil, newError(ENotFound, "VM with ID %s not found for NIC creation", vmid) | |||
} | |||
for _, n := range m.nics { | |||
if n.name == name { | |||
return nil, newError(ENotFound, "NIC with name %s is already in use", name) | |||
if n.name == name && m.vnicProfiles[n.vnicProfileID].networkID == m.vnicProfiles[vnicProfileID].networkID { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked in my local setup, if I remove this change the test still passes. That means that there is no test that catches this bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgold1234 this is still not resolved. If I remove this change and run the test suite the test passes. There needs to be a test that fails if this change is not added.
@janosdebugs , there is an option that I can see the result of run here, before you do the review? |
Yes, you can run the tests locally (the CI does the same) as described in the contribution guidelines. The steps taken by the CI are in this file. |
@@ -21,8 +21,8 @@ func (m *mockClient) CreateNIC( | |||
return nil, newError(ENotFound, "VM with ID %s not found for NIC creation", vmid) | |||
} | |||
for _, n := range m.nics { | |||
if n.name == name { | |||
return nil, newError(ENotFound, "NIC with name %s is already in use", name) | |||
if n.name == name && m.vnicProfiles[n.vnicProfileID].networkID == m.vnicProfiles[vnicProfileID].networkID { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgold1234 this is still not resolved. If I remove this change and run the test suite the test passes. There needs to be a test that fails if this change is not added.
@janosdebugs I looked on this example test that also implement negative test:
this test is not failure, and only catch the specfic error that appear in this case. |
@mgold1234 please remove the implementation highlighted above and run the test suite. It must fail. If I run it locally with the changes removed, it doesn't. |
@mgold1234 as discussed, we don't have capacity to pursue this edge case further at this time. Closing this PR to revisit #82 after the current release cycle. |
Please describe the change you are making
This PR fixes #82 and check that vnic doesn't has same network
Are you the owner of the code you are sending in, or do you have permission of the owner?
yes
The code will be published under the BSD 3 clause license. Have you read and understood this license?
yes