Skip to content

Commit d97ccb2

Browse files
committed
bugfix #2 vpc vr: fix issue if static nat is disabled but still other IP used by lb/pf
1 parent 78b947d commit d97ccb2

File tree

6 files changed

+51
-43
lines changed

6 files changed

+51
-43
lines changed

server/src/main/java/com/cloud/network/rules/NicPlugInOutRules.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.cloud.network.Networks.BroadcastDomainType;
4141
import com.cloud.network.Networks.IsolationType;
4242
import com.cloud.network.PublicIpAddress;
43+
import com.cloud.network.dao.FirewallRulesDao;
4344
import com.cloud.network.dao.IPAddressDao;
4445
import com.cloud.network.dao.IPAddressVO;
4546
import com.cloud.network.router.VirtualRouter;
@@ -189,6 +190,7 @@ private Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> getNics
189190
VpcManager vpcMgr = visitor.getVirtualNetworkApplianceFactory().getVpcMgr();
190191
NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao();
191192
IPAddressDao ipAddressDao = visitor.getVirtualNetworkApplianceFactory().getIpAddressDao();
193+
FirewallRulesDao rulesDao = visitor.getVirtualNetworkApplianceFactory().getFirewallRulesDao();
192194

193195
// find out nics to unplug
194196
for (PublicIpAddress ip : _ipAddresses) {
@@ -206,7 +208,10 @@ private Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> getNics
206208
final List<IPAddressVO> allIps = ipAddressDao.listByAssociatedVpc(ip.getVpcId(), null);
207209
boolean ipUpdated = false;
208210
for (IPAddressVO allIp : allIps) {
209-
if (allIp.getId() != ip.getId() && allIp.getVlanId() == ip.getVlanId() && allIp.getVmIp() != null) {
211+
if (allIp.getId() != ip.getId() && allIp.getVlanId() == ip.getVlanId()
212+
&& (allIp.isSourceNat()
213+
|| rulesDao.countRulesByIpIdAndState(allIp.getId(), FirewallRule.State.Active) > 0
214+
|| (allIp.isOneToOneNat() && allIp.getRuleState() == null))) {
210215
s_logger.debug("Updating the nic " + nic + " with new ip address " + allIp.getAddress().addr());
211216
nic.setIPv4Address(allIp.getAddress().addr());
212217
nicDao.update(nic.getId(), nic);

server/src/main/java/com/cloud/network/rules/VirtualNetworkApplianceFactory.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.cloud.dc.dao.VlanDao;
2727
import com.cloud.network.IpAddressManager;
2828
import com.cloud.network.NetworkModel;
29+
import com.cloud.network.dao.FirewallRulesDao;
2930
import com.cloud.network.dao.IPAddressDao;
3031
import com.cloud.network.dao.LoadBalancerDao;
3132
import com.cloud.network.dao.NetworkDao;
@@ -85,6 +86,8 @@ public class VirtualNetworkApplianceFactory {
8586
private IpAddressManager _ipAddrMgr;
8687
@Inject
8788
private NetworkACLManager _networkACLMgr;
89+
@Inject
90+
private FirewallRulesDao _rulesDao;
8891

8992
@Autowired
9093
@Qualifier("networkHelper")
@@ -183,4 +186,8 @@ public NicProfileHelper getNicProfileHelper() {
183186
public NetworkTopologyContext getNetworkTopologyContext() {
184187
return _networkTopologyContext;
185188
}
189+
190+
public FirewallRulesDao getFirewallRulesDao() {
191+
return _rulesDao;
192+
}
186193
}

test/integration/component/test_multiple_subnets_in_isolated_network.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
NetworkOffering,
3636
VPC,
3737
VpcOffering,
38+
StaticNATRule,
3839
NATRule,
3940
PublicIPAddress,
4041
PublicIpRange)
@@ -247,7 +248,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
247248
# verify the IPs in VR. eth0 -> guest nic IP, eth2 -> source nat IP
248249
249250
# 6. create new public ip range 1
250-
# 7. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm
251+
# 7. get a free ip 4 in new ip range 2, assign to network, and enable static nat to vm
251252
# verify the available nics in VR should be "eth0,eth1,eth2,eth3"
252253
# verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 1
253254
# 8. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm
@@ -395,7 +396,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
395396
)
396397
self.cleanup.append(self.public_ip_range1)
397398

398-
# 7. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm
399+
# 7. get a free ip 4 in new ip range 2, assign to network, and enable static nat to vm
399400
ip_address_1 = self.get_free_ipaddress(self.public_ip_range1.vlan.id)
400401
ipaddress_1 = PublicIPAddress.create(
401402
self.apiclient,
@@ -404,12 +405,11 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
404405
ipaddress=ip_address_1
405406
)
406407

407-
nat_rule = NATRule.create(
408+
StaticNATRule.enable(
408409
self.apiclient,
409-
self.virtual_machine1,
410-
self.services["natrule"],
410+
virtualmachineid=self.virtual_machine1.id,
411411
ipaddressid=ipaddress_1.ipaddress.id,
412-
openfirewall=True
412+
networkid=self.network1.id
413413
)
414414

415415
# verify the available nics in VR should be "eth0,eth1,eth2,eth3"
@@ -544,12 +544,11 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
544544
ipaddress=ip_address_4
545545
)
546546

547-
nat_rule = NATRule.create(
547+
StaticNATRule.enable(
548548
self.apiclient,
549-
self.virtual_machine1,
550-
self.services["natrule"],
549+
virtualmachineid=self.virtual_machine1.id,
551550
ipaddressid=ipaddress_4.ipaddress.id,
552-
openfirewall=True
551+
networkid=self.network1.id
553552
)
554553

555554

test/integration/component/test_multiple_subnets_in_isolated_network_rvr.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
NetworkOffering,
3636
VPC,
3737
VpcOffering,
38+
StaticNATRule,
3839
NATRule,
3940
PublicIPAddress,
4041
PublicIpRange)
@@ -247,7 +248,7 @@ def test_02_acquire_public_ips_in_isolated_network_with_redundant_vrs(self):
247248
# verify the IPs in VR. eth0 -> guest nic IP, eth2 -> source nat IP
248249
249250
# 6. create new public ip range 1
250-
# 7. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm
251+
# 7. get a free ip 4 in new ip range 2, assign to network, and enable static nat to vm
251252
# verify the available nics in VR should be "eth0,eth1,eth2,eth3"
252253
# verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 1
253254
# 8. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm
@@ -395,7 +396,7 @@ def test_02_acquire_public_ips_in_isolated_network_with_redundant_vrs(self):
395396
)
396397
self.cleanup.append(self.public_ip_range1)
397398

398-
# 7. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm
399+
# 7. get a free ip 4 in new ip range 2, assign to network, and enable static nat to vm
399400
ip_address_1 = self.get_free_ipaddress(self.public_ip_range1.vlan.id)
400401
ipaddress_1 = PublicIPAddress.create(
401402
self.apiclient,
@@ -404,12 +405,11 @@ def test_02_acquire_public_ips_in_isolated_network_with_redundant_vrs(self):
404405
ipaddress=ip_address_1
405406
)
406407

407-
nat_rule = NATRule.create(
408+
StaticNATRule.enable(
408409
self.apiclient,
409-
self.virtual_machine1,
410-
self.services["natrule"],
410+
virtualmachineid=self.virtual_machine1.id,
411411
ipaddressid=ipaddress_1.ipaddress.id,
412-
openfirewall=True
412+
networkid=self.network1.id
413413
)
414414

415415
# verify the available nics in VR should be "eth0,eth1,eth2,eth3"
@@ -544,12 +544,11 @@ def test_02_acquire_public_ips_in_isolated_network_with_redundant_vrs(self):
544544
ipaddress=ip_address_4
545545
)
546546

547-
nat_rule = NATRule.create(
547+
StaticNATRule.enable(
548548
self.apiclient,
549-
self.virtual_machine1,
550-
self.services["natrule"],
549+
virtualmachineid=self.virtual_machine1.id,
551550
ipaddressid=ipaddress_4.ipaddress.id,
552-
openfirewall=True
551+
networkid=self.network1.id
553552
)
554553

555554

test/integration/component/test_multiple_subnets_in_vpc.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
NetworkOffering,
3636
VPC,
3737
VpcOffering,
38+
StaticNATRule,
3839
NATRule,
3940
PublicIPAddress,
4041
PublicIpRange)
@@ -272,7 +273,7 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
272273
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> tier 1, eth3 -> new ip 3, eth4 -> tier 2
273274
274275
# 13. create new public ip range 2
275-
# 14. get a free ip 4 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm
276+
# 14. get a free ip 4 in new ip range 2, assign to network, and enable static nat to vm 2 in tier 2
276277
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,eth5,"
277278
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> tier 1, eth3 -> new ip 3, eth4 -> tier 2, eth5 -> new ip 4
278279
# 15. get a free ip 5 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm
@@ -451,10 +452,9 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
451452
ipaddress=ip_address_1
452453
)
453454

454-
nat_rule = NATRule.create(
455+
StaticNATRule.enable(
455456
self.apiclient,
456-
self.virtual_machine1,
457-
self.services["natrule"],
457+
virtualmachineid=self.virtual_machine1.id,
458458
ipaddressid=ipaddress_1.ipaddress.id,
459459
networkid=vpc_tier_1.id
460460
)
@@ -581,7 +581,7 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
581581
)
582582

583583
try:
584-
self.virtual_machine1 = VirtualMachine.create(
584+
self.virtual_machine2 = VirtualMachine.create(
585585
self.apiclient,
586586
self.services["virtual_machine"],
587587
accountid=self.account1.name,
@@ -621,7 +621,7 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
621621
)
622622
self.cleanup.append(self.public_ip_range2)
623623

624-
# 14. get a free ip 4 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm
624+
# 14. get a free ip 4 in new ip range 2, assign to network, and enable static nat to vm 2 in tier 2
625625
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,eth5,"
626626
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> tier 1, eth3 -> new ip 3, eth4 -> tier 2, eth5 -> new ip 4
627627
ip_address_4 = self.get_free_ipaddress(self.public_ip_range2.vlan.id)
@@ -632,10 +632,9 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
632632
ipaddress=ip_address_4
633633
)
634634

635-
nat_rule = NATRule.create(
635+
StaticNATRule.enable(
636636
self.apiclient,
637-
self.virtual_machine1,
638-
self.services["natrule"],
637+
virtualmachineid=self.virtual_machine2.id,
639638
ipaddressid=ipaddress_4.ipaddress.id,
640639
networkid=vpc_tier_2.id
641640
)
@@ -665,7 +664,7 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
665664

666665
nat_rule = NATRule.create(
667666
self.apiclient,
668-
self.virtual_machine1,
667+
self.virtual_machine2,
669668
self.services["natrule"],
670669
ipaddressid=ipaddress_5.ipaddress.id,
671670
networkid=vpc_tier_2.id
@@ -696,7 +695,7 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
696695

697696
nat_rule = NATRule.create(
698697
self.apiclient,
699-
self.virtual_machine1,
698+
self.virtual_machine2,
700699
self.services["natrule"],
701700
ipaddressid=ipaddress_6.ipaddress.id,
702701
networkid=vpc_tier_2.id

test/integration/component/test_multiple_subnets_in_vpc_rvr.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
NetworkOffering,
3636
VPC,
3737
VpcOffering,
38+
StaticNATRule,
3839
NATRule,
3940
PublicIPAddress,
4041
PublicIpRange)
@@ -272,7 +273,7 @@ def test_04_acquire_public_ips_in_vpc_with_redundant_vrs(self):
272273
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> tier 1, eth3 -> new ip 3, eth4 -> tier 2
273274
274275
# 13. create new public ip range 2
275-
# 14. get a free ip 4 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm
276+
# 14. get a free ip 4 in new ip range 2, assign to network, and enable static nat to vm 2 in tier 2
276277
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,eth5,"
277278
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> tier 1, eth3 -> new ip 3, eth4 -> tier 2, eth5 -> new ip 4
278279
# 15. get a free ip 5 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm
@@ -451,10 +452,9 @@ def test_04_acquire_public_ips_in_vpc_with_redundant_vrs(self):
451452
ipaddress=ip_address_1
452453
)
453454

454-
nat_rule = NATRule.create(
455+
StaticNATRule.enable(
455456
self.apiclient,
456-
self.virtual_machine1,
457-
self.services["natrule"],
457+
virtualmachineid=self.virtual_machine1.id,
458458
ipaddressid=ipaddress_1.ipaddress.id,
459459
networkid=vpc_tier_1.id
460460
)
@@ -581,7 +581,7 @@ def test_04_acquire_public_ips_in_vpc_with_redundant_vrs(self):
581581
)
582582

583583
try:
584-
self.virtual_machine1 = VirtualMachine.create(
584+
self.virtual_machine2 = VirtualMachine.create(
585585
self.apiclient,
586586
self.services["virtual_machine"],
587587
accountid=self.account1.name,
@@ -621,7 +621,7 @@ def test_04_acquire_public_ips_in_vpc_with_redundant_vrs(self):
621621
)
622622
self.cleanup.append(self.public_ip_range2)
623623

624-
# 14. get a free ip 4 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm
624+
# 14. get a free ip 4 in new ip range 2, assign to network, and enable static nat to vm 2 in tier 2
625625
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,eth5,"
626626
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> tier 1, eth3 -> new ip 3, eth4 -> tier 2, eth5 -> new ip 4
627627
ip_address_4 = self.get_free_ipaddress(self.public_ip_range2.vlan.id)
@@ -632,10 +632,9 @@ def test_04_acquire_public_ips_in_vpc_with_redundant_vrs(self):
632632
ipaddress=ip_address_4
633633
)
634634

635-
nat_rule = NATRule.create(
635+
StaticNATRule.enable(
636636
self.apiclient,
637-
self.virtual_machine1,
638-
self.services["natrule"],
637+
virtualmachineid=self.virtual_machine2.id,
639638
ipaddressid=ipaddress_4.ipaddress.id,
640639
networkid=vpc_tier_2.id
641640
)
@@ -665,7 +664,7 @@ def test_04_acquire_public_ips_in_vpc_with_redundant_vrs(self):
665664

666665
nat_rule = NATRule.create(
667666
self.apiclient,
668-
self.virtual_machine1,
667+
self.virtual_machine2,
669668
self.services["natrule"],
670669
ipaddressid=ipaddress_5.ipaddress.id,
671670
networkid=vpc_tier_2.id
@@ -696,7 +695,7 @@ def test_04_acquire_public_ips_in_vpc_with_redundant_vrs(self):
696695

697696
nat_rule = NATRule.create(
698697
self.apiclient,
699-
self.virtual_machine1,
698+
self.virtual_machine2,
700699
self.services["natrule"],
701700
ipaddressid=ipaddress_6.ipaddress.id,
702701
networkid=vpc_tier_2.id

0 commit comments

Comments
 (0)