Short feedback on Cisco pyATS and Genie Parser

Vincent Bernat

Cisco pyATS is a frame­work for net­work au­to­ma­tion and test­ing. It in­cludes, among other things, an open-source multi-ven­dor set of parsers and mod­els, Ge­nie Parser. It fea­tures 2700 parsers for var­i­ous com­mands over many net­work OS. On pa­per, this seems like a great tool!

>>> from genie.conf.base import Device
>>> device = Device("router", os="iosxr")
>>> # Hack to parse outputs without connecting to a device
>>> device.custom.setdefault("abstraction", {})["order"] = ["os", "platform"]
>>> cmd = "show route ipv4 unicast"
>>> output = """
... Tue Oct 29 21:29:10.924 UTC
...
... O    10.13.110.0/24 [110/2] via 10.12.110.1, 5d23h, GigabitEthernet0/0/0/0.110
... """
>>> device.parse(cmd, output=output)
{'vrf': {'default': {'address_family': {'ipv4': {'routes': {'10.13.110.0/24': {'route': '10.13.110.0/24',
       'active': True,
       'route_preference': 110,
       'metric': 2,
       'source_protocol': 'ospf',
       'source_protocol_codes': 'O',
       'next_hop': {'next_hop_list': {1: {'index': 1,
          'next_hop': '10.12.110.1',
          'outgoing_interface': 'GigabitEthernet0/0/0/0.110',
          'updated': '5d23h'}}}}}}}}}}

First dis­ap­point­ment: pyATS is closed-source with some ex­cep­tions. This is quite an­noy­ing if you run into some is­sues out­side Ge­nie Parser. For ex­am­ple, al­though pyATS uses the ssh com­mand, it can­not lever­age my ssh_​config file: pyATS re­solves host­names be­fore pro­vid­ing them to ssh. There is no plan to open source pyATS. 🤨

Then, Ge­nie Parser has two problems:

  1. The data mod­els used are de­pen­dent on the ven­dor and OS, de­spite the doc­u­men­ta­tion say­ing oth­er­wise. For ex­am­ple, the data model used for IPv4 in­ter­faces is dif­fer­ent be­tween NX-OS and IOS XR.
  2. The parsers rely on line-by-line reg­u­lar ex­pres­sions to ex­tract data and some Python code as glue. This is frag­ile and may break silently.

To il­lus­trate the sec­ond point, let’s as­sume the out­put of show ipv4 vrf all interface is:

Loopback10 is Up, ipv4 protocol is Up
  Vrf is default (vrfid 0x60000000)
  Internet protocol processing disabled
Loopback30 is Up, ipv4 protocol is Down [VRF in FWD reference]
  Vrf is ran (vrfid 0x0)
  Internet address is 203.0.113.17/32
  MTU is 1500 (1500 is available to IP)
  Helper address is not set
  Directed broadcast forwarding is disabled
  Outgoing access list is not set
  Inbound  common access list is not set, access list is not set
  Proxy ARP is disabled
  ICMP redirects are never sent
  ICMP unreachables are always sent
  ICMP mask replies are never sent
  Table Id is 0x0

Be­cause the reg­u­lar ex­pres­sion to parse an in­ter­face name does not ex­pect the ex­tra data af­ter the in­ter­face state, Ge­nie Parser ig­nores the line start­ing the def­i­ni­tion of Loopback30 and parses the out­put to this structure:1

{
  "Loopback10": {
    "int_status": "up",
    "oper_status": "up",
    "vrf": "ran",
    "vrf_id": "0x0",
    "ipv4": {
      "203.0.113.17/32": {
        "ip": "203.0.113.17",
        "prefix_length": "32"
      },
      "mtu": 1500,
      "mtu_available": 1500,
      "broadcast_forwarding": "disabled",
      "proxy_arp": "disabled",
      "icmp_redirects": "never sent",
      "icmp_unreachables": "always sent",
      "icmp_replies": "never sent",
      "table_id": "0x0"
    }
  }
}

While this bug is sim­ple to fix, this is an up­hill bat­tle. Any ex­ist­ing or fu­ture slight vari­a­tion in the out­put of a com­mand could trig­ger an­other sim­i­lar un­de­tected bug, de­spite the ex­tended test cov­er­age. I have re­ported and fixed sev­eral other silent pars­ing er­rors: #516, #529, and #530. A more ro­bust al­ter­na­tive would have been to use TextFSM and to trig­ger a warn­ing when some out­put is not rec­og­nized, like Bat­fish, a con­fig­u­ra­tion anal­y­sis tool, does.

In the fu­ture, we should rely on YANG for data ex­trac­tion, but it is cur­rently not widely sup­ported. SNMP is still a valid pos­si­bil­ity but much in­for­ma­tion is not ac­ces­si­ble through this pro­to­col. In the mean­time, I would ad­vise you to only use Ge­nie Parser with caution.