From d1979cdc22bb14542f65689ab19fdf31fa07ffa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Castillo=20Alc=C3=ADbar?= Date: Mon, 31 Aug 2020 09:01:48 +0200 Subject: [PATCH] Update get probe code to make it work it IOS XE 16.12.x --- napalm/ios/ios.py | 22 +++++++++++-------- .../normal/expected_result.json | 9 ++++++++ ...xt => show_run___section_ip_sla__0_9_.txt} | 8 ++++++- 3 files changed, 29 insertions(+), 10 deletions(-) rename test/ios/mocked_data/test_get_probes_config/normal/{show_run___include_ip_sla__0_9_.txt => show_run___section_ip_sla__0_9_.txt} (64%) diff --git a/napalm/ios/ios.py b/napalm/ios/ios.py index 22bc566b6..8d18ab53d 100644 --- a/napalm/ios/ios.py +++ b/napalm/ios/ios.py @@ -2697,18 +2697,22 @@ def process_mac_fields(vlan, mac, mac_type, interface): def get_probes_config(self): probes = {} + probes_regex = ( r"ip\s+sla\s+(?P\d+)\n" - r"\s+(?P\S+)\s+(?P.*\n).*" - r"\s+tag\s+(?P\S+)\n.*" - r"\s+history\s+buckets-kept\s+(?P\d+)\n.*" - r"\s+frequency\s+(?P\d+)$" + r"\s+(?P\S+)\s+(?P.*)\n" + r"\s+tag\s+(?P[\S ]+)\n" + r"(\s+.*\n)*" + r"((\s+frequency\s+(?P\d+)\n(\s+.*\n)*\s+history" + r"\s+buckets-kept\s+(?P\d+))|(\s+history\s+buckets-kept" + r"\s+(?P\d+)\n.*\s+frequency\s+(?P\d+)))" ) + probe_args = { "icmp-echo": r"^(?P\S+)\s+source-(?:ip|interface)\s+(?P\S+)$" } probe_type_map = {"icmp-echo": "icmp-ping"} - command = "show run | include ip sla [0-9]" + command = "show run | section ip sla [0-9]" output = self._send_command(command) for match in re.finditer(probes_regex, output, re.M): probe = match.groupdict() @@ -2724,8 +2728,8 @@ def get_probes_config(self): "probe_type": probe_type_map[probe["probe_type"]], "target": probe_data["target"], "source": probe_data["source"], - "probe_count": int(probe["probe_count"]), - "test_interval": int(probe["interval"]), + "probe_count": int(probe["probe_count0"] or probe["probe_count1"]), + "test_interval": int(probe["interval0"] or probe["interval1"]), } } @@ -3047,8 +3051,8 @@ def get_route_to(self, destination="", protocol="", longer=False): destination, _vrf, nh, ip_version ) nh_line_found = ( - False - ) # for next RT entry processing ... + False # for next RT entry processing ... + ) routes[route_match].append(route_entry) return routes diff --git a/test/ios/mocked_data/test_get_probes_config/normal/expected_result.json b/test/ios/mocked_data/test_get_probes_config/normal/expected_result.json index 76935ad9c..f914b4333 100644 --- a/test/ios/mocked_data/test_get_probes_config/normal/expected_result.json +++ b/test/ios/mocked_data/test_get_probes_config/normal/expected_result.json @@ -16,5 +16,14 @@ "test_interval": 3, "probe_count": 20 } + }, + "3": { + "quad9": { + "source": "GigabitEthernet11", + "probe_type": "icmp-ping", + "target": "9.9.9.9", + "test_interval": 15, + "probe_count": 60 + } } } diff --git a/test/ios/mocked_data/test_get_probes_config/normal/show_run___include_ip_sla__0_9_.txt b/test/ios/mocked_data/test_get_probes_config/normal/show_run___section_ip_sla__0_9_.txt similarity index 64% rename from test/ios/mocked_data/test_get_probes_config/normal/show_run___include_ip_sla__0_9_.txt rename to test/ios/mocked_data/test_get_probes_config/normal/show_run___section_ip_sla__0_9_.txt index f778ecef4..eadb56e07 100644 --- a/test/ios/mocked_data/test_get_probes_config/normal/show_run___include_ip_sla__0_9_.txt +++ b/test/ios/mocked_data/test_get_probes_config/normal/show_run___section_ip_sla__0_9_.txt @@ -11,4 +11,10 @@ ip sla 2 history lives-kept 1 history buckets-kept 20 timeout 2000 - frequency 3 \ No newline at end of file + frequency 3 +ip sla 3 + icmp-echo 9.9.9.9 source-interface GigabitEthernet11 + tag quad9 + frequency 15 + history lives-kept 1 + history buckets-kept 60