Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with using netmiko for SONIC Nokia switch #3517

Open
sindhujit1 opened this issue Oct 28, 2024 · 7 comments
Open

Issue with using netmiko for SONIC Nokia switch #3517

sindhujit1 opened this issue Oct 28, 2024 · 7 comments

Comments

@sindhujit1
Copy link

Description of Issue/Question

We are facing an issue connecting to SONIC vendor using netmiko. We have used netmiko in the past for nexus 9ks, cat 9ks, aristas, and it worked. Is SONIC not supported ?

Setup

Netmiko version

netadc3.8) [svc.netadc@hvidlnetwa03 netadc3]$ pip freeze | grep netmiko
netmiko==3.4.0

Netmiko device_type (if relevant to the issue)

We tried different device types. 

f5_linux
ovs_linux
nlinux

Nothing worked.

Error Traceback

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

['Authentication to device failed.\n\nCommon causes of this problem are:\n1. Invalid username and password\n2. Incorrect SSH-key file\n3. Connecting to the wrong device\n\nDevice settings: <device_type> x.x.x.x:22\n\n\nAuthentication timeout.']

Relevant Python code

ssh = netmiko.ConnectHandler(device_type="<device_type>",host=sonic_ip_input,username=username,password=password,
session_timeout=180,conn_timeout=60,timeout=300,auth_timeout=30)
ssh.disable_paging()
response_prompt = ssh.send_command_timing('sudo config snmp community add '+snmpv3_val+' RO')
logging.warning('response_prompt'+response_prompt)
@ktbyers
Copy link
Owner

ktbyers commented Oct 30, 2024

There is a dell_sonic device_type. Can you try that and see if it works?

If that fails, can you show what the the standard SSH login process looks like when you do it manually (i.e. copy-and-paste the SSH login interaction). You can change/mask any username and passwords.

@sindhujit1
Copy link
Author

sindhujit1 commented Nov 4, 2024

Tried that. It failed as well.

ssh = netmiko.ConnectHandler(device_type="dell_sonic",host=sonic_ip_input,username=username,password=password,
session_timeout=180,conn_timeout=60,timeout=300,auth_timeout=30)

This is how the login looks:

Linux <device_name> 5.10.0-23-2-arm64 #1 SMP Debian 5.10.179-3 (2023-07-27) aarch64
You are on
  ____   ___  _   _ _  ____
 / ___| / _ \| \ | (_)/ ___|
 \___ \| | | |  \| | | |
  ___) | |_| | |\  | | |___
 |____/ \___/|_| \_|_|\____|

-- Software for Open Networking in the Cloud --

Unauthorized access and/or use are prohibited.
All access and/or use are subject to monitoring.

Help:    https://sonic-net.github.io/SONiC/

Last login: Mon Nov  4 17:23:26 2024 from 10.71.19.69
admin@<device_name>:~$

@ktbyers
Copy link
Owner

ktbyers commented Nov 5, 2024

I would probably try to capture the log file to see if it provides you any additional information as to why authentication is failing:

https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#enable-netmiko-logging-of-all-reads-and-writes-of-the-communications-channel

@sindhujit1
Copy link
Author

sindhujit1 commented Nov 12, 2024

Here is the script:

import netmiko,sys,linecache
import logging
logging.basicConfig(filename='test.log', level=logging.DEBUG)
logger = logging.getLogger("netmiko")
import time

def test():
	try:
		now = time.strftime("%d/%m/%Y").replace("/", "_")
		ssh = netmiko.ConnectHandler(device_type="dell_sonic",host='x.x.x.x',username="admin",password="xxxxx",session_timeout=180,conn_timeout=60,timeout=300,auth_timeout=30)
		response_prompt = ssh.send_command('show version')
		print(response_prompt,"response_prompt")

	except Exception as e:
		exc_type, exc_obj, tb = sys.exc_info()
		f1 = tb.tb_frame
		lineno = tb.tb_lineno
		filename = f1.f_code.co_filename
		linecache.checkcache(filename)
		line = linecache.getline(filename, lineno, f1.f_globals)
		print('Unknown exception occurred on ' + ' ' + str(e) + ". Error On file " + filename + " Line Number " + str(lineno))
		print(str(e))

	ssh.disconnect()
	print('Connection closed.')

test()

Here's the output on the console for the script:

C:\Users\xxxx\OneDrive - xxx\Documents>python netmiko_sonic.py
^
% Error: Invalid input detected at "^" marker. response_prompt
Connection closed.

Attached is the netmiko log file:

test.log

@sindhujit1
Copy link
Author

Any update on this @ktbyers ?

@inaba-vdom-0
Copy link
Contributor

@sindhujit1
I have tried with sonic-vs image and confirmed that it is accessible with [“device_type”: “linux”].
I think you need to run show version after executing the .enable() method or sudo show version command.
For “dell_sonic”, sonic-cli is executed after the ssh connection, so unsupported software cannot execute the command.

  • test-code
from netmiko import ConnectHandler

remote_device = {
    "ip": "192.168.1.20",
    "username": "admin",
    "password": "test",
    "secret": "test",
    "device_type": "linux",
    "global_delay_factor": 3,
    "session_log": "test-session.log",
    "fast_cli": False,
}

