Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: empty line crash in 1.6.41 but not 1.6.40 #248

Closed
1 task done
FliesLikeABrick opened this issue Oct 3, 2022 · 2 comments
Closed
1 task done

[Bug]: empty line crash in 1.6.41 but not 1.6.40 #248

FliesLikeABrick opened this issue Oct 3, 2022 · 2 comments
Labels

Comments

@FliesLikeABrick
Copy link

FliesLikeABrick commented Oct 3, 2022

Contact Details

Via issue ticket

What happened?

Backtrace in init, _bootstrap_obj_init_ios, assign_parent_to_closing_braces

On 1.6.40 and older the code has run without failure

CiscoConfParse Version

1.6.41

What Operating System are you using?

Linux - Debian, Ubuntu, CentOS, RHEL or others, Other (please specify): CentOS 7.x and Cygwin

What Python version(s) have this problem?

Python 3.6.9, 3.6.8. Probably others/all, we have not found a python version that avoids this issue

Show us how to reproduce the problem. Please tell us if the problem is specific to certain inputs or situations.

# note newline in `config`
config = """feature fex

feature lldp""".splitlines()


from ciscoconfparse import CiscoConfParse
parse = CiscoConfParse(config, syntax="ios")

Python tracebacks

>>> parse = CiscoConfParse(config, syntax="ios")
2022-10-03 11:05:01.132 | ERROR    | ciscoconfparse.ciscoconfparse:_bootstrap_obj_init_ios:5317 - An error has been caught in function '_bootstrap_obj_init_ios', process 'MainProcess' (1473), thread 'MainThread' (25769803792):
Traceback (most recent call last):

  File "<stdin>", line 1, in <module>
  File "/home/ryarawdo/env/lib/python3.6/site-packages/ciscoconfparse/ciscoconfparse.py", line 506, in __init__
    ccp_ref=self,
            └ <CiscoConfParse: None lines / syntax: ios / comment delimiter: '!' / factory: False / encoding: 'UTF-8'>
  File "/home/ryarawdo/env/lib/python3.6/site-packages/ciscoconfparse/ciscoconfparse.py", line 4445, in __init__
    self._list = self._bootstrap_obj_init_ios(initlist)
    │    │       │    │                       └ ['feature fex\n', '\n', 'feature lldp\n']
    │    │       │    └ <function ConfigList._bootstrap_obj_init_ios at 0x6fffdf307b8>
    │    │       └ <ConfigList, syntax='ios', comment='!', conf=[<IOSCfgLine # 0 'feature fex
    │    │         '>, <IOSCfgLine # 1 '
    │    │         ' (parent is # 0)>, <IOSCfgL...
    │    └ [<IOSCfgLine # 0 'feature fex
    │      '>, <IOSCfgLine # 1 '' (parent is # 0)>, <IOSCfgLine # 2 'feature lldp
    │      '>]
    └ <ConfigList, syntax='ios', comment='!', conf=[<IOSCfgLine # 0 'feature fex
      '>, <IOSCfgLine # 1 '
      ' (parent is # 0)>, <IOSCfgL...
> File "/home/ryarawdo/env/lib/python3.6/site-packages/ciscoconfparse/ciscoconfparse.py", line 5317, in _bootstrap_obj_init_ios
    self._list = assign_parent_to_closing_braces(input_list=self._list)
    │    │       │                                          │    └ [<IOSCfgLine # 0 'feature fex
    │    │       │                                          │      '>, <IOSCfgLine # 1 '
    │    │       │                                          │      ' (parent is # 0)>, <IOSCfgLine # 2 'feature lldp
    │    │       │                                          │      '>]
    │    │       │                                          └ <ConfigList, syntax='ios', comment='!', conf=[<IOSCfgLine # 0 'feature fex
    │    │       │                                            '>, <IOSCfgLine # 1 '
    │    │       │                                            ' (parent is # 0)>, <IOSCfgL...
    │    │       └ <function assign_parent_to_closing_braces at 0x6fffdf7ee18>
    │    └ [<IOSCfgLine # 0 'feature fex
    │      '>, <IOSCfgLine # 1 '' (parent is # 0)>, <IOSCfgLine # 2 'feature lldp
    │      '>]
    └ <ConfigList, syntax='ios', comment='!', conf=[<IOSCfgLine # 0 'feature fex
      '>, <IOSCfgLine # 1 '
      ' (parent is # 0)>, <IOSCfgL...
  File "/home/ryarawdo/env/lib/python3.6/site-packages/ciscoconfparse/ciscoconfparse.py", line 338, in assign_parent_to_closing_braces
    if len(obj.text)>=1 and obj.text.rstrip()[-1] == '{':
           │   │            │   └ <property object at 0x6fffe0dd908>
           │   │            └ <IOSCfgLine # 1 '
           │   │              ' (parent is # 0)>
           │   └ <property object at 0x6fffe0dd908>
           └ <IOSCfgLine # 1 '
             ' (parent is # 0)>

IndexError: string index out of range

Relevant log output

No response

Code of Conduct

@FliesLikeABrick
Copy link
Author

Issue does not occur if the empty line is taken out of the config, or if <= 1.6.40 is used.

Cisco NX-OS 7.3 and others do generate configurations with blank lines, for example this is the last output of "show run" on a device of ours:
logging logfile messages 6
logging server 10.110.180.23
logging server 10.30.183.174
logging source-interface loopback0
logging timestamp milliseconds
logging monitor 6
logging level local6 6
no logging console

scheduler aaa-authentication username VCC_Network_Cisco password 7 redacted

scheduler job name auto_checkpoint
checkpoint

end-job

scheduler job name VCC_NW_Cisco_auto_checkpoint
checkpoint

end-job

scheduler schedule name 8hr_checkpoint
job name auto_checkpoint
time start 2013:03:12:21:14 repeat 0:8:0

scheduler schedule name 8hr_checkpoint_VCC_NW_Cisco
job name VCC_NW_Cisco_auto_checkpoint
time start 2017:06:01:17:42 repeat 0:8:0

@mpenning
Copy link
Owner

mpenning commented Oct 4, 2022

Hello,

from ciscoconfparse import CiscoConfParse
config = """feature fex

feature lldp""".splitlines()
parse = CiscoConfParse(config, syntax="nxos", ignore_blank_lines=False)
print(parse.ioscfg)
['feature fex', '', 'feature lldp']

@mpenning mpenning closed this as completed Oct 4, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants