py-junos-eznc
py-junos-eznc copied to clipboard
Problem with console/tty login after rebooting RE tty.py
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
During my investigation, I checked the
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
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.
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
Hi @jnpr-bowen, Can you please provide a reproduction script. I tried testing this and I can retrieve the facts successfully.