From 1f01cf135fe2d61ef80b9f4a14e0f94378b2e2eb Mon Sep 17 00:00:00 2001 From: Brandon Ewing Date: Wed, 17 Jul 2019 09:28:51 -0500 Subject: [PATCH 1/3] Handle empty LLDP capabilities If an LLDP neighbor lists no enabled capabilities, this is displayed as an empty string by the device output. Detect this and return an empty list instead. --- napalm_mos/mos.py | 2 +- .../empty_cap/expected_result.json | 1 + .../empty_cap/show_lldp_neighbor__verbose.text | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/empty_cap/expected_result.json create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/empty_cap/show_lldp_neighbor__verbose.text diff --git a/napalm_mos/mos.py b/napalm_mos/mos.py index 8a58b0e..a229b54 100644 --- a/napalm_mos/mos.py +++ b/napalm_mos/mos.py @@ -444,7 +444,7 @@ def get_environment(self): def _transform_lldp_capab(self, capabilities): return sorted( - [LLDP_CAPAB_TRANFORM_TABLE[c.lower()] for c in capabilities.split(", ")] + [LLDP_CAPAB_TRANFORM_TABLE[c.lower()] for c in capabilities.split(", ") if c] ) def get_lldp_neighbors_detail(self, interface=""): diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/empty_cap/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors_detail/empty_cap/expected_result.json new file mode 100644 index 0000000..5453b47 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/empty_cap/expected_result.json @@ -0,0 +1 @@ +{"et37": [{"parent_interface": "et37", "remote_port": "74:a0:2f:1c:1f:91", "remote_port_description": "eth1", "remote_chassis_id": "74:a0:2f:1c:1f:91", "remote_system_name": "localhost", "remote_system_description": "CentOS Linux 7 (Core) Linux 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64", "remote_system_capab": ["bridge", "router", "wlan-access-point"], "remote_system_enable_capab": []}]} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/empty_cap/show_lldp_neighbor__verbose.text b/test/unit/mocked_data/test_get_lldp_neighbors_detail/empty_cap/show_lldp_neighbor__verbose.text new file mode 100644 index 0000000..d467022 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/empty_cap/show_lldp_neighbor__verbose.text @@ -0,0 +1,13 @@ +* et37 + src: (mac address) 74:a0:2f:1c:1f:91 + received: Wed Jul 17 10:09:25 2019 (0:00:15) + chassis id: (mac address) 74:a0:2f:1c:1f:91 + port id: (mac address) 74:a0:2f:1c:1f:91 + time to live: 120 secs + system name: localhost + system description: CentOS Linux 7 (Core) Linux 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 + system capability: {'enabled': '', 'capabilities': 'mac-bridge,wlan-access-point,router'} + port description: eth1 + IEEE 802.3 link aggr (3): {'capability': 'capable', 'status': 'not in aggregation', 'port id': '00 00 00 00'} + IEEE 802.3 mac phy cfg status (1): {'auto-neg status': 'enabled', 'auto-neg support': 'supported'} + end of lldpdu: \ No newline at end of file From d6c19a393572503794702950a51c4359b4b346b7 Mon Sep 17 00:00:00 2001 From: Brandon Ewing Date: Wed, 17 Jul 2019 09:44:12 -0500 Subject: [PATCH 2/3] Update version to 2.4.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index caf1ccb..215a046 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name="napalm-mos", - version="2.4.0", + version="2.4.1", packages=find_packages(), author="Benny Holmgren, Brandon Ewing", author_email="benny@holmgren.id.au, brandon.ewing@warningg.com", From cdb54dd5d1b110bcac98560881a36a7379d4b7d6 Mon Sep 17 00:00:00 2001 From: Brandon Ewing Date: Wed, 17 Jul 2019 09:48:29 -0500 Subject: [PATCH 3/3] Blacken --- napalm_mos/mos.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/napalm_mos/mos.py b/napalm_mos/mos.py index a229b54..b13b491 100644 --- a/napalm_mos/mos.py +++ b/napalm_mos/mos.py @@ -444,7 +444,11 @@ def get_environment(self): def _transform_lldp_capab(self, capabilities): return sorted( - [LLDP_CAPAB_TRANFORM_TABLE[c.lower()] for c in capabilities.split(", ") if c] + [ + LLDP_CAPAB_TRANFORM_TABLE[c.lower()] + for c in capabilities.split(", ") + if c + ] ) def get_lldp_neighbors_detail(self, interface=""):