Skip to content

Commit f991a37

Browse files
committed
CLOUDSTACK-10187: Don't delete vifs for VPCs with source nat
On XenServer, both redundant router's vifs were getting deleted when any PF rule is removed from any of the acquired public IPs. This fix ensures that lastIp is set to `false` when processed by hypervisor resources to avoid removing of VIFs when VPCs have any source nat IP. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 1cbe636 commit f991a37

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

server/src/com/cloud/network/router/CommandSetupHelper.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ public void createFirewallRulesCommands(final List<? extends FirewallRule> rules
475475

476476
public void createAssociateIPCommands(final VirtualRouter router, final List<? extends PublicIpAddress> ips, final Commands cmds, final long vmId) {
477477
final String ipAssocCommand = "IPAssocCommand";
478-
createRedundantAssociateIPCommands(router, ips, cmds, ipAssocCommand, vmId);
478+
createRedundantAssociateIPCommands(router, ips, cmds, ipAssocCommand, false);
479479
}
480480

481481
public void createNetworkACLsCommands(final List<? extends NetworkACLItem> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId,
@@ -645,7 +645,7 @@ public void createVpcAssociatePublicIPCommands(final VirtualRouter router, final
645645

646646
final String ipAssocCommand = "IPAssocVpcCommand";
647647
if (router.getIsRedundantRouter()) {
648-
createRedundantAssociateIPCommands(router, ips, cmds, ipAssocCommand, 0);
648+
createRedundantAssociateIPCommands(router, ips, cmds, ipAssocCommand, true);
649649
return;
650650
}
651651

@@ -742,7 +742,7 @@ public int compare(final PublicIpAddress o1, final PublicIpAddress o2) {
742742
}
743743
}
744744

745-
public void createRedundantAssociateIPCommands(final VirtualRouter router, final List<? extends PublicIpAddress> ips, final Commands cmds, final String ipAssocCommand, final long vmId) {
745+
public void createRedundantAssociateIPCommands(final VirtualRouter router, final List<? extends PublicIpAddress> ips, final Commands cmds, final String ipAssocCommand, final boolean isVPC) {
746746

747747
// Ensure that in multiple vlans case we first send all ip addresses of
748748
// vlan1, then all ip addresses of vlan2, etc..
@@ -840,7 +840,16 @@ public int compare(final PublicIpAddress o1, final PublicIpAddress o2) {
840840
}
841841

842842
// for network if the ips does not have any rules, then only last ip
843-
List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(associatedWithNetworkId, null);
843+
final List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(associatedWithNetworkId, null);
844+
boolean hasSourceNat = false;
845+
if (isVPC && userIps.size() > 0 && userIps.get(0) != null) {
846+
// All ips should belong to a VPC
847+
final Long vpcId = userIps.get(0).getVpcId();
848+
final List<IPAddressVO> sourceNatIps = _ipAddressDao.listByAssociatedVpc(vpcId, true);
849+
if (sourceNatIps != null && sourceNatIps.size() > 0) {
850+
hasSourceNat = true;
851+
}
852+
}
844853

845854
int ipsWithrules = 0;
846855
int ipsStaticNat = 0;
@@ -864,7 +873,7 @@ public int compare(final PublicIpAddress o1, final PublicIpAddress o2) {
864873
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
865874

866875
// if there is 1 static nat then it will be checked for remove at the resource
867-
if (ipsWithrules == 0 && ipsStaticNat == 0) {
876+
if (ipsWithrules == 0 && ipsStaticNat == 0 && !hasSourceNat) {
868877
// there is only one ip address for the network.
869878
cmd.setAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP, "true");
870879
} else {

test/integration/smoke/test_vpc_redundant.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ def test_04_rvpc_network_garbage_collector_nics(self):
600600

601601
gc_wait = Configurations.list(self.apiclient, name="network.gc.wait")
602602
gc_interval = Configurations.list(self.apiclient, name="network.gc.interval")
603-
603+
604604
self.logger.debug("network.gc.wait is ==> %s" % gc_wait)
605605
self.logger.debug("network.gc.interval is ==> %s" % gc_interval)
606606

@@ -618,7 +618,7 @@ def test_04_rvpc_network_garbage_collector_nics(self):
618618

619619
@attr(tags=["advanced", "intervlan"], required_hardware="true")
620620
def test_05_rvpc_multi_tiers(self):
621-
""" Create a redundant VPC with 1 Tier, 1 VM, 1 ACL, 1 PF and test Network GC Nics"""
621+
""" Create a redundant VPC with multiple tiers"""
622622
self.logger.debug("Starting test_05_rvpc_multi_tiers")
623623
self.query_routers()
624624

0 commit comments

Comments
 (0)