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

Problem with console/tty login after rebooting RE tty.py #823

Open
jnpr-bowen opened this issue Apr 17, 2018 · 2 comments
Open

Problem with console/tty login after rebooting RE tty.py #823

jnpr-bowen opened this issue Apr 17, 2018 · 2 comments
Assignees

Comments

@jnpr-bowen
Copy link

jnpr-bowen commented Apr 17, 2018

I am having a problem using a console connection in Ansible after rebooting the RE. I believe I have found the solution, but need others to verify the problem and my 'fix'.
To recreate the issue from Ansible have a playbook that reboots the RE, delay for time to allow reboot to happen, then juniper_junos_facts via the console port. The facts task should fail.
I traced the problem down into the tty.py login state machine and I think there is an error in the RE.
After a reboot the console connection does not present a login after the initial '\n' is sent to the port, and so nothing is read by the login state machine, resulting in a 10 second read timeout. The state machine then tries sending a <close/> line to the console and that is the only thing read back from the console by the state machine. The <close/> appears to match the pattern and the state machine thinks it has a successful login and then attempts to start the netconf session, which fails.

During my investigation, I checked the RE at regex101.com and it did not think the cli RE was valid as it says '-' is not properly escaped. At regex101, if I take out one \ from the RE, the tag end in <close/> matches the RE. With my testing, I have changed the RE to:
'(?P[^/\\-"]>\s*$)'

Without any documentation of the pattern, it is hard to know what the writer was trying to accomplish. My thinking is that the cli prompt is viewed as the '>' char with or without spaces at the end of line. But if it is preceded by '\', '-', '"' it might be something else that is not the cli prompt. My change switches the negative match from '\', to '/'. If '\' should also be in the negative, the pattern would have to be something like:
'(?P[^\\\\/\\-"]>\s*$)'

The pattern is on line 55 of tty.py

_RE_PAT = [
    '(?P<loader>oader>\s*$)',
    _re_pat_login,
    '(?P<passwd>assword:\s*$)',
    '(?P<badpasswd>ogin incorrect)',
    '(?P<netconf_closed><!-- session end at .*-->\s*)',
    '(?P<shell>%|#\s*$)',
    '(?P<cli>[^\\-"]>\s*$)',
    '(?P<option>Enter your option:\s*$)',
    '(?P<hotkey>connection: <CTRL>Z)',
    '(?P<new_cli_re>[\\/\-"]>\s*$)'
]

Just noticed that markdown is messing with how backslash is being displayed. Don't copy/paste my pattern from the text, use the pattern I added to the _RE_PAT code snippet.

@jnpr-bowen
Copy link
Author

Some extra details from an Ansible playbook log where one connection works and another does not:
Working connection:
2018-04-16 09:49:42,845 jnpr.junos.tty TTY: logging in......
2018-04-16 09:49:52,847 jnpr.junos.tty_telnet Got:
2018-04-16 09:49:52,847 jnpr.junos.tty_telnet Write: <close-session/>
2018-04-16 09:49:52,908 jnpr.junos.tty_telnet Got: <close-session/>^M
Password:
2018-04-16 09:49:52,908 jnpr.junos.tty_telnet Write: changed_for_posting
2018-04-16 09:49:54,139 jnpr.junos.tty_telnet Got: ^M
Login incorrect^M
login:
2018-04-16 09:49:54,139 jnpr.junos.tty_telnet Write: bbowen
2018-04-16 09:49:54,194 jnpr.junos.tty_telnet Got: bbowen^M
Password:
2018-04-16 09:49:54,195 jnpr.junos.tty_telnet Write: changed_for_posting
2018-04-16 09:49:55,953 jnpr.junos.tty_telnet Got: ^M
Last login: Mon Apr 16 08:43:50 on ttyu0^M
...
;bbowen@lab-re1>
2018-04-16 09:49:55,953 jnpr.junos.tty TTY: OK.....starting NETCONF
2018-04-16 09:49:55,953 jnpr.junos.tty_telnet Write: junoscript netconf need-trailer
2018-04-16 09:49:57,570 jnpr.junos.tty_netconf Received:

Failing connection:
2018-04-16 10:02:05,173 jnpr.junos.tty TTY: logging in......
2018-04-16 10:02:15,175 jnpr.junos.tty_telnet Got:
2018-04-16 10:02:15,176 jnpr.junos.tty_telnet Write: <close-session/>
2018-04-16 10:02:15,220 jnpr.junos.tty_telnet Got: <close-session/>^M

2018-04-16 10:02:15,220 jnpr.junos.tty TTY: OK.....starting NETCONF
2018-04-16 10:02:15,221 jnpr.junos.tty_telnet Write: junoscript netconf need-trailer
2018-04-16 10:02:36,543 jnpr.junos.console ERROR: login:Netconify Error: netconf not responding

@apurvaraghu
Copy link
Collaborator

Hi @jnpr-bowen, Can you please provide a reproduction script. I tried testing this and I can retrieve the facts successfully.

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

No branches or pull requests

4 participants