Repository: napalm-automation/napalm

Issue:
NAPALM returns two equal IPv6 with get_bgp_neighbors()
I have found a strange issue on JUNOS and IPv6 BGP neighbors.

When using the `get_bgp_neighbors` method the inner the dictionary of peers for a given VRF might return two times the same IPv6 address. Here is a minimized output of a result.

```python
            '2001:db8:10:100:0:5:4100:1': {
                'uptime': 738
            },
            '2001:db8:10:100::5:4100:1': {
                'local_as': 64545,
                'remote_as': 64546,
                'remote_id': '',
                'is_up': False,
                'is_enabled': True,
                'description': '',
                'uptime': 0,
                'address_family': {
                    'ipv4': {
                        'received_prefixes': -1,
                        'accepted_prefixes': -1,
                        'sent_prefixes': -1
                    },
                    'ipv6': {
                        'received_prefixes': -1,
                        'accepted_prefixes': -1,
                        'sent_prefixes': -1
                    }
                }
            }
```

If you take a look this is the same peer but with the address in two different format. The issue may come from JUNOS itself. In fact I've noticed that in the configuration the `2001:db8:10:100::5:4100:1` is used but when showing the BGP summary on the router itself the address is expanded to `2001:db8:10:100:0:5:4100:1`.

The expected output would be to have only one peer in the dictionary (address being expanded or not).


Discussion:
That's unfortunate, I guess we will have to parse the IP with `netaddr` library to make sure this doesn't happen.
You might want to use the official module instead https://docs.python.org/3/library/ipaddress.html
Can we just normalize using the `ip` helper in `napalm/base/helpers.py`. This helper uses netaddr's IPAddress:

Looks like it should work.

```
>>> from netaddr import IPAddress
>>> IPAddress("2001:db8:10:100:0:5:4100:1")
IPAddress('2001:db8:10:100:0:5:4100:1')
>>> IPAddress("2001:db8:10:100::5:4100:1")
IPAddress('2001:db8:10:100:0:5:4100:1')
```

Resolving patch:
diff --git a/napalm/junos/junos.py b/napalm/junos/junos.py
--- a/napalm/junos/junos.py
+++ b/napalm/junos/junos.py
@@ -628,9 +628,11 @@ def _get_bgp_neighbors_core(neighbor_data, instance=None, uptime_table_items=Non
                 if not uptime_table_items:
                     uptime_table_items = _get_uptime_table(instance)
                 for neighbor, uptime in uptime_table_items:
-                    if neighbor not in bgp_neighbor_data[instance_name]['peers']:
-                        bgp_neighbor_data[instance_name]['peers'][neighbor] = {}
-                    bgp_neighbor_data[instance_name]['peers'][neighbor]['uptime'] = uptime[0][1]
+                    normalized_neighbor = napalm.base.helpers.ip(neighbor)
+                    if normalized_neighbor not in bgp_neighbor_data[instance_name]['peers']:
+                        bgp_neighbor_data[instance_name]['peers'][normalized_neighbor] = {}
+                    bgp_neighbor_data[instance_name]['peers'][normalized_neighbor]['uptime'] = \
+                        uptime[0][1]
 
         # Commenting out the following sections, till Junos
         #   will provide a way to identify the routing instance name


Test patch: