diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index 58992e100645de91cedcb5c89ea495bad724f6e5..50ffc3d078cd0e6492d04f9724b6429b4b80e55f 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 868f019df8b2d7b55202e4b72a93a0fabc75f39c..0ecf82c5e257d6db09ed8be14f725c4def0e7ae0 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'