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

IndexError: string index out of range #286

Closed
sc68cal opened this issue Sep 13, 2023 · 5 comments
Closed

IndexError: string index out of range #286

sc68cal opened this issue Sep 13, 2023 · 5 comments
Labels

Comments

@sc68cal
Copy link

sc68cal commented Sep 13, 2023

I am trying to use pyEAPI with an Arista switch, and it appears that the code is broken, since all the API calls (vlans, bgp, etc) do not work...

>>> conn = pyeapi.connect(host='REDACTED', transport='http')
>>> conn.execute('show version')
{'jsonrpc': '2.0', 'id': '4378960720', 'result': [{'imageFormatVersion': '3.0', 'uptime': 6903160.73, 'modelName': 'DCS-7280SR2-48YC6-R', 'internalVersion': '4.28.3M-28837868.4283M', 'memTotal': 8098932, 'mfgName': 'Arista', 'serialNumber': '', 'systemMacAddress': '', 'bootupTimestamp': 1687730683.544857, 'memFree': 5698516, 'version': '4.28.3M', 'configMacAddress': '00:00:00:00:00:00', 'isIntlVersion': False, 'imageOptimization': 'Sand-4GB', 'internalBuildId': 'f6ff9a13-c989-4fe6-a396-a510e5d33302', 'hardwareRevision': '11.00', 'hwMacAddress': '', 'architecture': 'i686'}]}
#show running-config section vlan
spanning-tree vlan-id 1-3967 priority 4096
no vlan 1
vlan 4
   name REDACTED
vlan 10
   name REDACTD 
vlan 48
   name REDACTED
vlan 49
   name REDACTED
vlan 50
   name REDACTED
vlan 520
   name REDACTED
vlan 521
   name REDACTED
vlan 801
   name REDACTED
vlan 2999
   name REDACTED
vlan 3966
   name REDACTED
vlan 3967
   name REDACTED
vlan 4094
   name REDACTED
   trunk group mlagpeer
interface Port-Channel57.5
   encapsulation dot1q vlan 5
interface Port-Channel59.5
   encapsulation dot1q vlan 5
interface Ethernet34
   switchport access vlan 521
interface Ethernet35
   switchport access vlan 521
interface Ethernet36
   switchport access vlan 521
interface Ethernet38
   switchport access vlan 521
interface Ethernet39
   switchport access vlan 521
interface Ethernet40
   switchport access vlan 521
interface Ethernet42
   switchport access vlan 521
interface Ethernet43
   switchport access vlan 521

pip freeze | grep 'pyeapi'
pyeapi==1.0.2
>>> print(node.api('vlans').getall())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<snip>/pyeapi/api/vlans.py", line 191, in getall
    response[vid] = self.get(vid)
  File "<snip>/pyeapi/api/vlans.py", line 104, in get
    config = self.get_block('vlan %s' % value)
  File "<snip>/pyeapi/api/abstract.py", line 99, in get_block
    return self.node.section(parent, config=config)
  File "<snip>/pyeapi/client.py", line 759, in section
    chunked = self._chunkify(config)
  File "<snip>/pyeapi/client.py", line 734, in _chunkify
    if is_subsection_present( lines, ind ):
  File "<snip>/pyeapi/client.py", line 721, in is_subsection_present
    return any( [line[ indent ] == ' ' for line in section] )
  File "<snip>/pyeapi/client.py", line 721, in <listcomp>
    return any( [line[ indent ] == ' ' for line in section] )
IndexError: string index out of range
@sc68cal
Copy link
Author

sc68cal commented Sep 13, 2023

I think this is choking on the banner section of the config. Adding this bit and invoking the debugger:

        def is_subsection_present( section, indent ):
            try:
                return any( [line[ indent ] == ' ' for line in section] )
            except:
                import pdb; pdb.set_trace()

And printing the locals() shows:

-> import pdb; pdb.set_trace()
(Pdb) locals()
{'section': ['                                    WARNING', '                                    '], 'pdb': <module 'pdb' from '/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/pdb.py'>, '__return__': None, 'indent': 36}

@sc68cal
Copy link
Author

sc68cal commented Sep 13, 2023

The configuration of the switch has the following. I have only included the first part and redacted the rest, but it's choking on the banner section.

banner login
***********************************************************************************
                                    WARNING

sc68cal added a commit to sc68cal/pyeapi that referenced this issue Sep 13, 2023
@dlyssenko
Copy link
Contributor

Hi, @sc68cal, thanks for catching this! pyeapi unit test also has to be updated accordingly to catch this regression. Would you be able also to add it to your PR?

@sc68cal
Copy link
Author

sc68cal commented Sep 14, 2023

sure! Do you have some tips for where things should go? Which fixture should I add the banner config to? Which unit test files should I update, etc etc?

Thanks

dlyssenko added a commit that referenced this issue Dec 6, 2023
fix for issue #286 - traceback when banner section contains white-spaces lines
@dlyssenko dlyssenko added the bug label Dec 6, 2023
@dlyssenko
Copy link
Contributor

Fixed with #291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants