nornir_napalm with nxos_ssh platform requires invoke?
supertylerc opened this issue · 7 comments
Ran into a weird one today. With the following config and inventory:
---
# config.yaml
inventory:
plugin: SimpleInventory
runner:
plugin: threaded
options:
num_workers: 4
---
# hosts.yaml
example.dal:
hostname: example.dal.example.com
port: 22
platform: nxos_ssh
And the following Python:
import logging
import os
from nornir_napalm.plugins.tasks import napalm_get
from nornir import InitNornir
nr = InitNornir(config_file="config.yaml", inventory={
"options": {
"host_file": "hosts.yaml",
},
})
nr.inventory.defaults.username = os.getenv("NORNIR_USERNAME")
nr.inventory.defaults.password = os.getenv("NORNIR_PASSWORD")
r = nr.run(task=napalm_get, getters=["config"], severity_level=logging.DEBUG)
I get a ModuleNotFound
that invoke
couldn't be found. Confused why invoke
would be necessary, I tried with straight napalm
, using the following code:
from napalm import get_network_driver
driver = get_network_driver('nxos_ssh')
device = driver('example.dal.example.com', os.getenv("NAPALM_USERNAME"), os.getenv("NAPALM_PASSWORD"))
device.open()
device.get_config()
The above code using napalm
directly works flawlessly. Using the nxos
platform
in nornir_napalm
works without issue. But, for some reason, using nxos_ssh
platform
in nornir_napalm
requires invoke
(at least in my testing).
After installing invoke
package, nornir_napalm
works without any problem. I see it in the Poetry.lock
, but I can't find any other references to it in this repo.
Versions of packages are below:
$ pip freeze | grep -i "nornir\|napalm"
napalm==4.0.0
nornir==3.3.0
nornir-napalm==0.3.0
@supertylerc Do you have the full stack trace of the invoke
ModuleNotFound error?
@ktbyers I don't. Passing severity_level=logging.DEBUG
only had the error. Any suggestion for how to bubble up/retrieve the stacktrace?
Okay, I think it is probably due to Paramiko. Paramiko has invoke
in extra_requires.
It looks like it gets used in some rare case for SSH config files.
Do you have an SSH-config file at ~/.ssh/config (Nornir will automatically pass that to Netmiko/Paramiko).
So I am wondering if you are just tripping this edge case in Paramiko via your SSH-config file (even though you are not using it).
Here are some details on invoke in Paramiko:
@ktbyers ahhhhh, nice find! I do, in fact, have an SSH config file that uses Match
in this particular environment. Certainly seems like an edge case. Appreciate your help!
Should we open an issue with them? They probably shouldn’t have this as extra_requires if it is actually required. Specially if it breaks downstream packages that might not be aware of obscure details like this.
It is a pretty rare situation as I think that is a rarely used SSH-config feature. It is probably easier for us to just add it to our dependencies (if we don't want to stumble on this again). It doesn't install anything else besides the library itself (I just tested it).
I'd rather not add a library we don't use ourselves. IMO this should be considered a bug in paramiko.
I am closing this issue as it is not really a problem in nornir but feel free to keep commenting or even reopening if needed.