From d322c773d346514b2eb47fa12283cdcbe7738011 Mon Sep 17 00:00:00 2001 From: jifox Date: Thu, 22 Oct 2020 16:07:18 +0200 Subject: [PATCH] New Template: Linux - arp -a (#814) --- templates/index | 2 + templates/linux_arp_-a.textfsm | 11 +++ tests/linux/arp_-a/linux_arp_a.raw | 9 +++ tests/linux/arp_-a/linux_arp_a.yml | 48 +++++++++++++ tests/test_index_order.py | 110 +++++++++++++++-------------- 5 files changed, 126 insertions(+), 54 deletions(-) create mode 100644 templates/linux_arp_-a.textfsm 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/templates/index b/templates/index index 49661f748b..8870dec78d 100644 --- a/templates/index +++ b/templates/index @@ -403,6 +403,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..8f058a453f --- /dev/null +++ b/templates/linux_arp_-a.textfsm @@ -0,0 +1,11 @@ +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+\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.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..793442a5a7 --- /dev/null +++ b/tests/linux/arp_-a/linux_arp_a.yml @@ -0,0 +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: "" + 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: "?" 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)