From e4a82fa991c517ff39911058e75668ab07c0912c Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Sat, 23 Jan 2021 07:59:11 +0100 Subject: [PATCH] canonify peer addresses --- inventory_provider/juniper.py | 3 ++- test/per_router/test_juniper_data.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index 58992e10..50ffc3d0 100644 --- a/inventory_provider/juniper.py +++ b/inventory_provider/juniper.py @@ -214,7 +214,8 @@ def list_interfaces(netconf_config): def all_bgp_peers(netconf_config): def _peering_params(neighbor_node): - info = {'address': neighbor_node.find('name').text} + address = neighbor_node.find('name').text + info = {'address': ipaddress.ip_address(address).exploded} peer_as = neighbor_node.find('peer-as') if peer_as is not None: # lxml usage warning: can't just test `if peer_as:` diff --git a/test/per_router/test_juniper_data.py b/test/per_router/test_juniper_data.py index 868f019d..0ecf82c5 100644 --- a/test/per_router/test_juniper_data.py +++ b/test/per_router/test_juniper_data.py @@ -1,3 +1,4 @@ +import ipaddress import jsonschema from inventory_provider import juniper @@ -85,6 +86,12 @@ def test_bgp_peering_data(netconf_doc): jsonschema.validate(peerings, schema) assert peerings # there's always at least one + # confirm the addresses are in canonical (exploded) form + for p in peerings: + canonical_address = ipaddress.ip_address(p['address']).exploded + assert p['address'] == canonical_address + + def test_snmp_community_string(mocked_netifaces, netconf_doc): assert juniper.snmp_community_string(netconf_doc) == '0pBiFbD' -- GitLab