From fa97b68ae195c3692c55daebc6d82ed957cdec6d Mon Sep 17 00:00:00 2001 From: Jason Lixfeld Date: Fri, 16 Jun 2023 15:18:38 +0000 Subject: [PATCH 1/3] Use `LastStateTransitionTime` to populate `last_flapped` for `get_interfaces()` in IOS-XR --- napalm/iosxr/iosxr.py | 2 ++ .../_Get__Operational__Interfaces____Operational___Get_.txt | 3 +++ 2 files changed, 5 insertions(+) diff --git a/napalm/iosxr/iosxr.py b/napalm/iosxr/iosxr.py index 475ad3484..3079a476e 100644 --- a/napalm/iosxr/iosxr.py +++ b/napalm/iosxr/iosxr.py @@ -302,6 +302,7 @@ def get_interfaces(self): mtu = int(napalm.base.helpers.find_txt(interface_tree, "MTU")) description = napalm.base.helpers.find_txt(interface_tree, "Description") + last_flapped = napalm.base.helpers.find_txt(interface_tree, "LastStateTransitionTime") interfaces[interface_name] = copy.deepcopy(INTERFACE_DEFAULTS) interfaces[interface_name].update( { @@ -311,6 +312,7 @@ def get_interfaces(self): "is_enabled": enabled, "mac_address": mac_address, "description": description, + "last_flapped": last_flapped, } ) diff --git a/test/iosxr/mocked_data/test_get_interfaces/normal/_Get__Operational__Interfaces____Operational___Get_.txt b/test/iosxr/mocked_data/test_get_interfaces/normal/_Get__Operational__Interfaces____Operational___Get_.txt index c3c7a6b68..1263f135f 100644 --- a/test/iosxr/mocked_data/test_get_interfaces/normal/_Get__Operational__Interfaces____Operational___Get_.txt +++ b/test/iosxr/mocked_data/test_get_interfaces/normal/_Get__Operational__Interfaces____Operational___Get_.txt @@ -287,6 +287,9 @@ 0 + + 1682947558700282575 + false From 1cb3e7525824fef5793434a7aec03cbb97b2a755 Mon Sep 17 00:00:00 2001 From: Jason Lixfeld Date: Fri, 16 Jun 2023 15:42:04 +0000 Subject: [PATCH 2/3] Add missing default to `last_flapped` --- napalm/iosxr/iosxr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/napalm/iosxr/iosxr.py b/napalm/iosxr/iosxr.py index 3079a476e..3294857c4 100644 --- a/napalm/iosxr/iosxr.py +++ b/napalm/iosxr/iosxr.py @@ -302,7 +302,7 @@ def get_interfaces(self): mtu = int(napalm.base.helpers.find_txt(interface_tree, "MTU")) description = napalm.base.helpers.find_txt(interface_tree, "Description") - last_flapped = napalm.base.helpers.find_txt(interface_tree, "LastStateTransitionTime") + last_flapped = napalm.base.helpers.find_txt(interface_tree, "LastStateTransitionTime", -1) interfaces[interface_name] = copy.deepcopy(INTERFACE_DEFAULTS) interfaces[interface_name].update( { From f4a73a42d4beea821b4fcc0a5ce9955b080fa012 Mon Sep 17 00:00:00 2001 From: Mircea Ulinic Date: Thu, 21 Mar 2024 12:07:46 +0000 Subject: [PATCH 3/3] Black format and fix tests --- napalm/iosxr/iosxr.py | 12 ++++++++++-- .../test_get_interfaces/normal/expected_result.json | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/napalm/iosxr/iosxr.py b/napalm/iosxr/iosxr.py index 3294857c4..2bcb19a0d 100644 --- a/napalm/iosxr/iosxr.py +++ b/napalm/iosxr/iosxr.py @@ -302,7 +302,13 @@ def get_interfaces(self): mtu = int(napalm.base.helpers.find_txt(interface_tree, "MTU")) description = napalm.base.helpers.find_txt(interface_tree, "Description") - last_flapped = napalm.base.helpers.find_txt(interface_tree, "LastStateTransitionTime", -1) + last_flapped = napalm.base.helpers.convert( + float, + napalm.base.helpers.find_txt( + interface_tree, "LastStateTransitionTime", -1 + ), + -1, + ) interfaces[interface_name] = copy.deepcopy(INTERFACE_DEFAULTS) interfaces[interface_name].update( { @@ -312,7 +318,9 @@ def get_interfaces(self): "is_enabled": enabled, "mac_address": mac_address, "description": description, - "last_flapped": last_flapped, + "last_flapped": last_flapped / 1e9 + if last_flapped != -1.0 + else -1.0, } ) diff --git a/test/iosxr/mocked_data/test_get_interfaces/normal/expected_result.json b/test/iosxr/mocked_data/test_get_interfaces/normal/expected_result.json index 8d25c7331..824c19195 100644 --- a/test/iosxr/mocked_data/test_get_interfaces/normal/expected_result.json +++ b/test/iosxr/mocked_data/test_get_interfaces/normal/expected_result.json @@ -2,7 +2,7 @@ "TenGigE0/0/0/14": { "is_enabled": true, "description": "", - "last_flapped": -1.0, + "last_flapped": 1682947558.7002826, "is_up": false, "mac_address": "E0:AC:F1:64:71:52", "mtu": 1514,