diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 4e6efa5f48..6a8e194298 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -8317,6 +8317,7 @@ struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp, int ret; struct peer *peer; union sockunion su; + struct peer_group *group; /* Get peer sockunion. */ ret = str2sockunion(ip_str, &su); @@ -8325,6 +8326,11 @@ struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp, if (!peer) { peer = peer_lookup_by_hostname(bgp, ip_str); + if (!peer) { + group = peer_group_lookup(bgp, ip_str); + peer = listnode_head(group->peer); + } + if (!peer) { if (use_json) { json_object *json_no = NULL; diff --git a/tests/topotests/bgp_peer_group/r3/bgpd.conf b/tests/topotests/bgp_peer_group/r3/bgpd.conf index eb2fca15fb..5a1340fb0b 100644 --- a/tests/topotests/bgp_peer_group/r3/bgpd.conf +++ b/tests/topotests/bgp_peer_group/r3/bgpd.conf @@ -1,7 +1,11 @@ ! router bgp 65003 - neighbor PG peer-group - neighbor PG remote-as external - neighbor PG timers 3 10 - neighbor 192.168.255.1 peer-group PG + no bgp ebgp-requires-policy + neighbor PG peer-group + neighbor PG remote-as external + neighbor PG timers 3 10 + neighbor 192.168.255.1 peer-group PG + address-family ipv4 unicast + redistribute connected + exit-address-family ! diff --git a/tests/topotests/bgp_peer_group/test_bgp_peer-group.py b/tests/topotests/bgp_peer_group/test_bgp_peer-group.py index e8c3feb76f..a91fade049 100644 --- a/tests/topotests/bgp_peer_group/test_bgp_peer-group.py +++ b/tests/topotests/bgp_peer_group/test_bgp_peer-group.py @@ -74,9 +74,26 @@ def test_bgp_peer_group(): return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_peer_group_configured) - success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed bgp convergence in r1" - assert result is None, 'Failed bgp convergence in "{}"'.format(tgen.gears["r1"]) + def _bgp_peer_group_check_advertised_routes(): + output = json.loads( + tgen.gears["r3"].vtysh_cmd("show ip bgp neighbor PG advertised-routes json") + ) + expected = { + "advertisedRoutes": { + "192.168.255.0/24": { + "valid": True, + "best": True, + } + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_peer_group_check_advertised_routes) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed checking advertised routes from r3" if __name__ == "__main__":