ktbyers / netmiko

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

Timed-out reading channel because of \r inserted in output #1798

Closed lazhao123 closed 4 years ago

lazhao123 commented 4 years ago

I need to configure brocade switch. The command is:

R1-G620-A:admin> ipaddrset -ipv4 -add -ethip 192.168.0.57 -ethmask 255.255.255.0 -gwyip 192.168.0.1 -dhcp OFF R1-G620-A:admin>

Here is the code, it keeps getting timeout exception when sending command:

net_connect = ConnectHandler(device_type='brocade_nos', ip=xxxx, username='admin', password=xxxx) command = 'ipaddrset -ipv4 -add -ethip 192.168.0.57 -ethmask 255.255.255.0 -gwyip 192.168.0.1 -dhcp OFF' output = net_connect.send_command(command) net_connect.disconnect()

In debug net_connect.send_command(command), In[9]: output = net_connect.send_command(command) read_channel: R1-G620-A:admin> Clear buffer detects data in the channel read_channel: write_channel: b'\n' read_channel: R1-G620-A:admin> read_channel: [find_prompt()]: prompt is R1-G620-A:admin> read_channel: write_channel: b'ipaddrset -ipv4 -add -ethip 192.168.0.57 -ethmask 255.255.255.0 -gwyip 192.168.0.1 -dhcp OFF\n' Pattern is: ipaddrset\ -ipv4\ -add\ -ethip\ 192.168.0.57\ -ethmask\ 255.255.255.0\ -gwyip\ 192.168.0.1\ -dhcp\ OFF -gwyip 192.168.0.1 -dhcp OFF R1-G620-A:admin>

In debug Netmiko _read_channel_expect(), I found: In[ ]: print(new_data) Out[1]: 'ipaddrset -ipv4 -add -ethip 192.168.0.57 -ethmask 255.255.255.0 \r -gwyip 192.168.0.1 -dhcp OFF\r\nR1-G620-A:admin> '

Notice there is '\r' in the middle of new_data, that caused Pattern is not matched with new_data, thus timeout. "Timed-out reading channel, data not available."

If I remove '\r', they will match and return successfully. I don't know why '\r' is inserted there. Configure on device looks fine.

Can _read_channel_expect() remove '\r' before matching?

ktbyers commented 4 years ago

Which device_type are you using?

lazhao123 commented 4 years ago

device is brocade G620 FC switch, device_type used in Connect_handler is brocade_nos.

In netmiko/ssh_dispatcher.py. brocade_nos is mapped to ExtremeNosSSH.

CLASS_MAPPER_BASE = { "brocade_fastiron": RuckusFastironSSH, "brocade_netiron": ExtremeNetironSSH, "brocade_nos": ExtremeNosSSH,

ktbyers commented 4 years ago

Does that brocade_nos have a way to set the terminal width?

On Cisco IOS this would be terminal width 511

lazhao123 commented 4 years ago

This brocade switch doesn't have command to change terminal width.

lazhao123 commented 4 years ago

I split the long command into 2 short commands, that solved the issue. Thank you for the hint.