Skip to content

Commit

Permalink
Dynamic: fix frr config in VPC VR when change bgp peers
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhouapache committed Aug 22, 2024
1 parent 035c440 commit 58a3823
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 31 deletions.
7 changes: 7 additions & 0 deletions server/src/main/java/com/cloud/bgp/BGPServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,13 @@ public boolean applyBgpPeers(Vpc vpc, boolean continueOnError) throws ResourceUn
NetworkElement provider = networkModel.getElementImplementingProvider(gatewayProviderStr);
if (provider != null && provider instanceof BgpServiceProvider) {
List<BgpPeerVO> bgpPeers = bgpPeerDao.listNonRevokeByVpcId(vpc.getId());
if (CollectionUtils.isEmpty(bgpPeers)) {
Account owner = accountDao.findByIdIncludingRemoved(vpc.getAccountId());
List<Long> bgpPeerIds = routedIpv4Manager.getBgpPeerIdsForAccount(owner, vpc.getZoneId());
bgpPeers = bgpPeerIds.stream()
.map(bgpPeerId -> bgpPeerDao.findById(bgpPeerId))
.collect(Collectors.toList());
}
LOGGER.debug(String.format("Applying BPG Peers for VPC [%s]: [%s]", vpc, bgpPeers));
List<? extends Network> networks = networkModel.listNetworksByVpc(vpc.getId());
if (CollectionUtils.isNotEmpty(networks)) {
Expand Down
105 changes: 74 additions & 31 deletions test/integration/smoke/test_ipv4_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,10 @@ def test_11_isolated_network_with_dynamic_routed_mode(self):
# 5. Verify frr.conf in network VR
# 6. Reboot VR
# 7. Verify frr.conf in network VR
# 8. Update network BGP peers (to null)
# 8. Update network BGP peers (to bgppeer_2)
# 9. Verify frr.conf in network VR
# 10. Update network BGP peers (to null)
# 11. Verify frr.conf in network VR
"""
self.message("Running test_11_isolated_network_with_dynamic_routed_mode")

Expand All @@ -1255,15 +1257,6 @@ def test_11_isolated_network_with_dynamic_routed_mode(self):
)
self.cleanup.append(bgppeer_1)

bgppeer_2 = BgpPeer.create(
self.apiclient,
zoneid=self.zone.id,
asnumber=ASN_2,
ipaddress=IP4_ADDR_2,
password=PASSWORD_2
)
self.cleanup.append(bgppeer_2)

# 1. Create Isolated network with Dynamic routing
test_network_dynamic = Network.create(
self.apiclient,
Expand Down Expand Up @@ -1302,6 +1295,15 @@ def test_11_isolated_network_with_dynamic_routed_mode(self):
self.verifyFrrConf(network_router, frr_configs)

# 4. Update network BGP peers (to bgp_peer_1 and bgp_peer_2)
bgppeer_2 = BgpPeer.create(
self.apiclient,
zoneid=self.zone.id,
asnumber=ASN_2,
ipaddress=IP4_ADDR_2,
password=PASSWORD_2
)
self.cleanup.append(bgppeer_2)

test_network_dynamic.changeBgpPeers(
self.apiclient,
bgppeerids=[bgppeer_1.id, bgppeer_2.id]
Expand All @@ -1327,10 +1329,10 @@ def test_11_isolated_network_with_dynamic_routed_mode(self):
network_router = self.get_router(networkid=test_network_dynamic.id)
self.verifyFrrConf(network_router, frr_configs)

# 8. Update network BGP peers (to null)
# 8. Update network BGP peers (to bgppeer_2)
test_network_dynamic.changeBgpPeers(
self.apiclient,
bgppeerids=[]
bgppeerids=[bgppeer_2.id]
)

# 9. Verify frr.conf in network VR
Expand All @@ -1339,13 +1341,31 @@ def test_11_isolated_network_with_dynamic_routed_mode(self):
{"config": "neighbor %s password %s" % (bgppeer_1.ipaddress, PASSWORD_1),
"exists": False},
{"config": "neighbor %s remote-as %s" % (bgppeer_2.ipaddress, bgppeer_2.asnumber),
"exists": False},
"exists": True},
{"config": "neighbor %s password %s" % (bgppeer_2.ipaddress, PASSWORD_2),
"exists": False},
"exists": True},
{"config": "network %s" % test_network_dynamic.cidr,
"exists": False}]
"exists": True}]
self.verifyFrrConf(network_router, frr_configs)

# 10. Update network BGP peers (to null)
test_network_dynamic.changeBgpPeers(
self.apiclient,
bgppeerids=[]
)

# 11. Verify frr.conf in network VR
frr_configs = [{"config": "neighbor %s remote-as %s" % (bgppeer_1.ipaddress, bgppeer_1.asnumber),
"exists": True},
{"config": "neighbor %s password %s" % (bgppeer_1.ipaddress, PASSWORD_1),
"exists": True},
{"config": "neighbor %s remote-as %s" % (bgppeer_2.ipaddress, bgppeer_2.asnumber),
"exists": True},
{"config": "neighbor %s password %s" % (bgppeer_2.ipaddress, PASSWORD_2),
"exists": True},
{"config": "network %s" % test_network_dynamic.cidr,
"exists": True}]
self.verifyFrrConf(network_router, frr_configs)

@attr(tags=['advanced'], required_hardware=False)
def test_12_vpc_and_tier_with_dynamic_routed_mode(self):
Expand All @@ -1364,8 +1384,10 @@ def test_12_vpc_and_tier_with_dynamic_routed_mode(self):
# 11. Verify frr.conf in VPC VR
# 12. Reboot VPC VR
# 13. Verify frr.conf in VPC VR
# 14. Update network BGP peers (to null)
# 14. Update network BGP peers (to bgppeer_2)
# 15. Verify frr.conf in VPC VR
# 16. Update network BGP peers (to null)
# 17. Verify frr.conf in VPC VR
"""
self.message("Running test_12_vpc_and_tier_with_dynamic_routed_mode")

Expand All @@ -1379,15 +1401,6 @@ def test_12_vpc_and_tier_with_dynamic_routed_mode(self):
)
self.cleanup.append(bgppeer_1)

bgppeer_2 = BgpPeer.create(
self.apiclient,
zoneid=self.zone.id,
asnumber=ASN_2,
ipaddress=IP4_ADDR_2,
password=PASSWORD_2
)
self.cleanup.append(bgppeer_2)

# 2.1 VPC offering for static routing
vpc_offering_dynamic = VpcOffering.create(
self.apiclient,
Expand Down Expand Up @@ -1456,6 +1469,15 @@ def test_12_vpc_and_tier_with_dynamic_routed_mode(self):
self.verifyFrrConf(vpc_router, frr_configs)

# 7. Update VPC BGP peers (to bgp_peer_1 and bgp_peer_2)
bgppeer_2 = BgpPeer.create(
self.apiclient,
zoneid=self.zone.id,
asnumber=ASN_2,
ipaddress=IP4_ADDR_2,
password=PASSWORD_2
)
self.cleanup.append(bgppeer_2)

test_vpc_dynamic.changeBgpPeers(
self.apiclient,
bgppeerids=[bgppeer_1.id, bgppeer_2.id]
Expand Down Expand Up @@ -1523,10 +1545,10 @@ def test_12_vpc_and_tier_with_dynamic_routed_mode(self):
vpc_router = self.get_router(vpcid=test_vpc_dynamic.id)
self.verifyFrrConf(vpc_router, frr_configs)

# 14. Update VPC BGP peers (to null)
# 14. Update VPC BGP peers (to bgppeer_2)
test_vpc_dynamic.changeBgpPeers(
self.apiclient,
bgppeerids=[]
bgppeerids=[bgppeer_2.id]
)

# 15. Verify frr.conf in VPC VR
Expand All @@ -1535,13 +1557,34 @@ def test_12_vpc_and_tier_with_dynamic_routed_mode(self):
{"config": "neighbor %s password %s" % (bgppeer_1.ipaddress, PASSWORD_1),
"exists": False},
{"config": "neighbor %s remote-as %s" % (bgppeer_2.ipaddress, bgppeer_2.asnumber),
"exists": False},
"exists": True},
{"config": "neighbor %s password %s" % (bgppeer_2.ipaddress, PASSWORD_2),
"exists": False},
"exists": True},
{"config": "network %s" % test_vpc_tier_dynamic_1.cidr,
"exists": False},
"exists": True},
{"config": "network %s" % test_vpc_tier_dynamic_2.cidr,
"exists": False}]
"exists": True}]
self.verifyFrrConf(vpc_router, frr_configs)

