-
Notifications
You must be signed in to change notification settings - Fork 1.3k
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Linux SSH / OpenGear read_until_prompt fails to detect enable mode when prompt is only single character #2866
Comments
In other words, if the prompt is The reason for this is that the terminating character frequently changes as you can see with the But obviously that is problematic in cases where the prompt is So one solution is to just raise an error or exception if self.base_prompt is ever a null-string as that should be invalid (and instruct the end-user that they need to set their device's prompt to a longer value). Another option would be to modify the default Do you have a way of testing this failing napalm-opengear (if we make this latter fix)? I am a bit concerned that allowing a prompt of |
Thanks for looking into this and for your notes @ktbyers! Might also be worth pointing out that this only happens on Netmiko 4.x, no issues with 3.x.
I'm not aware of a way to do this. For example, the hostname is configured, but the prompt is always
Yes, no problem with that... Would it be a good idea to have a global argument such as device = ConnectHandler(device_type="linux", host="some-opengear", username="root", password="pass", secret="pass", fast_cli=False, global_pattern="#") Or perhaps device = ConnectHandler(device_type="linux", host="some-opengear", username="root", password="pass", secret="pass", fast_cli=False, expected_prompt="#") And then after https://github.com/ktbyers/netmiko/blob/v4.1.1/netmiko/base_connection.py#L1289 we add if not self.base_prompt:
self.base_prompt = expected_prompt Just trying to think of other alternatives. Regardless, I'm curious what's the reasoning for having |
Yes, that one is hard as a lot of things changed from Netmiko 3.x to Netmiko 4.x. The main thing I can think of is that Netmiko 3.x had a pretty fundamental bug with respect to reading beyond pattern (i.e. it would/could read beyond the pattern). This was fixed in Netmiko 4.x. In general for terminal servers I recommend the use of the It is likely (or at least possible) that we should create a Netmiko specific device_type for I previously started moving (in a small way) towards a class attribute to indicate a terminating pattern, but it is definitely not ubiquitous and would (likely) be a very large overhaul to apply this generally. See an example here: https://github.com/ktbyers/netmiko/blob/develop/netmiko/linux/linux_ssh.py#L18 Let me research a bit about what is a practical solution to fix this in the near term. |
For self.base_prompt, I want something that is enduring (not likely to change). For example, in the below:
I want to be able to go through the state changes and still have the netmiko read succeed. So I want the part of the prompt that is common to all of these cases i.e. Obviously, that doesn't always work, but that is why the last character is dropped (to try to make Netmiko output reading more reliable). Linux behavior can already be problematic here (relative to platforms that are very Cisco IOS like). For example:
i.e. the prompt here is changing on more things than just the last character. |
Until there will be a more permanent solution in Netmiko, in order to have this driver usable with version 4.x, we need to "help" Netmiko when it fails to detect the prompt. Strictly speaking, as discussed under ktbyers/netmiko#2866 Netmiko works as designed, the ``base_prompt`` attribute is what we'd expect to be, but when OpenGear doesn't set anything on the prompt other than ``$`` or ``#`` depending on the user elevation, then Netmiko fails to properly read (more specifically, won't know when to stop). I also took this chance to change the behaviour in ``open()`` to only invoke ``enable()`` when the user is not root -- this saves one unnecessary operation when we use the root user.
Should be fixed here: |
Steps to reproduce:
The previous command does send the
sudo -s
command as it should, the device returns a line containing the#
as expected, but it fails oncheck_enable_mode
.After digging deeper, it seems like the issue is caused by the
read_until_prompt
method that is misbehaving. To reproduce, use thedevice
defined previously:Can notice that it sends the return, it reads the prompt correctly, but the regular expression split renders
output + match_str
to be an empty string. As a result,check_enable_mode
will never find the#
prompt in the empty string, and thereforecheck_enable_mode
will always returnFalse
in https://github.com/ktbyers/netmiko/blob/v4.1.1/netmiko/base_connection.py#L1861.The above is a simplified version of https://github.com/ktbyers/netmiko/blob/v4.1.1/netmiko/base_connection.py#L614-L640 to reproduce it step-by-step. The pattern
.*
comes from https://github.com/ktbyers/netmiko/blob/v4.1.1/netmiko/base_connection.py#L731-L733 asself.base_prompt
is empty string. So everything seems to be caused by the incorrectly detected prompt.TL;DR:
self.base_prompt
should be#
but it's''
.If I change the line https://github.com/ktbyers/netmiko/blob/v4.1.1/netmiko/base_connection.py#L1289 to
Everything seems to work fine, but might break other things? If so, perhaps something like the following would be more appropriate?
In fact, I can't think of a case where we need to strip the last character of a prompt, but perhaps there's more background to this than I'm aware of.
The text was updated successfully, but these errors were encountered: