miron0xff / vyatta-conf-parser

Config parser for Vyatta/VyOS
MIT License
20 stars 11 forks source link

Incorrect handling of multi-value nodes #8

Open dmbaturin opened 4 years ago

dmbaturin commented 4 years ago

Some nodes can have multiple values, like "address" in interfaces. Your parser confuses them with tag nodes. A useful rule of thumb is presence of a left curly brace on the same line. Leaf nodes never have them, tag nodes always do.

>>> import vyattaconfparser
>>> conf="""
... ethernet eth0 {
...   address 192.0.2.1/24
...   address 192.0.2.2/24
... }
... """
>>> 
>>> vyattaconfparser.parse_conf(conf)
{'ethernet': {'eth0': {'address': {'192.0.2.1/24': {}, '192.0.2.2/24': {}}}}}

For the record, there's now built-in, fully "anatomically correct" parser and Python3 bindings for it that power the migration scripts and in the latest rolling release, the vyos.config library, and it can manipulate the trees in memory (it's a part of the future config backend to replace libvyattacfg).

Installing it on random machine is not quite easy since it has native code dependencies (https://github.com/vyos/libvyosconfig/), so an independent pure Python "config to a dict" parser retains its value.

miron0xff commented 4 years ago

Hello, thanks for your time inspecting this lib. Yes, I know about this behaviour. First test shows it. https://github.com/hedin/vyatta-conf-parser/blob/master/test_vyattaconfparser.py#L33