Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Can't convert with callable None - for junos routers #1931

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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]
Expand All @@ -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:
Expand All @@ -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)}
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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=""):
Expand Down
Loading