mpenning / ciscoconfparse

Parse, Audit, Query, Build, and Modify Arista / Cisco / Juniper / Palo Alto / F5 configurations.
http://www.pennington.net/py/ciscoconfparse/
GNU General Public License v3.0
793 stars 220 forks source link

insert_after() and insert_before() broken between versions 1.5.48 and 1.5.51 #209

Closed thecityofguanyu closed 2 years ago

thecityofguanyu commented 3 years ago

Version:

~/ pip show ciscoconfparse
Name: ciscoconfparse
Version: 1.5.50
Summary: UNKNOWN
Home-page: http://www.pennington.net/py/ciscoconfparse/
Author: David Michael Pennington
Author-email: mike@pennington.net
License: GPLv3
Location: /Users/user/Documents/venv/lib/python3.9/site-packages
Requires: colorama, loguru, passlib, dnspython
Required-by: 

Snippet from ASA config:

interface GigabitEthernet0/6
 no shutdown
 no nameif
 no security-level
 no ip address

Library usage:

from ciscoconfparse import CiscoConfParse
config = "asa.cfg"
parse = CiscoConfParse(config, syntax="asa")
parse.insert_after('interface GigabitEthernet0/6', new_val='interface GigabitEthernet0/6.30')

Exception thrown:

python asa_config_sync.py
Traceback (most recent call last):
  File "/Users/user/Documents/asa_config_sync.py", line 42, in <module>
    parse.insert_after(r'interface\sGigabitEthernet0/6', 'interface\sGigabitEthernet0/6.30')
  File "/Users/user/Documents/venv/lib/python3.9/site-packages/ciscoconfparse/ciscoconfparse.py", line 2006, in insert_after
    self.ConfigObjs.insert_after(exist_val, new_val, atomic=atomic)
  File "/Users/user/Documents/venv/lib/python3.9/site-packages/ciscoconfparse/ciscoconfparse.py", line 4250, in insert_after
    raise ValueError
mpenning commented 2 years ago

Thank you for this report! This wound up being a pretty bad config insertion bug (worse than I realized, until today). These versions are exposed to it: 1.5.48, 1.5.49, 1.5.50, and 1.5.51.

Github issue #209 is fixed in 1.6.0. Unit tests updated to catch this problem if a regression is introduced.

Please test and advise.

mpenning commented 2 years ago

Please feel free to re-open if there's a problem... this should be fixed...