ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.62k stars 1.31k forks source link

auth_timeout on SERIAL ConnectHandler - login authentication appears to happen but NetMikoAuthenticationException is thrown at random #3410

Open jmarcedwards opened 7 months ago

jmarcedwards commented 7 months ago

Description of Issue/Question

I've tried this with both ConnLogOnly and ConnectHandler with the same result.

It appears from the DEBUG output that NetMiko HAS LOGGED INTO the network device.
I can see the prompt in the DEBUG output log.

However, a NetMikeAuthenticationException is being thrown about 60% of the time, i.e., there are times when the login occurs properly. The reason that I know that the login is happening is that when I would try to run the code a 2nd time, a VALID AuthenticationError occurs, because the DEVICE IS IN A LOGIN STATE.

When I check manually the login, I am immediately jumped into the PROMPT, NOT the login prompt for the username.

So, it seems that NetMiko is MISSING the successful login attempt looking for the first prompt.

I have tried the auth_timeout, conn_timeout, blocking_timeout, timeout at "30 seconds" with no luck. I can manually test the login over the SERIAL connection, and the network device is responding with a prompt after entering the password in about 5 seconds or so.

And again, it seems to be hit or miss. About 40% of the time, the login is successful.

I'm trying to figure out WHICH timeout needs to be adjusted. Can someone please help?

Thanks, Marc

Setup

Netmiko version

netmiko==4.3.0

Netmiko device_type (if relevant to the issue)

(Paste device_type between quotes below)

cisco_ios_serial

Steps to Reproduce the Issue

Error Traceback

(Paste the complete traceback of the exception between quotes below)

'Login failed: serial'

Relevant Python code

(Please try to essentialize your Python code to the minimum code needed to reproduce the issue) (Paste the code between the quotes below)

    with ConnectHandler(**cgr_serial_params_jme1) as cgr_serial_conn:
        cgr_serial_conn.enable()
        first_prompt = cgr_serial_conn.find_prompt()
        logging.info(f"SERIAL prompt ==> \"{first_prompt}\"")
        cgr_ser_num_re = re.search('CGR(.+?)#', first_prompt)
        if cgr_ser_num_re:
            cgr_under_upgrade = list(filter(lambda elem: elem.cgr_serial_number == cgr_ser_num_re.group(1), all_cgrs))
        else:
            raise Exception("CGR Serial Number NOT found!")
jmarcedwards commented 7 months ago

I also tried this on a 2nd identical model Cisco CGR, and again, the 1st time logging in NO PROBLEM. The 2nd and 3rd times, it logged in, but missed the prompt and threw an AuthenticationException.

ktbyers commented 7 months ago

@jmarcedwards Can you post the full exception stack trace of a failure?

You might need to eliminate/replace the Context Manager in your code (if you are not seeing the full exception stack trace).