Repository: napalm-automation/napalm

Issue:
Eos get_bgp_neighbors is failing on devices due to type mismatch
### Description of Issue/Question

*Note*: Please check https://guides.github.com/features/mastering-markdown/
to see how to properly format your request.

### Did you follow the steps from https://github.com/napalm-automation/napalm#faq
(Place an ``x`` between the square brackets where applicable)

- [] Yes
- [x] No


### Setup

### napalm version
(Paste verbatim output from `pip freeze | grep napalm` between quotes below)

```
napalm==2.5.0
```

### Network operating system version
(Paste verbatim output from `show version` - or equivalent - between quotes below)

```
            "version": "4.22.2F-DPE",
```

### Steps to Reproduce the Issue

run get_bgp_neighbors with more than one neighbor on a device with that version. 

### Error Traceback
(Paste the complete traceback of the exception between quotes below)

```
020-04-13T15:45:18Z
return executor()
2020-04-13T15:45:18Z
File "/usr/local/lib/python3.6/site-packages/olympus_nqa/Device.py", line 144, in _run
2020-04-13T15:45:18Z
return getattr(self.device, method)(*args, **kwargs)
2020-04-13T15:45:18Z
File "/usr/local/lib/python3.6/site-packages/napalm/eos/eos.py", line 504, in get_bgp_neighbors
2020-04-13T15:45:18Z
"uptime": int(time.time() - peer_data["upDownTime"]),
2020-04-13T15:45:18Z
TypeError: unsupported operand type(s) for -: 'float' and 'str'

```


Looks like the code problem is here:
https://github.com/napalm-automation/napalm/blob/develop/napalm/eos/eos.py#L501

I grabbed the output of `show ip bgp summary vrf all` from a non working device and the field is a string (`upDownTime`):
```
       "peers": {
                        "100.98.0.120": {
                            "description": "bad-host",
                            "msgSent": 56860,
                            "inMsgQueue": 0,
                            "prefixReceived": 6,
                            "upDownTime": "1586651008.000000",
                            "version": 4,
                            "prefixAccepted": 6,
                            "msgReceived": 56920,
                            "peerState": "Established",
                            "outMsgQueue": 0,
                            "underMaintenance": false,
                            "asn": "64814"
                        },

```

However on a device that works the field is a float:

```
        "peers": {
                        "100.64.0.8": {
                            "description": "good-host",
                            "msgSent": 2092805,
                            "inMsgQueue": 0,
                            "prefixReceived": 2440,
                            "upDownTime": 1580852047.450348,
                            "version": 4,
                            "msgReceived": 2240470,
                            "prefixAccepted": 2440,
                            "peerState": "Established",
                            "outMsgQueue": 0,
                            "underMaintenance": false,
                            "asn": 64801
```

the working version is:

```
            "version": "4.21.7.1M-DPE",
```


Discussion:
Thanks for reporting @sdanelli, this should be an easy fix. I'd also recommend you to report this to Arista to correct this in the next EOS releases.

Resolving patch:
diff --git a/napalm/eos/eos.py b/napalm/eos/eos.py
--- a/napalm/eos/eos.py
+++ b/napalm/eos/eos.py
@@ -498,7 +498,7 @@ def get_re_group(res, key, default=None):
                     peer_info = {
                         "is_up": peer_data["peerState"] == "Established",
                         "is_enabled": is_enabled,
-                        "uptime": int(time.time() - peer_data["upDownTime"]),
+                        "uptime": int(time.time() - float(peer_data["upDownTime"])),
                     }
                     bgp_counters[vrf]["peers"][napalm.base.helpers.ip(peer)] = peer_info
         lines = []


