Skip to content

Conversation

@csfmomo
Copy link
Contributor

@csfmomo csfmomo commented Oct 23, 2020

feat: Add NC version in SecondaryIPConfig structure.

Reason for Change:
When CNS reconcile, it needs NC version to determine whether an IP should be stay in pending programming or available.

  • [X ] adds unit tests

@codecov
Copy link

codecov bot commented Oct 23, 2020

Codecov Report

Merging #701 into master will decrease coverage by 0.23%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #701      +/-   ##
==========================================
- Coverage   38.84%   38.61%   -0.24%     
==========================================
  Files          79       79              
  Lines       10471    10479       +8     
==========================================
- Hits         4067     4046      -21     
- Misses       5912     5938      +26     
- Partials      492      495       +3     

@neaggarwMS
Copy link
Member

There is no change in the reconcile funntion? can you also cover it here? That will complete the NC version check for all scenarios .

@csfmomo
Copy link
Contributor Author

csfmomo commented Oct 27, 2020

There is no change in the reconcile funntion? can you also cover it here? That will complete the NC version check for all scenarios .

Discussed offline. We'll use a separate PR to address this scenario.

@csfmomo csfmomo closed this Oct 27, 2020
@csfmomo csfmomo reopened this Oct 27, 2020
Copy link
Contributor

@ramiro-gamarra ramiro-gamarra left a comment

Choose a reason for hiding this comment

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

Some comments

ipSubnet.PrefixLength = uint8(size)
ncRequest.IPConfiguration.IPSubnet = ipSubnet
ncRequest.IPConfiguration.GatewayIPAddress = nc.DefaultGateway
ncVersion, _ := strconv.Atoi(ncRequest.Version)
Copy link
Contributor

Choose a reason for hiding this comment

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

should probably bubble the error to be safe

}

func validateSecondaryIPsNCVersion(t *testing.T, req cns.CreateNetworkContainerRequest) {
containerStatus := svc.state.ContainerStatus[req.NetworkContainerid]
Copy link
Contributor

Choose a reason for hiding this comment

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

Couple of things:

  • Reading state should be mutex guarded
  • You should also check that the map actually contains an entry for the nc id

Copy link
Contributor Author

@csfmomo csfmomo Oct 28, 2020

Choose a reason for hiding this comment

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

  • This is a validation code in test file. I don't think mutex guard is necessary. No others have access to svc.state.
  • Not necessary. If it doesn't exist, test will fail.

if (secIPConfig.IPAddress == "10.0.0.16" && secIPConfig.NCVersion != 0) ||
(secIPConfig.IPAddress == "10.0.0.17" && secIPConfig.NCVersion != 1) {
t.Fatalf("nc request version is %d, secondary ip %s nc version is %d, expected nc version is 0",
ncVersion, secIPConfig.IPAddress, secIPConfig.NCVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

These assertion values (the expected ip addresses and versions) are very far from the test. If you need to create similar tests with different IP addresses, this would not be very reusable. You should define the expected values on the test, and pass them to this function. The check is also very narrow: if there was only a secondary IP of 10.0.0.15 for example, this would pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. This test is designed specifically and is validating specific scenario.
In this specific test, secondary IP address only contains 10.0.0.16 and 10.0.0.17.
10.0.0.16 must be version 0 and 10.0.0.17 must be version 1.

for ipId, ipconfig := range ipconfigs {
// New secondary IP configs has new NC version however, CNS don't want to override existing IPs'with new NC version
// Set it back to previous NC version if IP already exist.
if existingIPConfig, existsInPreviousIPConfig := existingSecondaryIPConfigs[ipId]; existsInPreviousIPConfig && existingIPConfig.IPAddress == ipconfig.IPAddress {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the check on ip address equality necessary?

Copy link
Contributor Author

@csfmomo csfmomo Oct 28, 2020

Choose a reason for hiding this comment

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

I think it's necessary. If uuid is the same, IPAddress must be same. If not the same, then sth wrong. At least we don't want to set the NC version back.
In other way, I don't see any drawback to double check IPAddress.

}

func validateSecondaryIPsNCVersion(t *testing.T, req cns.CreateNetworkContainerRequest) {
containerStatus := svc.state.ContainerStatus[req.NetworkContainerid]
Copy link
Member

Choose a reason for hiding this comment

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

This function seems generic but inside it has hardcoded the ipaddress and expected version. Can we pass the expected SecondaryIpConfig as parameter and compare the req with expected list? This will allow to reuse this function in future as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can but I don't think it's necessary. I don't think any other test should reuse this function. This validation is designed for TestCreateAndUpdateNCWithSecondaryIPNCVersion specifically.

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 moved this validation to test function and avoid confusion.

Copy link
Contributor

@ramiro-gamarra ramiro-gamarra left a comment

Choose a reason for hiding this comment

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

Few more comments

req := createNCReqInternal(t, secondaryIPConfigs, ncID, strconv.Itoa(ncVersion))
containerStatus := svc.state.ContainerStatus[req.NetworkContainerid]
// Validate secondary IPs' NC version has been updated by NC request
receivedSecondaryIPConfigs = containerStatus.CreateNetworkContainerRequest.SecondaryIPConfigs
Copy link
Contributor

Choose a reason for hiding this comment

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

  • no need to make a map in line 59, just use := here
  • the reason why a check for existence of entry in the map is better is that the test won't fail if there is no match. If you don't get the check for existence, you get the zero value of a struct, including all of it's members recursively, and ranging over a nil map is valid. In case the nc id was not found in the map, the checks below will not happen, and the test will continue as normal. Let me know if that makes sense.

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 think what you are trying to say is adding one more check in map length. I can do that though it's not the key point in this test.

// Though "10.0.0.16" IP exists in NC version 1, secodanry IP still keep its original NC version 0
if (secIPConfig.IPAddress == "10.0.0.16" && secIPConfig.NCVersion != 0) ||
(secIPConfig.IPAddress == "10.0.0.17" && secIPConfig.NCVersion != 1) {
t.Fatalf("nc request version is %d, secondary ip %s nc version is %d, expected nc version is 0",
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer a switch statement here, and messages more specific to each. in case the inconsistent version was with 10.0.0.17, the message still tells you that it expected 0, which is not appropriate:

switch secIPConfig:
case "10.0.0.16":
    // check for 0
case "10.0.0.17":
    // check for 1
default:
    // error since this is unexpected

@csfmomo csfmomo dismissed neaggarwMS’s stale review October 29, 2020 17:53

Discussed offline, it's ready to merge.

@csfmomo csfmomo merged commit 6fad74d into Azure:master Oct 29, 2020
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.

3 participants