-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -780,10 +780,11 @@ public int compare(final PublicIpAddress o1, final PublicIpAddress o2) { | |
|
|
||
| final boolean add = ipAddr.getState() == IpAddress.State.Releasing ? false : true; | ||
| boolean sourceNat = ipAddr.isSourceNat(); | ||
| /* enable sourceNAT for the first ip of the public interface */ | ||
| if (firstIP) { | ||
| sourceNat = true; | ||
| /* enable sourceNAT for the first ip of the public interface as long as it's source nat. */ | ||
| if (firstIP && !sourceNat) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
| firstIP = false; | ||
| } | ||
|
|
||
| final String vlanId = ipAddr.getVlanTag(); | ||
| final String vlanGateway = ipAddr.getGateway(); | ||
| final String vlanNetmask = ipAddr.getNetmask(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package com.cloud.network; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
| import com.cloud.network.dao.IPAddressDao; | ||
| import com.cloud.network.dao.IPAddressVO; | ||
| import com.cloud.network.rules.StaticNat; | ||
| import com.cloud.network.rules.StaticNatImpl; | ||
| import com.cloud.utils.net.Ip; | ||
|
|
||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static org.mockito.Mockito.anyLong; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| public class IpAddressManagerTest { | ||
|
|
||
| @Mock | ||
| IPAddressDao _ipAddrDao; | ||
|
|
||
| @InjectMocks | ||
| IpAddressManagerImpl _ipManager; | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| MockitoAnnotations.initMocks(this); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetStaticNatSourceIps() { | ||
| String publicIpAddress = "192.168.1.3"; | ||
| IPAddressVO vo = mock(IPAddressVO.class); | ||
| when(vo.getAddress()).thenReturn(new Ip(publicIpAddress)); | ||
| when(vo.getId()).thenReturn(1l); | ||
|
|
||
| when(_ipAddrDao.findById(anyLong())).thenReturn(vo); | ||
| StaticNat snat = new StaticNatImpl(1, 1, 1, 1, publicIpAddress, false); | ||
|
|
||
| List<IPAddressVO> ips = _ipManager.getStaticNatSourceIps(Collections.singletonList(snat)); | ||
| Assert.assertNotNull(ips); | ||
| Assert.assertEquals(1, ips.size()); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is it possible to do that with JUnit?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You do not use JUnit for that. you can do something like this: |
||
| IPAddressVO returnedVO = ips.get(0); | ||
| Assert.assertEquals(vo, returnedVO); | ||
| } | ||
| } | ||
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 know this is not your code; but, what about changing "staticNats == null || staticNats.size() == 0" to "CollectionUtils.isEmpty(staticNats)"