From c19ea0d4c5e0ac87b434f407f5d0cf9b6cfc47dd Mon Sep 17 00:00:00 2001 From: Jeroen van Bemmel Date: Fri, 2 Jun 2023 00:11:15 +0000 Subject: [PATCH 1/3] * Set XML namespace for get_bgp_neighbors_* * Check SR OS version and adjust state XML filter accordingly --- napalm_sros/api/get_bgp_neighbors.py | 2 +- napalm_sros/api/get_bgp_neighbors_detail.py | 2 +- napalm_sros/nc_filters.py | 7 +++---- napalm_sros/sros.py | 18 +++++++++--------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/napalm_sros/api/get_bgp_neighbors.py b/napalm_sros/api/get_bgp_neighbors.py index 038da58..00e712f 100644 --- a/napalm_sros/api/get_bgp_neighbors.py +++ b/napalm_sros/api/get_bgp_neighbors.py @@ -70,7 +70,7 @@ """ GET_BGP_NEIGHBORS = """ - + diff --git a/napalm_sros/api/get_bgp_neighbors_detail.py b/napalm_sros/api/get_bgp_neighbors_detail.py index f5ba89b..7e7b7c9 100644 --- a/napalm_sros/api/get_bgp_neighbors_detail.py +++ b/napalm_sros/api/get_bgp_neighbors_detail.py @@ -104,7 +104,7 @@ """ GET_BGP_NEIGHBORS_DETAILS = """ - + diff --git a/napalm_sros/nc_filters.py b/napalm_sros/nc_filters.py index b4ed44e..2f6ab6c 100644 --- a/napalm_sros/nc_filters.py +++ b/napalm_sros/nc_filters.py @@ -34,8 +34,8 @@ } -GET_INTERFACES = { - "_": """ +def GET_INTERFACES(R19): + return f""" @@ -49,7 +49,7 @@ - + { '' if R19 else '' } @@ -80,7 +80,6 @@ """ -} GET_INTERFACES_COUNTERS = { "_": """ diff --git a/napalm_sros/sros.py b/napalm_sros/sros.py index 1c6c654..e36e1f9 100644 --- a/napalm_sros/sros.py +++ b/napalm_sros/sros.py @@ -132,6 +132,10 @@ def open(self): hostkey_verify=False, timeout=self.timeout, ) + revision = re.compile( ".*&revision=(.*).*" ) + self.state_revisions = [ revision.match(i).groups()[0] for i in self.conn.server_capabilities if "nokia-state" in i ] + log.info( self.state_revisions ) + self.R19 = '2016-07-06' in self.state_revisions # Older SR OS release e.g. '2022-10-19' or '2016-07-06' except ConnectionException as ce: print("Error in opening netconf connection : {}".format(ce)) log.error( @@ -641,7 +645,7 @@ def get_interfaces(self): interfaces = {} result = to_ele( self.conn.get( - filter=GET_INTERFACES["_"], with_defaults="report-all" + filter=GET_INTERFACES(R19=self.R19), with_defaults="report-all" ).data_xml ) # get physical interfaces (ports) information @@ -787,14 +791,10 @@ def get_interfaces(self): ) ifd["speed"] = if_speed - ifd["is_up"] = ( - True - if self._find_txt( - if_state, "state_ns:if-oper-status", namespaces=self.nsmap - ) - == "up" - else False - ) + ifd["is_up"] = self._find_txt( + if_state, "state_ns:if-oper-status" if self.R19 else "state_ns:oper-state", + namespaces=self.nsmap + ) == "up" flap_time = self._find_txt( if_state, "state_ns:last-oper-change", namespaces=self.nsmap From 6bcdcf9d1e44de0ee182fa91512c9c8ab18e1697 Mon Sep 17 00:00:00 2001 From: Jeroen van Bemmel Date: Fri, 2 Jun 2023 00:15:43 +0000 Subject: [PATCH 2/3] Adjust input XML --- .../mocked_data/test_get_interfaces/normal/get_interfaces.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/mocked_data/test_get_interfaces/normal/get_interfaces.xml b/test/unit/mocked_data/test_get_interfaces/normal/get_interfaces.xml index c09a2f5..749fccc 100644 --- a/test/unit/mocked_data/test_get_interfaces/normal/get_interfaces.xml +++ b/test/unit/mocked_data/test_get_interfaces/normal/get_interfaces.xml @@ -37,7 +37,7 @@ system 1500 - up + up 2020-04-13T15:53:27.0Z From a808e9920fd3c97a5a3fa8da454108c9b4014292 Mon Sep 17 00:00:00 2001 From: Jeroen van Bemmel Date: Fri, 2 Jun 2023 00:21:31 +0000 Subject: [PATCH 3/3] Set R19 flag --- test/unit/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/conftest.py b/test/unit/conftest.py index 8f8652d..ecc55e6 100644 --- a/test/unit/conftest.py +++ b/test/unit/conftest.py @@ -49,6 +49,7 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None) self.ssh_channel = FakeSSHConnectionChannel() self.conn_ssh = FakeSSHConnection() self.manager = FakeManager() + self.R19 = False def is_alive(self): return {"is_alive": True}