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
797 stars 220 forks source link

IOSConfigLine.delete() can delete too much #37

Closed mpenning closed 9 years ago

mpenning commented 9 years ago

As of CiscoConfParse version 1.2.18, calling delete() on an IOSConfigLine() can delete too many config lines... this is an example....

from ciscoconfparse import CiscoConfParse
CONFIG = ['!',
    'interface GigabitEthernet0/0',
    ' ip address 10.0.0.1 255.255.255.0',
    'banner motd ^', '    trivial banner1 here ^',   ## Deleting this banner line fails
    'interface GigabitEthernet0/1',
    ' ip address 192.0.2.1 255.255.255.0',
    'banner exec ^', '    trivial banner2 here ^',
    'end'] 

parse = CiscoConfParse(CONFIG)
banner = parse.find_objects('banner motd')[0]
banner.delete()
parse.atomic()

The code above fails with:

Traceback (most recent call last):
  File "banner.py", line 18, in <module>
    banner.delete()
  File "/home/mpenning/fail/ciscoconfparse/ccp_abc.py", line 198, in delete
    child.delete()
  File "/home/mpenning/fail/ciscoconfparse/ccp_abc.py", line 199, in delete
    del self.confobj._list[self.linenum]
IndexError: list assignment index out of range
mpenning commented 9 years ago

Fixed in 1.2.19