Fix Huawei special_login_handler (#2711) #2719
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a proposal to fix the
special_login_handler()
issue (#2711).TL;DR: I removed the
special_login_handler()
completely and moved the handling for the password change prompt intosession_preparation()
, because I did not see a better way of fixing the issues altogether (read the whole story below).After spending some time investigating the issue I found out that the pattern matching logic in
read_until_pattern
expects the pattern to split exactly in 3 parts (using re.split), see base_connection.py#L579 for reference. Seems this change was introduced during some fundamental changes to the channel reading logic in in 793100d.At first I tried to simply fix the
password_change_prompt
regex (see huawei.py#L104) by replacing the inner groups (parenthesis) with(?:)
like so:However, when looking more closely at the code, I stumbled upon the
if re.search(password_change_prompt, output):
condition, which seemed wrong (would always evaluate toTrue
). So I modified the if-condition to actually search for the password_change_prompt only, like so:At first it seemed to work, but it turns out that connecting to the device now only works if a password change prompt is present. When no password change prompt is found, the following exception is raised:
Huh? Inspecting the debug logs, it turns out that
self.write_channel("N\n")
(which was always called before changing the if-condition) was responsible for the following debug logs:This means, the
self.write_channel("N\n")
did not only produce an error, but also a new prompt!To me, it looks like it was only this new prompt (which was triggered by the "Unrecognized command" error) that actually made
_test_channel_read
insession_preparation
work at all.Therefore, I think it would only be possible to keep the handling logic for the password change prompt in
special_login_handler
if either_test_channel_read
insession_preparation
would be removed completely orself.write_channel(self.RETURN)
would be needed to to trigger a new prompt for_test_channel_read
to read it. Both of which are not really elegant IMHO. Maybe it would also be possible to read until the prompt by using a lookahead assertion, but I don't know if that's possible with the wayread_until_pattern
is currently implemented.Let me know what you think.
Kind regards
Flo