conn = ConnectHandler(**remote_device)
conn.enable()
version = conn.send_command("show version")
print(version)

conn.disconnect()
  • output

Linux sonic 6.1.0-22-2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.94-1 (2024-06-21) x86_64
You are on
  ____   ___  _   _ _  ____
 / ___| / _ \| \ | (_)/ ___|
 \___ \| | | |  \| | | |
  ___) | |_| | |\  | | |___
 |____/ \___/|_| \_|_|\____|

-- Software for Open Networking in the Cloud --

Unauthorized access and/or use are prohibited.
All access and/or use are subject to monitoring.

Help:    https://sonic-net.github.io/SONiC/

Last login: Wed Jan 15 13:35:12 2025 from 192.168.1.xxx
admin@sonic:~$ 
admin@sonic:~$ 
admin@sonic:~$ 
admin@sonic:~$ sudo -s
root@sonic:/home/admin# 
root@sonic:/home/admin# 
root@sonic:/home/admin# 
root@sonic:/home/admin# show version

SONiC Software Version: SONiC.master.741892-94b860b67
SONiC OS Version: 12
Distribution: Debian 12.6
Kernel: 6.1.0-22-2-amd64
Build commit: 94b860b67
Build date: Thu Jan  9 14:00:44 UTC 2025
Built by: azureuser@9c7aac8fc00000B

Platform: x86_64-kvm_x86_64-r0
HwSKU: Force10-S6000
ASIC: vs
ASIC Count: 1
Serial Number: N/A
Model Number: N/A
Hardware Revision: N/A
Uptime: 13:48:50 up 25 min,  1 user,  load average: 0.38, 0.65, 0.73
Date: Wed 15 Jan 2025 13:48:50

Docker images:
REPOSITORY                    TAG                       IMAGE ID       SIZE
docker-macsec                 la********                    bd3be18cb8a9   345MB
docker-orchagent              la********                    96a6fd0e409a   356MB
docker-orchagent              master.741892-94b860b67   96a6fd0e409a   356MB
docker-teamd                  la********                    026447d723df   342MB
docker-teamd                  master.741892-94b860b67   026447d723df   342MB
docker-fpm-frr                la********                    106a9bd9d029   377MB
docker-fpm-frr                master.741892-94b860b67   106a9bd9d029   377MB
docker-nat                    la********                    08a0bd019c05   345MB
docker-nat                    master.741892-94b860b67   08a0bd019c05   345MB
docker-sflow                  la********                    387a29a3be61   344MB
docker-sflow                  master.741892-94b860b67   387a29a3be61   344MB
docker-gbsyncd-vs             la********                    d8aeeddf4ca7   2.16GB
docker-gbsyncd-vs             master.741892-94b860b67   d8aeeddf4ca7   2.16GB
docker-syncd-vs               la********                    b8a52414903f   2.16GB
docker-syncd-vs               master.741892-94b860b67   b8a52414903f   2.16GB
docker-dhcp-relay             la********                    a82f1a7d4aa1   323MB
docker-sonic-bmp              la********                    2c60ea213af1   315MB
docker-sonic-bmp              master.741892-94b860b67   2c60ea213af1   315MB
docker-snmp                   la********                    8c3f4e93f92d   353MB
docker-snmp                   master.741892-94b860b67   8c3f4e93f92d   353MB
docker-platform-monitor       la********                    fb051520357b   433MB
docker-platform-monitor       master.741892-94b860b67   fb051520357b   433MB
docker-router-advertiser      la********                    8c80615c0e3b   313MB
docker-router-advertiser      master.741892-94b860b67   8c80615c0e3b   313MB
docker-mux                    la********                    3a36c0dceeca   365MB
docker-mux                    master.741892-94b860b67   3a36c0dceeca   365MB
docker-lldp                   la********                    678bff6ec231   359MB
docker-lldp                   master.741892-94b860b67   678bff6ec231   359MB
docker-sonic-gnmi             la********                    1ebdef1171e3   402MB
docker-sonic-gnmi             master.741892-94b860b67   1ebdef1171e3   402MB
docker-eventd                 la********                    12ebf8c6eede   313MB
docker-eventd                 master.741892-94b860b67   12ebf8c6eede   313MB
docker-dash-engine            la********                    cfe16c23f431   697MB
docker-dash-engine            master.741892-94b860b67   cfe16c23f431   697MB
docker-database               la********                    98e92126d722   322MB
docker-database               master.741892-94b860b67   98e92126d722   322MB
docker-sonic-mgmt-framework   la********                    7ed04c361f9f   399MB
docker-sonic-mgmt-framework   master.741892-94b860b67   7ed04c361f9f   399MB

root@sonic:/home/admin# 
root@sonic:/home/admin# 
root@sonic:/home/admin# exit
exit
admin@sonic:~$ 
admin@sonic:~$ 
admin@sonic:~$ exit

@ktbyers
Copy link
Owner

ktbyers commented Jan 21, 2025

@sindhujit1 Do you want to try the above pattern from @inaba-vdom-0 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants