Uh oh!
There was an error while loading. Please reload this page.
CLOUDSTACK-9317: Enable/disable static NAT associates only relevant IPs. - #1450
CLOUDSTACK-9317: Enable/disable static NAT associates only relevant IPs.#1450ProjectMoon wants to merge 1 commit into
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.
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.
ProjectMoon
commented
Mar 23, 2016
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.
I would also add a check here to confirm that the ipAddrDao.findById was called only once.
There was a problem hiding this comment.
How is it possible to do that with JUnit?
There was a problem hiding this comment.
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);
rafaelweingartner
commented
Mar 24, 2016
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.
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.
How do I trigger this case using the CS API? Is it by adding multiple NICs to the virtual router?
cristofolini
commented
Mar 27, 2016
@ProjectMoon According to that comment on line 781 in |
ProjectMoon
commented
Mar 29, 2016
@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. |
swill
commented
May 12, 2016
CI RESULTSAssociated Uploads
Uploads will be available until Comment created by |
swill
commented
May 12, 2016
Can I get some code review on this one? Thx... |
DaanHoogland
commented
May 12, 2016
tag:needsreview |
ProjectMoon
commented
May 13, 2016
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. |
swill
commented
May 26, 2016
CI is clean and everything is green. I need some code review on this one. Thanks... |
ProjectMoon
commented
May 26, 2016
Rebased against latest 4.7. |
bvbharatk
commented
Jun 7, 2016
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: |
ProjectMoon
commented
Aug 2, 2016
Updated to latest 4.7. |
ProjectMoon
commented
Aug 2, 2016
Closing to reopen against 4.8. |
jayapalu
commented
Jan 12, 2017
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. |
ProjectMoon
commented
Jan 12, 2017
@jayapalu Can you post this in the new version of the fix? (And possibly re-test, if you were using an older version) |
@ProjectMoon |
jayapalu
commented
Jan 17, 2017
@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.