ktbyers / netmiko

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

EOFerror on HP Procurve intermittently #3490

Closed giacomotontini closed 2 months ago

giacomotontini commented 2 months ago

Description of Issue/Question

I wrote a python script to parse via TextFsm the output of cli command on a HP Procurve 2810 switch. The odd thing is that it runs fine the first time and then the second one throws an EOFerror, the third one work, the fourth one not works and so on.

Inspecting the logs, netmiko is able to connect via ssh to the switch, skip the initial key pressure prompt, write down the credential and log into the switch (both in working and not working scenario) "Thread-1 paramiko.transport INFO: Authentication (password) successful!"

I've also tried to manually connect and execute the same cli command on the switch to verify the behavior of the device but cli output is always the same. This is not caused by a parsing error. The EOF happens way before parsing stage. In fact, the error happens even without sending any command ("show arp" in the example below).

Playing with timeout values in device_config didn't affect this behavior.

Setup

other than netmiko, ensure ntc_templates is installed

Netmiko version

4.4.0

Netmiko device_type

hp_procurve

Steps to Reproduce the Issue

Execute the script multiple times. The first one works, the second not, the third one works, the fourth not and so on.

Error Traceback

see attachments (working.txt and eof-error.txt) eof-error.txt working.txt

Python code

from ntc_templates.parse import parse_output
from netmiko.hp.hp_procurve import HPProcurveSSH
from pprint import pprint
import logging

logging.basicConfig(
    format='%(threadName)s %(name)s %(levelname)s: %(message)s',
    level=logging.DEBUG,
)

device_config = {
    'device_type': 'hp_procurve',
    'host': '10.255.12.7',
    'username': 'admin', 
    'password': [retracted],
    "verbose": True,
    #"global_delay_factor": 5,
    #"conn_timeout": 20,
    #"auth_timeout": 5,
    #"session_timeout": 5,
    #"banner_timeout": 5,
    #"read_timeout_override": 5
}

def get_arp_table(connection):
    command = 'show arp'
    output = connection.send_command(command)
    return parse_output(platform="hp_procurve", command=command, data=output)

def main(*args, **kwargs):
    # Connessione allo switch HP ProCurve
    try: 
        connection = HPProcurveSSH(**device_config)
        with connection:
            #connection.session_preparation()
            arp_table = get_arp_table(connection)
            pprint(arp_table)

    except EOFError as e:
        logging.error(f"Damn EOF")

if __name__ == "__main__":
    main()
giacomotontini commented 2 months ago

Using connection.cleanup() before exiting solve the issue.