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

Unable to load banner MOTD on Arista #732

Closed
mirceaulinic opened this issue May 21, 2018 · 4 comments
Closed

Unable to load banner MOTD on Arista #732

mirceaulinic opened this issue May 21, 2018 · 4 comments

Comments

@mirceaulinic
Copy link
Member

Firstly, I am not entirely sure what's the right format expected. I tried loading:

banner motd
!!aaaaa
EOF

With this, it fails:

>>> config = '''banner motd
... !!aaaa
... EOF
... '''
>>> e.load_merge_candidate(config=config)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/napalm/eos/eos.py", line 245, in load_merge_candidate
    self._load_config(filename, config, False)
  File "/usr/local/lib/python2.7/dist-packages/napalm/eos/eos.py", line 225, in _load_config
    commands = self._multiline_convert(commands, start=start, depth=depth)
  File "/usr/local/lib/python2.7/dist-packages/napalm/eos/eos.py", line 157, in _multiline_convert
    ret[s] = {'cmd': ret[s], 'input': "\n".join(ret[s+1:e])}
TypeError: sequence item 0: expected string or Unicode, dict found

Testing against a vEOS running:

Software image version: 4.18.1F
Architecture:           i386
Internal build version: 4.18.1F-4591672.4181F
Internal build ID:      6fcb426e-70a9-48b8-8958-54bb72ee28ed

Changing the line 157 to:

diff --git a/napalm/eos/eos.py b/napalm/eos/eos.py
index 4216ae5..bcb07e1 100644
--- a/napalm/eos/eos.py
+++ b/napalm/eos/eos.py
@@ -154,7 +154,7 @@ class EOSDriver(NetworkDriver):
                 depth = depth - 1
         except ValueError:  # Couldn't find end, abort
             return ret
-        ret[s] = {'cmd': ret[s], 'input': "\n".join(ret[s+1:e])}
+        ret[s] = {'cmd': ret[s], 'input': "\n".join([ele['input'] for ele in ret[s+1:e]])}
         del ret[s + 1:e + 1]

         return ret

As it looks like ret is a list looking like: [u'configure session napalm_61252', 'banner motd', {u'input': u'aaaa', u'cmd': u'comment'}, 'EOF'], and the object referenced by ret[s+1:e] is a list of dictionaries (not a list of strings).

@bewing I recall you've been working on this, would you recall any details and wondering if on other EOS versions pyeapi returns a list of strings as the code would suggest? I am running pyeapi 0.8.1.

@mirceaulinic mirceaulinic added this to the BLOCKED milestone May 21, 2018
@mirceaulinic mirceaulinic self-assigned this May 21, 2018
@mirceaulinic
Copy link
Member Author

It appears that there's the same behaviour on a real device running 4.17.4M, which makes me wonder whether there's a pyeapi versioning issue whatsoever.

mirceaulinic added a commit that referenced this issue May 21, 2018
…ced this

issue before which makes me questions what changed when (and why)? Without this
patch, loading a multiline banner motd fails (at least with the configuration I
tried to load):

```python
>>> config = '''banner motd
... !!aaaa
... EOF
... '''
>>> e.load_merge_candidate(config=config)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/napalm/eos/eos.py", line 245, in load_merge_candidate
    self._load_config(filename, config, False)
  File "/usr/local/lib/python2.7/dist-packages/napalm/eos/eos.py", line 225, in _load_config
    commands = self._multiline_convert(commands, start=start, depth=depth)
  File "/usr/local/lib/python2.7/dist-packages/napalm/eos/eos.py", line 157, in _multiline_convert
    ret[s] = {'cmd': ret[s], 'input': "\n".join(ret[s+1:e])}
TypeError: sequence item 0: expected string or Unicode, dict found
```
@bewing
Copy link
Member

bewing commented May 22, 2018

Per slack discussion, I believe this is occurring because napalm.eos.EOSDriver::_mode_comment_covert() is being called prior to napalm.eos.EOSDriver::_multiline_convert() inside napalm.eos.EOSDriver::_load_config()

The former reformats block-mode comments (which appear in configs as multi-line comments, all starting with !!), while the latter reformats multi-line commands (banners, https certificates, etc) which do not have prelimiters.

If we re-order these two operations (so the banner is converted, and then we check for mode-level comments), it should work as intended, I hope.

@mirceaulinic
Copy link
Member Author

Confirmed that the issue was caused only by the !! at the beginning of the lines. @bewing suggestion to reorder the operations might help.
Either way, I've added the documentation label, as the documentation can be enhanced a little.

bewing added a commit that referenced this issue May 23, 2018
@bewing
Copy link
Member

bewing commented May 23, 2018

@mirceaulinic can you checkout PR #738 and see if that resolves your issue?

@bewing bewing closed this as completed in e3787c4 Aug 3, 2018
cspeidel pushed a commit to cspeidel/napalm that referenced this issue Aug 9, 2018
The new heredoc handling code was causing issues with multiline banners that contained bangs (!), as we originally checked first for bang comments before checking for heredoc sections.

* Fixes napalm-automation#732
ExaneServerTeam pushed a commit to ExaneServerTeam/napalm that referenced this issue Mar 6, 2020
The new heredoc handling code was causing issues with multiline banners that contained bangs (!), as we originally checked first for bang comments before checking for heredoc sections.

* Fixes napalm-automation#732
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants