ktbyers / netmiko

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

Junos Terminal Output Discrepancy Between Device and Netmiko #3466

Open jvdspeare opened 1 month ago

jvdspeare commented 1 month ago

Description of Issue/Question

netmiko.exceptions.ReadTimeout: Pattern not detected, while configuring a Juniper EX2300. From the logs, it would appear netmiko is having an issue reading the terminal, or there's an issue with the logging. Please observe the discrepancy between: Jul 23 16:55:40 lab_jun_ex2300_0 mgd[7099]: UI_CMDLINE_READ_LINE: User 'x', command 'set interfaces ge-0/0/2 unit 0 description provisioning-vlan ' & {master:0}[edit] x@lab_jun_ex2300_0# set interfaces ge-0/0/2 x@lab_jun_ex2300_0# set interfaces ge-0/0/2 unit 0 description provisioning-vlan

Device perspective: Jul 23 16:55:40 lab_jun_ex2300_0 mgd[7099]: UI_CMDLINE_READ_LINE: User 'x', command 'configure exclusive ' Jul 23 16:55:40 lab_jun_ex2300_0 mgd[7099]: UI_DBASE_LOGIN_EVENT: User 'x' entering configuration mode Jul 23 16:55:40 lab_jun_ex2300_0 mgd[7099]: UI_CMDLINE_READ_LINE: User 'x', command 'delete interfaces ge-0/0/2 disable ' Jul 23 16:55:40 lab_jun_ex2300_0 mgd[7099]: UI_CMDLINE_READ_LINE: User 'x', command 'set interfaces ge-0/0/2 unit 0 description provisioning-vlan '

Netmiko session log: {master:0} x@lab_jun_ex2300_0> {master:0} x@lab_jun_ex2300_0> {master:0} x@lab_jun_ex2300_0> configure exclusive warning: uncommitted changes will be discarded on exit Entering configuration mode {master:0}[edit] x@lab_jun_ex2300_0# {master:0}[edit] x@lab_jun_ex2300_0# {master:0}[edit] x@lab_jun_ex2300_0# delete interfaces ge-0/0/2 disable {master:0}[edit] x@lab_jun_ex2300_0# set interfaces ge-0/0/2 x@lab_jun_ex2300_0# set interfaces ge-0/0/2 unit 0 description provisioning-vlan

Exception: netmiko.exceptions.ReadTimeout: Pattern not detected: 'set\ interfaces\ ge\-0/0/2\ unit\ 0\ description\ provisioning\-vlan' in output. Things you might try to fix this:

  1. Adjust the regex pattern to better identify the terminating string. Note, in many situations the pattern is automatically based on the network device's prompt.
  2. Increase the read_timeout to a larger value. You can also look at the Netmiko session_log or debug log for more information.

Netmiko version

4.4.0

Netmiko device_type (if relevant to the issue)

juniper_junos

Relevant Python code

ssh_configuration = ['delete interfaces ge-0/0/2 disable', 'set interfaces ge-0/0/2 unit 0 description provisioning-vlan']

net_connect.send_config_set(ssh_configuration,
                                                                             exit_config_mode=False,
                                                                             read_timeout=120)})
jvdspeare commented 1 month ago

cmd_verify=False resolves however I feel it's worth raising as it may be a bug. I tried different delays (global and delay_factor) without success. I can only replicate when configuring certain interfaces, which makes the behaviour even stranger.

ktbyers commented 1 month ago

@jvdspeare It looks like the Juniper device does something odd here from a user-interface perspective with the "?" mark characters.

x@lab_jun_ex2300_0# set interfaces ge-0/0/2 ���unit 0 description provisioning-vlan

You can probably see if you can actually capture the characters that get echoed back (i.e. what Juniper outputs here). You might need to look at them using "repr".

You could also very that the Netmiko command (earlier in the session) that sets the terminal width is being properly accepted ("set cli screen-width 511").