-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CLOUDSTACK-9317: Enable/disable static NAT associates only relevant IPs. #1450
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
Conversation
| List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null); | ||
| // get the list of public ip's that need to be applied for the static NAT. manipulating only these | ||
| // ips prevents concurrency issues when disabling static nat at the same time. | ||
| List<IPAddressVO> userIps = new ArrayList<>(); |
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.
Hi @ProjectMoon, what about creating a method that returns the userIps list. This new method would contain lines 1719-1722. Then, you would be able to write a unit test and add lines 1717-1718 as its java documentation.
|
I added a basic test now and moved the method out @rafaelweingartner. Maybe there are more scenarios that can be tested? |
| List<IPAddressVO> ips = _ipManager.getStaticNatSourceIps(Collections.singletonList(snat)); | ||
| Assert.assertNotNull(ips); | ||
| Assert.assertEquals(1, ips.size()); | ||
|
|
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 also add a check here to confirm that the ipAddrDao.findById was called only once.
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.
How is it possible to do that with JUnit?
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.
You do not use JUnit for that.
You use your mock API such as easy mock or mockito that we use here.
you can do something like this:
Mockito.verify(mock, Mockito.times(1)).method(parameter);
|
It is always great to see parts of a bigger method being extracted to smaller ones, and then test cases and java docs being used. I believe the tests like you did are ok, I would only add another assert there as I pointed out at line 67 of the test class. |
| if (firstIP) { | ||
| sourceNat = true; | ||
| /* enable sourceNAT for the first ip of the public interface as long as it's source nat. */ | ||
| if (firstIP && !sourceNat) { |
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.
For additional public subnet case, sourceNat should be set to 'true' to add a source nat rule on VR for the first ip in that subnet. This changes will break that.
If there is no source nat rule for the additional public subnet the traffic to this subnet from he VMs always go through the default source nat interface.
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.
How do I trigger this case using the CS API? Is it by adding multiple NICs to the virtual router?
|
@ProjectMoon According to that comment on line 781 in |
|
@cristofolini The idea was that the source NAT IP is always the first IP. Not sure if the logic is correct. But apparently I need to correct the logic for the case @jayapalu mentioned. |
CI RESULTSAssociated Uploads
Uploads will be available until Comment created by |
|
Can I get some code review on this one? Thx... |
|
tag:needsreview |
|
It would be useful for someone knowledgeable in the network internals to elaborate on @jayapalu's comment. We currently do not use the feature he's talking about, so it would be helpful if someone could direct me where to find setup instructions for that case. |
|
CI is clean and everything is green. I need some code review on this one. Thanks... |
|
Rebased against latest 4.7. |
ACS CI BVT RunSumarry: Link to logs Folder (search by build_no): https://www.dropbox.com/sh/yj3wnzbceo9uef2/AAB6u-Iap-xztdm6jHX9SjPja?dl=0 Failed tests: Skipped tests: Passed test suits: |
|
Updated to latest 4.7. |
|
Closing to reopen against 4.8. |
|
I tested this patch with below steps. It is not removing the ip addresses on the VR interface. Some times observed that even there is one ip with static nat but the interface got removed. Steps to test this:
In another case in step4 disable static nat on only 3 public ip addresses. |
|
@jayapalu Can you post this in the new version of the fix? (And possibly re-test, if you were using an older version) |
|
@ProjectMoon |
|
@ProjectMoon |
This pull request fixes a concurrency issue when disabling static NAT on a bunch of IPs simultaneously. Under the old behavior, executing multiple disable requests would result in invalid IP associations being sent to the virtual router. This commit changes the behavior to apply an IP association for only the IP being added/released, which means that it is impossible for the virtual router to receive invalid data.
This was tested against a virtual router running on KVM and VMware. It would be nice to have some input how this change could affect redundant routers and other static NAT providers.