# 16. Update VPC BGP peers (to null)
test_vpc_dynamic.changeBgpPeers(
self.apiclient,
bgppeerids=[]
)

# 17. Verify frr.conf in VPC VR
frr_configs = [{"config": "neighbor %s remote-as %s" % (bgppeer_1.ipaddress, bgppeer_1.asnumber),
"exists": True},
{"config": "neighbor %s password %s" % (bgppeer_1.ipaddress, PASSWORD_1),
"exists": True},
{"config": "neighbor %s remote-as %s" % (bgppeer_2.ipaddress, bgppeer_2.asnumber),
"exists": True},
{"config": "neighbor %s password %s" % (bgppeer_2.ipaddress, PASSWORD_2),
"exists": True},
{"config": "network %s" % test_vpc_tier_dynamic_1.cidr,
"exists": True},
{"config": "network %s" % test_vpc_tier_dynamic_2.cidr,
"exists": True}]
self.verifyFrrConf(vpc_router, frr_configs)


Expand Down
1 change: 1 addition & 0 deletions ui/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,7 @@
"message.success.assigned.vms": "Successfully assigned Instances",
"message.success.certificate.upload": "Certificate successfully uploaded",
"message.success.change.affinity.group": "Successfully changed affinity groups",
"message.success.change.bgp.peers": "Successfully changed BGP peers",
"message.success.change.offering": "Successfully changed offering",
"message.success.change.password": "Successfully changed password for User",
"message.success.clear.webhook.deliveries": "Successfully cleared webhook deliveries",
Expand Down

0 comments on commit 58a3823

Please sign in to comment.