Skip to content

Conversation

@behzad-mir
Copy link
Contributor

@behzad-mir behzad-mir commented Sep 8, 2022

The issue is that right now with an IP "172.168.1.1/24" networkName "azure" and multitenancy id "1", we expect the function to return "azure-vlan1-172.168.1-0_24" but instead it returns "azure-vlan1-172.168.1-1_24"

This PR is fixing the issue by parsing the CIDR correctly.

ipAddrNet := ipamAddResult.ipv4Result.IPs[0].Address
_, ipNet, err := net.ParseCIDR(ipAddrNet.String())
if err != nil {
log.Printf("Error parsing network CIDR: %v.", err)
Copy link
Member

Choose a reason for hiding this comment

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

log ipAddrNet.String() as well in error case

@tamilmani1989 tamilmani1989 changed the title fix: fixing the CIDR format of getNetworkName() on Windows plus adding a unti test for the function fix: fixing the CIDR format of getNetworkName() on Windows Sep 8, 2022
@behzad-mir behzad-mir force-pushed the behzadm-networkWindows-Multitenancy branch from 9ade267 to fc7545f Compare September 9, 2022 21:48
tamilmani1989
tamilmani1989 previously approved these changes Sep 9, 2022
Copy link
Member

@tamilmani1989 tamilmani1989 left a comment

Choose a reason for hiding this comment

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

lgtm

@behzad-mir
Copy link
Contributor Author

lgtm

I'll merge it after the multi-tenancy swift test is done

@tamilmani1989
Copy link
Member

lgtm

I'll merge it after the multi-tenancy swift test is done

Let also e2e and lint succeed

@behzad-mir behzad-mir force-pushed the behzadm-networkWindows-Multitenancy branch 2 times, most recently from ecddde8 to 7c6dec2 Compare September 9, 2022 22:57
tamilmani1989
tamilmani1989 previously approved these changes Sep 9, 2022
@behzad-mir behzad-mir force-pushed the behzadm-networkWindows-Multitenancy branch from 1d87d75 to f18ffc8 Compare September 12, 2022 17:20
@behzad-mir behzad-mir requested a review from vipul-21 September 12, 2022 18:33
@behzad-mir behzad-mir force-pushed the behzadm-networkWindows-Multitenancy branch from f18ffc8 to 42ff151 Compare September 12, 2022 18:35
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
networkName, err := tt.plugin.getNetworkName(tt.netNs, tt.ipamAddResult, tt.nwCfg)
Copy link
Contributor

@vipul-21 vipul-21 Sep 12, 2022

Choose a reason for hiding this comment

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

Do we want to cover the error case scenario as well ? Since this test case is checking the happy path right now. Want to understand the code coverage aspect we take into consideration while writing these tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point we only wanted to make sure that we're producing correct CIDR when the CNS response is valid. Seems that the failure path is not that critical for unit test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Checking the failure cases is absolutely critical in unit tests, come on. You should at least be testing that the input validation that you added correctly returns the error that you added when the input is invalid. How else do you know it rejects bad inputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the unit test that was asked for this particular case. Yes, in general unit test is critical for non-happy paths. I didn't consider it critical here, since I was informed malformed CIDR is not reaching to this function. Nevertheless, I will add a test case for malformed CIDR since it is the only error check that I have added.

vipul-21
vipul-21 previously approved these changes Sep 12, 2022
@behzad-mir behzad-mir force-pushed the behzadm-networkWindows-Multitenancy branch from 42ff151 to 26ce90f Compare September 12, 2022 21:33
Copy link
Collaborator

@rbtr rbtr left a comment

Choose a reason for hiding this comment

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

@vipul-21 was right to call out the incomplete UT, please finish those.

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
networkName, err := tt.plugin.getNetworkName(tt.netNs, tt.ipamAddResult, tt.nwCfg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Checking the failure cases is absolutely critical in unit tests, come on. You should at least be testing that the input validation that you added correctly returns the error that you added when the input is invalid. How else do you know it rejects bad inputs?

@behzad-mir behzad-mir merged commit afdee48 into master Sep 13, 2022
@behzad-mir behzad-mir deleted the behzadm-networkWindows-Multitenancy branch September 13, 2022 21:37
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.

5 participants