OSError: Search pattern never detected in send_command
carl-baillargeon opened this issue · 5 comments
Hi,
I am trying to replace an ACL configuration on Cisco IOS with Nornir and NAPALM but I'm getting this error :
Error:
Traceback (most recent call last):
File "/home/carl/.local/lib/python3.8/site-packages/nornir/core/task.py", line 99, in start
r = self.task(self, **self.params)
File "/home/carl/.local/lib/python3.8/site-packages/nornir_napalm/plugins/tasks/napalm_configure.py", line 39, in napalm_configure
device.commit_config()
File "/home/carl/.local/lib/python3.8/site-packages/napalm/ios/ios.py", line 531, in commit_config
output = self._commit_handler(cmd)
File "/home/carl/.local/lib/python3.8/site-packages/napalm/ios/ios.py", line 470, in wrapper
return f(self, *args, **kwargs)
File "/home/carl/.local/lib/python3.8/site-packages/napalm/ios/ios.py", line 487, in _commit_handler
output = self.device.send_command_expect(cmd, expect_string=patterns)
File "/home/carl/.local/lib/python3.8/site-packages/netmiko/base_connection.py", line 1582, in send_command_expect
return self.send_command(*args, **kwargs)
File "/home/carl/.local/lib/python3.8/site-packages/netmiko/utilities.py", line 500, in wrapper_decorator
return func(self, *args, *kwargs)
File "/home/carl/.local/lib/python3.8/site-packages/netmiko/base_connection.py", line 1535, in send_command
raise IOError(
OSError: Search pattern never detected in send_command: (?:[>##]\s$|.*all username.*confirm)
Script:
import logging
import re
from nornir import InitNornir
from nornir_napalm.plugins.tasks import napalm_get
from nornir_napalm.plugins.tasks import napalm_configure
from nornir_jinja2.plugins.tasks import template_file
from nornir_utils.plugins.tasks.data import load_yaml
from nornir_utils.plugins.functions import print_result
nr = InitNornir(config_file="config.yaml")
etx = chr(3)
def replace_acl(task):
data = task.run(
task=load_yaml,
file=f"./host_vars/{task.host}.yaml",
severity_level=logging.DEBUG,
)
task.host["facts"] = data.result
config = task.run(task=napalm_get, getters=["config"], severity_level=logging.DEBUG)
showrun = config.result["config"]["running"]
pattern = re.compile("^ip access-list([^!]+)", flags=re.I | re.M)
routing_template = task.run(
task=template_file,
name="Building ACL Configuration",
template="acl.j2",
path="./templates",
)
template_to_load = routing_template.result
newconfig = re.sub(pattern, template_to_load, showrun)
final_config = newconfig.replace("^C", etx)
return final_config
def replace_feature(task):
config = replace_acl(task)
task.run(task=napalm_configure, configuration=config, replace=True)
results = nr.run(task=replace_feature)
print_result(results)
acl.j2 :
ip access-list standard SSH_IN
permit 172.21.{{ host.facts.subnet }}.0 0.0.0.255
permit 172.24.11.0 0.0.0.255
permit 172.24.40.0 0.0.3.255
deny any
R1.yaml :
subnet: 101
Info
Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.8(3)M
Any ideas ?
Thanks
Have you looked that your generated configuration is 100% correct?
Have you tried to just do a config replace using a static configuration and does that work?
You might also look at the Netmiko session_log or Netmiko logging and see if that provides information about what is going on.
Regards,
Kirk
Hi Kirk,
Yes config replace with the candidate config works just fine. I tried my script on a real Cisco device and it worked. The issue is with IOSv.
How can do you check the Netmiko session_log or logging?
Thanks
Does your IOSv device have a file-system?
In other words, what does dir
on the device show?
Just add a session_log: "some_file.txt"
to NAPALM's optional_args dictionary and this should record what happens during the Netmiko SSH session.
Any update on the session_log contents?
I didn't have a chance to try it out again. I've been busy with work.
Thanks