networktocode / ntc-rosetta

The missing bridge between industry standard CLIs and YANG
https://ntc-rosetta.readthedocs.io/en/latest/index.html
Apache License 2.0
103 stars 23 forks source link

IOS config parsing error #23

Closed neill-k closed 4 years ago

neill-k commented 5 years ago

When the command vlan internal allocation policy ascending is present, parser fails with invalid literal for int() with base 10: 'internal'

Need to ignore that command, as the parser is trying to parse "internal" as a vlan id.

Stack trace follows:

Traceback (most recent call last):
  File "test.py", line 10, in <module>
    parsed = ios_driver.parse(native={"dev_conf": config})
  File "/home/nkillgore/.local/lib/python3.6/site-packages/ntc_rosetta/drivers/base.py", line 88, in parse
    root = parser.process(validate=validate)
  File "/home/nkillgore/.local/lib/python3.6/site-packages/yangify/parser/__init__.py", line 346, in process
    r = super()._process_container(self.config, self.state, [])
  File "/home/nkillgore/.local/lib/python3.6/site-packages/yangify/parser/__init__.py", line 214, in _process_container
    r = attr._process_container(config, state, [])
  File "/home/nkillgore/.local/lib/python3.6/site-packages/yangify/parser/__init__.py", line 225, in _process_container
    r = attr._process_list(config, state)
  File "/home/nkillgore/.local/lib/python3.6/site-packages/yangify/parser/__init__.py", line 267, in _process_list
    r = self._process_container(config, state, keys)
  File "/home/nkillgore/.local/lib/python3.6/site-packages/yangify/parser/__init__.py", line 214, in _process_container
    r = attr._process_container(config, state, [])
  File "/home/nkillgore/.local/lib/python3.6/site-packages/yangify/parser/__init__.py", line 225, in _process_container
    r = attr._process_list(config, state)
  File "/home/nkillgore/.local/lib/python3.6/site-packages/yangify/parser/__init__.py", line 267, in _process_list
    r = self._process_container(config, state, keys)
  File "/home/nkillgore/.local/lib/python3.6/site-packages/yangify/parser/__init__.py", line 242, in _process_container
    r = c()
  File "/home/nkillgore/.local/lib/python3.6/site-packages/ntc_rosetta/parsers/openconfig/ios/openconfig_vlan/vlans.py", line 44, in vlan_id
    return int(self.yy.key)
ValueError: invalid literal for int() with base 10: 'internal'

VLAN portion of config where it fails:

!
vlan internal allocation policy ascending
!
vlan 100
 name vlan100
!
vlan 300
 name vlan300
!
vlan 315
 name vlan315
!
vlan 915
 name vlan915
!
jathanism commented 5 years ago

It appears that this isn't (yet) supported by the OpenConfig YANG model for VLANs.

On which version of IOS is this, and on what hardware platform? Thanks.

neill-k commented 5 years ago

The switch is old. The IOS release is from 2016. I can strip the line before passing the config to the parser; it's not something I (or probably anyone) need modeled.

Switch Ports Model              SW Version            SW Image
------ ----- -----              ----------            ----------
*    1 26    WS-C2960-24TC-L    15.0(2)SE10a          C2960-LANBASEK9-M
jathanism commented 5 years ago

That wold be the quickest win for you to strip the line before passing in the config...

There is support for this in the Cisco-managed YANG models for IOS 16.x, but we don't have support for that in Rosetta yet. Still much work to be done on the grand scheme.

For example: https://github.com/YangModels/yang/blob/master/vendor/cisco/xe/16101/Cisco-IOS-XE-vlan.yang

ktbyers commented 5 years ago

I ran into that same issue on Cisco IOS:

Cisco IOS XE Software, Version 16.08.01

That is a very common config in Cisco switch land:

vlan internal allocation policy ascending

I will try stripping that config out with a preprocessor

dgjustice commented 4 years ago

This simply needs to be fixed in the parser. There are a few different commands starting with vlan that don't end in an integer.

cat9k(config)#vlan ?
  WORD           ISL VLAN IDs 1-4094
  access-map     Create vlan access-map or enter vlan access-map command mode
  accounting     VLAN accounting configuration
  configuration  vlan feature configuration mode
  dot1q          dot1q parameters
  filter         Apply a VLAN Map
  group          Create a vlan group
FragmentedPacket commented 4 years ago

I put in PR (#35) for this and would welcome any feedback.