Skip to content

Commit

Permalink
New Template: Linux - arp -a (networktocode#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
jifox authored Oct 22, 2020
1 parent f867c9e commit cd98f57
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 54 deletions.
2 changes: 2 additions & 0 deletions templates/index
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
11 changes: 11 additions & 0 deletions templates/linux_arp_-a.textfsm
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/linux/arp_-a/linux_arp_a.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
? (192.168.13.197) at 00:04:4b:cc:9c:ba [ether] on eth1.100
? (192.168.10.100) at <incomplete> 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 <incomplete> 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
48 changes: 48 additions & 0 deletions tests/linux/arp_-a/linux_arp_a.yml
Original file line number Diff line number Diff line change
@@ -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: "?"
110 changes: 56 additions & 54 deletions tests/test_index_order.py
Original file line number Diff line number Diff line change
@@ -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
):
Expand Down Expand Up @@ -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 = ""
Expand All @@ -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)
Expand Down

0 comments on commit cd98f57

Please sign in to comment.