-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
send_config_set does not wire in read_timeout for read_until_pattern #2774
Comments
So I have noticed that the configuration is getting sent despite the error, but due to the error it doesn't continue the for loop. |
@nlspears So your code should change to this (as far as command = [
"ip access-list extended vty",
"permit ip 192.168.208.0 0.0.7.255 any",
]
for line in ipfile:
device['ip']=line.strip()
net_connect = ConnectHandler(**device)
output = net_connect.send_config_set(command)
output += net_connect.save_config())
net_connect.discnnect() Let me know if that works or not. |
Sorry for late response. Will test today and reply. May I ask why the initial statement regarding send_config_set? I have used it in this script in the past to refer to the commented out portion using the configvty.txt file. |
Ok I tried your suggestions and received the same error. |
Can you post the code you are sending and the full exception stack? Also can you post your log file here i.e. the To answer your question here: Netmiko's send_config_set() is intended only for configuration commands and automatically handles entering/exiting configuration mode. Consequently, sending things like So at a high level, it was just lucky that what you sent in earlier versions of Netmiko worked. |
Hi Kirk,
|
Okay, can you simplify this to a single device that is failing and what the Also please included the full exception stack trace corresponding to the failing (updated) code. |
Hi! We encountered the same problem, please find below the details about it: Netmiko version: 4.1.2 Script Used:
OUTPUT:
After crypto pki authenticate command output is not shown in the output variable and there are missing commands after it. Here the configuration I am applying:
So the event manager part and the part after that got configured on the router, however are not visible in the output variable. Tested manually, that at the line crypto pki authenticate CANAME is waiting around 20 seconds, until than there es no prompt visible. I also tried if I do a read_channel after the script is finished: the rest of the missing configurations are shown. Am I missing a setting with which I could get the whole cli output? Thank you for looking into it. |
@sohalevi So when you do this manually:
it sits there for around 20 seconds and then the prompt appears? |
Hi, sorry for not answering your question. |
I'm hitting this issue as well it seems on When configuring the boot statement on an Arista switch, the prompt comes back after ~13 seconds. The Basic code: # Set the boot config.
task.run(
name="Set boot config",
task=netmiko_send_config,
config_commands="boot system flash:/" + task.host["image"],
read_timeout=60,
) Exception raised comes from the
|
Looking over the code, it looks like the |
Okay, it looks like there is a mismatch in the expected behavior of read_timeout and send_config_set (i.e. you are expecting it to do something it doesn't actually do). This definitely could be a design error on my part. From the code for send_config_set()
https://github.com/ktbyers/netmiko/blame/develop/netmiko/base_connection.py#L2151 It is intentionally not used for the read_until_pattern call. Can you try using the following arguments to cmd_verify=False
read_timeout=60 I am going to leave this issue open and change the title (as the behavior should probably be changed). |
Hi Kirk. I thought I had tested your suggestion earlier but noticed I was setting # Set the boot config.
task.run(
name="Set boot config",
task=netmiko_send_config,
config_commands="boot system flash:/" + task.host["image"],
read_timeout=60,
cmd_verify=False,
) |
I spoke too soon. I just realized I tested while having |
Did you try setting
|
No I hadn't tried that but just did with the same result. # Set the boot config.
task.run(
name="Set boot config",
task=netmiko_send_config,
config_commands="boot system flash:/" + task.host["image"],
read_timeout=300,
cmd_verify=False,
) eos:
platform: "eos"
port: 443
connection_options:
netmiko:
port: 22
extras:
data:
replace_config: false traceback
|
@jchristopher327 Okay, that is a different failure than you were getting earlier. This one is failing on You might need to look at the Netmiko eos:
platform: "eos"
port: 443
connection_options:
netmiko:
port: 22
extras:
# Note, this assumes you are only testing against a single device
# (as the group is sharing the same file).
session_log: "output.txt"
data:
replace_config: false |
Unfortunately not much to go on. The output of the session log just ends with the
|
Okay, let me look at it some more. |
@jchristopher327 Can you test this proposed fix? You will need to use these settings: # Set the boot config.
task.run(
name="Set boot config",
task=netmiko_send_config,
config_commands="boot system flash:/" + task.host["image"],
read_timeout=N, # Where N is some time in seconds with enough margin so that 'boot' command completes
cmd_verify=True, # This is the default
) |
Hey Kirk, I tried installing the fix but started running into dependency issues that I think boil down to Let me know if I should open a PR to on the |
Yeah that pinning should go away. Do you want to do a PR on that? We should just remove that dependency in nornir_netmiko as such (i.e. remove the textfsm dependency). Netmiko will install it. |
Related to this discussion - ktbyers/netmiko#2774 (comment)
Here's the PR in nornir-netmiko ktbyers/nornir_netmiko#55 |
@jchristopher327 Okay, that is merged so you would need the |
The proposed fix worked. Here's a rundown of the things I did on my end to test. Let me know if there's anything else you'd like me to test. used the develop branch of napalm since 4.0.0 has textfsm<=1.1.2 as a dependency
use the netmiko fix
use nornir_netmiko without the textfsm dependency (fyi, my PR was merged into master not develop)
code changes
script result
|
This was fixed with #3156 |
I am attempting to use a script I have always used in the past without issue. I has not been used in a couple of months but now with the updated netmiko it no longer works. Here is the script and the errors I am getting.
from netmiko import ConnectHandler
import getpass
import time, sys, paramiko
import logging
logging.basicConfig(filename='test.log', level=logging.DEBUG)
logger = logging.getLogger("netmiko")
user = input("Enter your SSH username: ")
pword = getpass.getpass()
device = {
'device_type': 'cisco_xe',
#'ip': '192.168.43.10',
'username': user,
'password': pword,
#'secret':'password'
}
ipfile=open("iplist.txt") #This file contains a list of switch ip addresses.
#configfile=open("configvty.txt") #opening the config file with the changes you want to push
#config=configfile.read() ##reads the config file
#configfile.close() #closes the config file
command = [
"ip access-list extended vty",
"permit ip 192.168.208.0 0.0.7.255 any",
"end",
"wr",
]
for line in ipfile:
device['ip']=line.strip()
print("Connecting to Device " + line)
net_connect = ConnectHandler(**device)
print ("Applying Configuration to Device " + line)
output = net_connect.send_config_set(command)
print('Configuration Complete')
Initially, I was using the file "configvty.txt" to read from for the configs. As I am troubleshooting. I have switched to using the command list.
The error I am getting is below:
Traceback (most recent call last):
File "/home/nspears/environments/vtypush.py", line 36, in
output = net_connect.send_config_set(command)
File "/home/nspears/environments/vtyacl_update/lib/python3.10/site-packages/netmiko/base_connection.py", line 2171, in send_config_set
output += self.read_until_pattern(pattern=pattern, re_flags=re.M)
File "/home/nspears/environments/vtyacl_update/lib/python3.10/site-packages/netmiko/base_connection.py", line 651, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '(?:L70\-MDF\-sw01.$|#.$)' in output.
Things you might try to fix this:
many situations the pattern is automatically based on the network device's prompt.
You can also look at the Netmiko session_log or debug log for more information.
The text was updated successfully, but these errors were encountered: