From 29f86f99b1f36ea5d4dd60622a7102c0ae42e345 Mon Sep 17 00:00:00 2001 From: talves Date: Tue, 23 May 2023 13:23:11 +0100 Subject: [PATCH] fix: restrict group names inside the bgp config --- napalm/junos/junos.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/napalm/junos/junos.py b/napalm/junos/junos.py index 02ae5eec9..6c0fc6e83 100644 --- a/napalm/junos/junos.py +++ b/napalm/junos/junos.py @@ -1246,6 +1246,8 @@ def build_prefix_limit(**args): } _GROUP_FIELDS_DATATYPE_MAP_.update(_COMMON_FIELDS_DATATYPE_) + _UNWANTED_GROUP_FIELDS = ["multihop", "cluster"] + _DATATYPE_DEFAULT_ = {str: "", int: 0, bool: False, list: []} bgp_config = {} @@ -1302,6 +1304,8 @@ def build_prefix_limit(**args): is_nhs, boolean = is_nhs_list[0] nhs_policies[policy_name] = boolean if boolean is not None else False + unwanted_group_fields = dict() + for bgp_group in bgp_items: bgp_group_name = bgp_group[0] bgp_group_details = bgp_group[1] @@ -1314,6 +1318,9 @@ def build_prefix_limit(**args): # Always overwrite with the system local_as (this will either be # valid or will be zero i.e. the same as the default value). bgp_config[bgp_group_name]["local_as"] = system_bgp_asn + unwanted_group_fields[bgp_group_name] = dict( + {key: False for key in _UNWANTED_GROUP_FIELDS} + ) for key, value in bgp_group_details: if "_prefix_limit" in key or value is None: @@ -1335,6 +1342,10 @@ def build_prefix_limit(**args): if key == "neighbors": bgp_group_peers = value continue + + if key in _UNWANTED_GROUP_FIELDS: + unwanted_group_fields[bgp_group_name][key] = True + continue if datatype: bgp_config[bgp_group_name].update( {key: napalm.base.helpers.convert(datatype, value, default)} @@ -1354,9 +1365,7 @@ def build_prefix_limit(**args): bgp_config[bgp_group_name]["prefix_limit"] = build_prefix_limit( **prefix_limit_fields ) - if "multihop" in bgp_config[bgp_group_name].keys(): - # Delete 'multihop' key from the output - del bgp_config[bgp_group_name]["multihop"] + if unwanted_group_fields[bgp_group_name]["multihop"]: if bgp_config[bgp_group_name]["multihop_ttl"] == 0: # Set ttl to default value 64 bgp_config[bgp_group_name]["multihop_ttl"] = 64 @@ -1411,7 +1420,7 @@ def build_prefix_limit(**args): # we do not want cluster in the output del bgp_peer_details["cluster"] - if "cluster" in bgp_config[bgp_group_name].keys(): + if unwanted_group_fields[bgp_group_name]["cluster"]: bgp_peer_details["route_reflector_client"] = True prefix_limit_fields = {} for key, value in bgp_group_details: @@ -1434,10 +1443,6 @@ def build_prefix_limit(**args): if neighbor and bgp_peer_address == neighbor_ip: break # found the desired neighbor - if "cluster" in bgp_config[bgp_group_name].keys(): - # we do not want cluster in the output - del bgp_config[bgp_group_name]["cluster"] - return bgp_config def get_bgp_neighbors_detail(self, neighbor_address=""):