From 891bb78c1222d7acdff14d56c6c5aad0139536f3 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Thu, 21 Jan 2021 18:44:49 +0100 Subject: bgp: T1875: validate() that peer-group specified via listen range exists --- src/conf_mode/protocols_bgp.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/conf_mode') diff --git a/src/conf_mode/protocols_bgp.py b/src/conf_mode/protocols_bgp.py index 39d367b97..2a1e5f50a 100755 --- a/src/conf_mode/protocols_bgp.py +++ b/src/conf_mode/protocols_bgp.py @@ -127,13 +127,17 @@ def verify(bgp): route_map = afi_config['route_map'][tmp].replace('-', '_') if dict_search(f'policy.route_map.{route_map}', asn_config) == None: raise ConfigError(f'route-map "{route_map}" used for "{tmp}" does not exist!') - + # Throw an error if a peer group is not configured for allow range - if 'listen' in asn_config: - if 'range' in asn_config['listen']: - for prefix in asn_config['listen']['range']: - if not 'peer_group' in asn_config['listen']['range'].get(prefix): - raise ConfigError(f'Listen range for prefix "{prefix}" has no peer group configured.') + for prefix in dict_search('listen.range', asn_config) or []: + # we can not use dict_search() here as prefix contains dots ... + if 'peer_group' not in asn_config['listen']['range'][prefix]: + raise ConfigError(f'Listen range for prefix "{prefix}" has no peer group configured.') + else: + peer_group = asn_config['listen']['range'][prefix]['peer_group'] + # the peer group must also exist + if not dict_search(f'peer_group.{peer_group}', asn_config): + raise ConfigError(f'Peer-group "{peer_group}" for listen range "{prefix}" does not exist!') return None -- cgit v1.2.3