From a8317600b065d60d0567195c6cad4383190c3a47 Mon Sep 17 00:00:00 2001 From: Josef Fuchs Date: Tue, 20 Oct 2020 10:42:12 +0200 Subject: [PATCH 1/5] Add Linux (arp -a) template linux_arp_a.textfsm --- templates/index | 2 ++ templates/linux_arp_a.textfsm | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 templates/linux_arp_a.textfsm diff --git a/templates/index b/templates/index index 9bb76f0e90..1bc184fb7e 100644 --- a/templates/index +++ b/templates/index @@ -402,6 +402,8 @@ juniper_junos_show_version.textfsm, .*, juniper_junos, sh[[ow]] ver[[sion]] juniper_screenos_get_route.textfsm, .*, juniper_screenos, get route +linux_arp_a.textfsm, .*, linux, arp -a + paloalto_panos_show_running_security-policy.textfsm, .*, paloalto_panos, sh[[ow]] runn[[ing]] security[[-policy]] paloalto_panos_show_high-availability_all.textfsm, .*, paloalto_panos, sh[[ow]] high[[-availability]] all paloalto_panos_show_interface_management.textfsm, .*, paloalto_panos, sh[[ow]] int[[erface]] man[[agement]] diff --git a/templates/linux_arp_a.textfsm b/templates/linux_arp_a.textfsm new file mode 100644 index 0000000000..b16b7ea079 --- /dev/null +++ b/templates/linux_arp_a.textfsm @@ -0,0 +1,8 @@ +Value REV_DNS (\S+) +Value IP_ADDRESS (\S+) +Value MAC_ADDRESS (\S+) +Value HW_TYPE (\S+) +Value INTERFACE (\S+) + +Start + ^${REV_DNS}\s+\(${IP_ADDRESS}\)\s+at\s+${MAC_ADDRESS}\s+\[${HW_TYPE}\]\s+on\s+${INTERFACE}$$ -> Record From a171efd102e8463b974fc0a5b7e75f992b5a9068 Mon Sep 17 00:00:00 2001 From: Josef Fuchs Date: Tue, 20 Oct 2020 18:34:28 +0200 Subject: [PATCH 2/5] added tests for linux arp -a --- tests/linux/arp_a/linux_arp_a.raw | 9 ++++++++ tests/linux/arp_a/linux_arp_a.yml | 37 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/linux/arp_a/linux_arp_a.raw create mode 100644 tests/linux/arp_a/linux_arp_a.yml diff --git a/tests/linux/arp_a/linux_arp_a.raw b/tests/linux/arp_a/linux_arp_a.raw new file mode 100644 index 0000000000..b222c25435 --- /dev/null +++ b/tests/linux/arp_a/linux_arp_a.raw @@ -0,0 +1,9 @@ +? (192.168.13.197) at 00:04:4b:cc:9c:ba [ether] on eth1.100 +? (192.168.10.100) at on eth1.10 +? (192.168.13.252) at 5c:e2:8c:fc:a4:74 [ether] on eth1.100 +esxi (192.168.13.5) at 00:e0:67:05:9d:5a [ether] on eth1.100 +? (192.168.13.253) at dc:f7:19:cd:d6:c4 [ether] on eth1.100 +? (192.168.123.199) at 00:0f:c9:0e:c8:ec [ether] on eth0.21 +? (192.168.10.52) at on eth1.10 +? (192.168.10.7) at 00:0c:29:02:3b:93 [ether] on eth1.10 +? (192.168.10.249) at 00:0c:29:bb:5f:a2 [ether] on eth1.10 diff --git a/tests/linux/arp_a/linux_arp_a.yml b/tests/linux/arp_a/linux_arp_a.yml new file mode 100644 index 0000000000..a60af088af --- /dev/null +++ b/tests/linux/arp_a/linux_arp_a.yml @@ -0,0 +1,37 @@ +--- +parsed_sample: + - hw_type: "ether" + interface: "eth1.100" + ip_address: "192.168.13.197" + mac_address: "00:04:4b:cc:9c:ba" + rev_dns: "?" + - hw_type: "ether" + interface: "eth1.100" + ip_address: "192.168.13.252" + mac_address: "5c:e2:8c:fc:a4:74" + rev_dns: "?" + - hw_type: "ether" + interface: "eth1.100" + ip_address: "192.168.13.5" + mac_address: "00:e0:67:05:9d:5a" + rev_dns: "esxi" + - hw_type: "ether" + interface: "eth1.100" + ip_address: "192.168.13.253" + mac_address: "dc:f7:19:cd:d6:c4" + rev_dns: "?" + - hw_type: "ether" + interface: "eth0.21" + ip_address: "192.168.123.199" + mac_address: "00:0f:c9:0e:c8:ec" + rev_dns: "?" + - hw_type: "ether" + interface: "eth1.10" + ip_address: "192.168.10.7" + mac_address: "00:0c:29:02:3b:93" + rev_dns: "?" + - hw_type: "ether" + interface: "eth1.10" + ip_address: "192.168.10.249" + mac_address: "00:0c:29:bb:5f:a2" + rev_dns: "?" From 509ae94cb49d15ab1525544035f1b0bc073e8aec Mon Sep 17 00:00:00 2001 From: jifox Date: Wed, 21 Oct 2020 05:46:26 +0200 Subject: [PATCH 3/5] Added missing validation Validate that all output was captured as expected --- templates/linux_arp_a.textfsm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/linux_arp_a.textfsm b/templates/linux_arp_a.textfsm index b16b7ea079..7c2c1e71a8 100644 --- a/templates/linux_arp_a.textfsm +++ b/templates/linux_arp_a.textfsm @@ -6,3 +6,5 @@ Value INTERFACE (\S+) Start ^${REV_DNS}\s+\(${IP_ADDRESS}\)\s+at\s+${MAC_ADDRESS}\s+\[${HW_TYPE}\]\s+on\s+${INTERFACE}$$ -> Record + ^\s*$$ + ^. -> Error From da1b5576827cd7f210646dd27c8c2782e3b4d073 Mon Sep 17 00:00:00 2001 From: Josef Fuchs Date: Wed, 21 Oct 2020 19:52:36 +0200 Subject: [PATCH 4/5] Add regex for mac address output --- templates/linux_arp_a.textfsm | 5 +- tests/linux/arp_a/linux_arp_a.yml | 85 +++++++++++++++++-------------- 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/templates/linux_arp_a.textfsm b/templates/linux_arp_a.textfsm index b16b7ea079..8f058a453f 100644 --- a/templates/linux_arp_a.textfsm +++ b/templates/linux_arp_a.textfsm @@ -5,4 +5,7 @@ Value HW_TYPE (\S+) Value INTERFACE (\S+) Start - ^${REV_DNS}\s+\(${IP_ADDRESS}\)\s+at\s+${MAC_ADDRESS}\s+\[${HW_TYPE}\]\s+on\s+${INTERFACE}$$ -> Record + ^${REV_DNS}\s+\(${IP_ADDRESS}\)\s+\S+\s+${MAC_ADDRESS}\s+\[${HW_TYPE}\]\s+\S+\s+${INTERFACE}$$ -> Record + ^${REV_DNS}\s+\(${IP_ADDRESS}\)\s+\S+\s+<${MAC_ADDRESS}>\s+\S+\s+${INTERFACE}$$ -> Record + ^\s*$$ + ^. -> Error diff --git a/tests/linux/arp_a/linux_arp_a.yml b/tests/linux/arp_a/linux_arp_a.yml index a60af088af..793442a5a7 100644 --- a/tests/linux/arp_a/linux_arp_a.yml +++ b/tests/linux/arp_a/linux_arp_a.yml @@ -1,37 +1,48 @@ ---- -parsed_sample: - - hw_type: "ether" - interface: "eth1.100" - ip_address: "192.168.13.197" - mac_address: "00:04:4b:cc:9c:ba" - rev_dns: "?" - - hw_type: "ether" - interface: "eth1.100" - ip_address: "192.168.13.252" - mac_address: "5c:e2:8c:fc:a4:74" - rev_dns: "?" - - hw_type: "ether" - interface: "eth1.100" - ip_address: "192.168.13.5" - mac_address: "00:e0:67:05:9d:5a" - rev_dns: "esxi" - - hw_type: "ether" - interface: "eth1.100" - ip_address: "192.168.13.253" - mac_address: "dc:f7:19:cd:d6:c4" - rev_dns: "?" - - hw_type: "ether" - interface: "eth0.21" - ip_address: "192.168.123.199" - mac_address: "00:0f:c9:0e:c8:ec" - rev_dns: "?" - - hw_type: "ether" - interface: "eth1.10" - ip_address: "192.168.10.7" - mac_address: "00:0c:29:02:3b:93" - rev_dns: "?" - - hw_type: "ether" - interface: "eth1.10" - ip_address: "192.168.10.249" - mac_address: "00:0c:29:bb:5f:a2" - rev_dns: "?" +--- + +parsed_sample: + - hw_type: "ether" + interface: "eth1.100" + ip_address: "192.168.13.197" + mac_address: "00:04:4b:cc:9c:ba" + rev_dns: "?" + - hw_type: "" + interface: "eth1.10" + ip_address: "192.168.10.100" + mac_address: "incomplete" + rev_dns: "?" + - hw_type: "ether" + interface: "eth1.100" + ip_address: "192.168.13.252" + mac_address: "5c:e2:8c:fc:a4:74" + rev_dns: "?" + - hw_type: "ether" + interface: "eth1.100" + ip_address: "192.168.13.5" + mac_address: "00:e0:67:05:9d:5a" + rev_dns: "esxi" + - hw_type: "ether" + interface: "eth1.100" + ip_address: "192.168.13.253" + mac_address: "dc:f7:19:cd:d6:c4" + rev_dns: "?" + - hw_type: "ether" + interface: "eth0.21" + ip_address: "192.168.123.199" + mac_address: "00:0f:c9:0e:c8:ec" + rev_dns: "?" + - hw_type: "" + interface: "eth1.10" + ip_address: "192.168.10.52" + mac_address: "incomplete" + rev_dns: "?" + - hw_type: "ether" + interface: "eth1.10" + ip_address: "192.168.10.7" + mac_address: "00:0c:29:02:3b:93" + rev_dns: "?" + - hw_type: "ether" + interface: "eth1.10" + ip_address: "192.168.10.249" + mac_address: "00:0c:29:bb:5f:a2" + rev_dns: "?" From 552be810b6c4c1db4223f59af396ba62ead6feb2 Mon Sep 17 00:00:00 2001 From: jmcgill298 Date: Wed, 21 Oct 2020 15:32:15 -0400 Subject: [PATCH 5/5] BugFix: Correctly derive OS name from template name --- templates/index | 2 +- ...nux_arp_a.textfsm => linux_arp_-a.textfsm} | 0 tests/linux/{arp_a => arp_-a}/linux_arp_a.raw | 0 tests/linux/{arp_a => arp_-a}/linux_arp_a.yml | 0 tests/test_index_order.py | 110 +++++++++--------- 5 files changed, 57 insertions(+), 55 deletions(-) rename templates/{linux_arp_a.textfsm => linux_arp_-a.textfsm} (100%) rename tests/linux/{arp_a => arp_-a}/linux_arp_a.raw (100%) rename tests/linux/{arp_a => arp_-a}/linux_arp_a.yml (100%) diff --git a/templates/index b/templates/index index 1bc184fb7e..0e69fba1ff 100644 --- a/templates/index +++ b/templates/index @@ -402,7 +402,7 @@ juniper_junos_show_version.textfsm, .*, juniper_junos, sh[[ow]] ver[[sion]] juniper_screenos_get_route.textfsm, .*, juniper_screenos, get route -linux_arp_a.textfsm, .*, linux, arp -a +linux_arp_-a.textfsm, .*, linux, arp -a paloalto_panos_show_running_security-policy.textfsm, .*, paloalto_panos, sh[[ow]] runn[[ing]] security[[-policy]] paloalto_panos_show_high-availability_all.textfsm, .*, paloalto_panos, sh[[ow]] high[[-availability]] all diff --git a/templates/linux_arp_a.textfsm b/templates/linux_arp_-a.textfsm similarity index 100% rename from templates/linux_arp_a.textfsm rename to templates/linux_arp_-a.textfsm diff --git a/tests/linux/arp_a/linux_arp_a.raw b/tests/linux/arp_-a/linux_arp_a.raw similarity index 100% rename from tests/linux/arp_a/linux_arp_a.raw rename to tests/linux/arp_-a/linux_arp_a.raw diff --git a/tests/linux/arp_a/linux_arp_a.yml b/tests/linux/arp_-a/linux_arp_a.yml similarity index 100% rename from tests/linux/arp_a/linux_arp_a.yml rename to tests/linux/arp_-a/linux_arp_a.yml diff --git a/tests/test_index_order.py b/tests/test_index_order.py index 84d05b6c0e..a6e378991b 100755 --- a/tests/test_index_order.py +++ b/tests/test_index_order.py @@ -1,14 +1,63 @@ #!/usr/bin/env python - -import pytest -import csv import os -import glob +import re import csv +import glob + +import pytest from tests import load_index_data +OS_CHOICES = [ + "a10", + "alcatel_aos", + "alcatel_sros", + "arista_eos", + "aruba_os", + "avaya_ers", + "avaya_vsp", + "broadcom_icos", + "brocade_fastiron", + "brocade_netiron", + "brocade_nos", + "brocade_vdx", + "brocade_vyos", + "checkpoint_gaia", + "ciena_saos", + "cisco_asa", + "cisco_ftd", + "cisco_ios", + "cisco_nxos", + "cisco_s300", + "cisco_wlc", + "cisco_xe", + "cisco_xr", + "dell_force10", + "enterasys", + "extreme", + "f5_ltm", + "fortinet_fortios", + "hp_comware", + "hp_procurve", + "huawei_vrp", + "juniper", + "juniper_junos", + "juniper_screenos", + "linux", + "ovs_linux", + "paloalto_panos", + "quanta_mesh", + "ruckus_fastiron", + "ubiquiti_edgeswitch", + "vmware_nsxv", + "vyatta_vyos", + "vyos", + "watchguard_firebox", +] +RE_TEMPLATE_OS = re.compile("^(" + "|".join(OS_CHOICES) + ")") + + def check_order( current_os, prior_os, cmd_len, prior_len, os_choices, used_os, cmd, prior_cmd ): @@ -60,54 +109,6 @@ def check_order( def test_index_ordering(): - - os_choices = [ - "a10", - "alcatel_aos", - "alcatel_sros", - "arista_eos", - "aruba_os", - "avaya_ers", - "avaya_vsp", - "broadcom_icos", - "brocade_fastiron", - "brocade_netiron", - "brocade_nos", - "brocade_vdx", - "brocade_vyos", - "checkpoint_gaia", - "ciena_saos", - "cisco_asa", - "cisco_ftd", - "cisco_ios", - "cisco_nxos", - "cisco_s300", - "cisco_wlc", - "cisco_xe", - "cisco_xr", - "dell_force10", - "enterasys", - "extreme", - "f5_ltm", - "fortinet_fortios", - "hp_comware", - "hp_procurve", - "huawei_vrp", - "juniper", - "juniper_junos", - "juniper_screenos", - "linux", - "ovs_linux", - "paloalto_panos", - "quanta_mesh", - "ruckus_fastiron", - "ubiquiti_edgeswitch", - "vmware_nsxv", - "vyatta_vyos", - "vyos", - "watchguard_firebox", - ] - prior_os = "" prior_len = 0 prior_cmd = "" @@ -116,11 +117,12 @@ def test_index_ordering(): index = load_index_data() for row in index: template = row[0].strip() - os = "_".join(template.split("_")[:2]) + os_match = RE_TEMPLATE_OS.match(template) + os = os_match.group(0) cmd = "_".join(template.split("_")[2:]) cmd_len = len(cmd) check_val, check_msg = check_order( - os, prior_os, cmd_len, prior_len, os_choices, used_os, cmd, prior_cmd + os, prior_os, cmd_len, prior_len, OS_CHOICES, used_os, cmd, prior_cmd ) if not check_val: # assertFalse(check_val, msg=check_msg)