Test patch:
diff --git a/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/expected_result.json b/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/expected_result.json
new file mode 100644
--- /dev/null
+++ b/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/expected_result.json
@@ -0,0 +1,91 @@
+{
+  "global": {
+    "router_id": "192.168.56.3",
+    "peers": {
+      "192.168.56.4": {
+        "is_enabled": true,
+        "uptime": "...",
+        "remote_as": 65001,
+        "description": "",
+        "remote_id": "192.168.56.3",
+        "local_as": 65002,
+        "is_up": false,
+        "address_family": {
+          "ipv4": {
+            "sent_prefixes": 0,
+            "accepted_prefixes": -1,
+            "received_prefixes": 0
+          },
+          "ipv6": {
+            "sent_prefixes": 0,
+            "accepted_prefixes": -1,
+            "received_prefixes": 0
+          }
+        }
+      },
+      "192.168.56.2": {
+        "is_enabled": true,
+        "uptime": "...",
+        "remote_as": 65002,
+        "description": "",
+        "remote_id": "192.168.56.2",
+        "local_as": 65001,
+        "is_up": true,
+        "address_family": {
+          "ipv4": {
+            "sent_prefixes": 0,
+            "accepted_prefixes": -1,
+            "received_prefixes": 0
+          },
+          "ipv6": {
+            "sent_prefixes": 0,
+            "accepted_prefixes": -1,
+            "received_prefixes": 0
+          }
+        }
+      },
+      "2001:7f8::f10:0:2": {
+        "is_enabled": true,
+        "uptime": "...",
+        "remote_as": 65002,
+        "description": "",
+        "remote_id": "192.168.56.2",
+        "local_as": 65001,
+        "is_up": true,
+        "address_family": {
+          "ipv4": {
+            "sent_prefixes": 0,
+            "accepted_prefixes": -1,
+            "received_prefixes": 0
+          },
+          "ipv6": {
+            "sent_prefixes": 0,
+            "accepted_prefixes": -1,
+            "received_prefixes": 0
+          }
+        }
+      },
+      "2001:7f8::f10:0:3": {
+        "is_enabled": true,
+        "uptime": "...",
+        "remote_as": 65001,
+        "description": "",
+        "remote_id": "192.168.56.3",
+        "local_as": 65002,
+        "is_up": false,
+        "address_family": {
+          "ipv4": {
+            "sent_prefixes": 0,
+            "accepted_prefixes": -1,
+            "received_prefixes": 0
+          },
+          "ipv6": {
+            "sent_prefixes": 0,
+            "accepted_prefixes": -1,
+            "received_prefixes": 0
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ip_bgp_neighbors_vrf_all___include_remote_AS___remote_router_ID__IPv_46___Unicast_6PE_____0_9____Local_AS_Desc_BGP_state.text b/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ip_bgp_neighbors_vrf_all___include_remote_AS___remote_router_ID__IPv_46___Unicast_6PE_____0_9____Local_AS_Desc_BGP_state.text
new file mode 100644
--- /dev/null
+++ b/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ip_bgp_neighbors_vrf_all___include_remote_AS___remote_router_ID__IPv_46___Unicast_6PE_____0_9____Local_AS_Desc_BGP_state.text
@@ -0,0 +1,12 @@
+BGP neighbor is 192.168.56.2, remote AS 65002, external link
+  BGP version 4, remote router ID 192.168.56.2, VRF default
+  BGP state is Established, up for   32d16h
+    IPv4 Unicast:           0         0
+    IPv6 Unicast:           0         0
+Local AS is 65001, local router ID 192.168.56.3
+BGP neighbor is 192.168.56.4, remote AS 65001, external link
+  BGP version 4, remote router ID 192.168.56.3, VRF default
+  BGP state is Established, up for   32d16h
+    IPv4 Unicast:           0         0
+    IPv6 Unicast:           0         0
+Local AS is 65002, local router ID 192.168.56.2
diff --git a/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ip_bgp_summary_vrf_all.json b/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ip_bgp_summary_vrf_all.json
new file mode 100644
--- /dev/null
+++ b/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ip_bgp_summary_vrf_all.json
@@ -0,0 +1,37 @@
+{
+"vrfs": {
+"default": {
+"routerId": "192.168.56.3",
+"peers": {
+"192.168.56.2": {
+"msgSent": 6,
+"inMsgQueue": 0,
+"prefixReceived": 0,
+"upDownTime": "1452680643.198489",
+"version": 4,
+"msgReceived": 5,
+"prefixAccepted": 0,
+"peerState": "Established",
+"outMsgQueue": 0,
+"underMaintenance": false,
+"asn": 65002
+},
+"192.168.56.4": {
+"msgSent": 267,
+"inMsgQueue": 0,
+"prefixReceived": 0,
+"upDownTime": "1452696202.499104",
+"version": 4,
+"msgReceived": 263,
+"prefixAccepted": 0,
+"peerState": "Active",
+"outMsgQueue": 0,
+"underMaintenance": false,
+"asn": 65001
+}
+},
+"vrf": "default",
+"asn": 65001
+}
+}
+}
diff --git a/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ipv6_bgp_neighbors_vrf_all___include_remote_AS___remote_router_ID__IPv_46___Unicast_6PE_____0_9____Local_AS_Desc_BGP_state.text b/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ipv6_bgp_neighbors_vrf_all___include_remote_AS___remote_router_ID__IPv_46___Unicast_6PE_____0_9____Local_AS_Desc_BGP_state.text
new file mode 100644
--- /dev/null
+++ b/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ipv6_bgp_neighbors_vrf_all___include_remote_AS___remote_router_ID__IPv_46___Unicast_6PE_____0_9____Local_AS_Desc_BGP_state.text
@@ -0,0 +1,12 @@
+BGP neighbor is 2001:7f8::f10:0:2, remote AS 65002, external link
+  BGP version 4, remote router ID 192.168.56.2, VRF default
+  BGP state is Established, up for   32d16h
+    IPv4 Unicast:           0         0
+    IPv6 Unicast:           0         0
+Local AS is 65001, local router ID 192.168.56.3
+BGP neighbor is 2001:7f8::f10:0:3, remote AS 65001, external link
+  BGP version 4, remote router ID 192.168.56.3, VRF default
+  BGP state is Established, up for   32d16h
+    IPv4 Unicast:           0         0
+    IPv6 Unicast:           0         0
+Local AS is 65002, local router ID 192.168.56.2
diff --git a/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ipv6_bgp_summary_vrf_all.json b/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ipv6_bgp_summary_vrf_all.json
new file mode 100644
--- /dev/null
+++ b/test/eos/mocked_data/test_get_bgp_neighbors/issue1168/show_ipv6_bgp_summary_vrf_all.json
@@ -0,0 +1,37 @@
+{
+"vrfs": {
+"default": {
+"routerId": "192.168.56.3",
+"peers": {
+"2001:7f8::f10:0:2": {
+"msgSent": 5,
+"inMsgQueue": 0,
+"prefixReceived": 0,
+"upDownTime": "1452681618.167685",
+"version": 4,
+"msgReceived": 5,
+"prefixAccepted": 0,
+"peerState": "Established",
+"outMsgQueue": 0,
+"underMaintenance": false,
+"asn": 65002
+},
+"2001:7f8::f10:0:3": {
+"msgSent": 267,
+"inMsgQueue": 0,
+"prefixReceived": 0,
+"upDownTime": "1452696202.499104",
+"version": 4,
+"msgReceived": 263,
+"prefixAccepted": 0,
+"peerState": "Active",
+"outMsgQueue": 0,
+"underMaintenance": false,
+"asn": 65001
+}
+},
+"vrf": "default",
+"asn": 65001
+}
+}
+}