nornir-automation / nornir

Pluggable multi-threaded framework with inventory management to help operate collections of devices
https://nornir.readthedocs.io/
Apache License 2.0
1.38k stars 234 forks source link

No output from Cisco XR on "admin show inventory" #840

Closed andyb2000 closed 1 year ago

andyb2000 commented 1 year ago

Hi, Whilst this is under a netbox dev area, I don't believe it's netbox specific, using a basic debug script, calling "admin show inventory" on a Cisco ASR-9010 I get no output at all from NORNIR, nor does anything appear in logs/debugging that would point to blank output.

nornir debug log output: Running task 'multiple_tasks' with args {} on 1 hosts Host 'x.x.x.x': running task 'multiple_tasks' Host 'x.x.x.x': running task 'admin show inventory' Actual output: `{'defaults': {'connection_options': {}, 'data': {}, 'hostname': None, 'password': None, 'platform': None, 'port': None, 'username': None}, 'groups': {'all': {'connection_options': {}, 'data': {}, 'groups': [], 'hostname': None, 'name': 'all', 'password': None, 'platform': None, 'port': None, 'username': None}, 'cisco_ios': {'connection_options': {}, 'data': {}, 'groups': [], 'hostname': None, 'name': 'cisco_ios', 'password': None, 'platform': None, 'port': None, 'username': None}, 'cisco_xr': {'connection_options': {}, 'data': {}, 'groups': [], 'hostname': None, 'name': 'cisco_xr', 'password': None, 'platform': None, 'port': None, 'username': None}, 'site-x1': {'connection_options': {}, 'data': {}, 'groups': [], 'hostname': None, 'name': 'site-xxx', 'password': None, 'platform': None, 'port': None, 'username': None}}, 'hosts': {'x.x.x.x': {'connection_options': {'netmiko': {'extras': {}, 'hostname': None, 'password': None, 'platform': None, 'port': None, 'username': None}}, 'data': {'site': 'x1', 'site_id': 107}, 'groups': ['cisco_xr', 'site-x1'], 'hostname': 'x.x.x.x', 'name': 'x.x.x.x', 'password': 'mypass', 'platform': 'cisco_xr', 'port': 22, 'username': 'myuser'}}} multiple_tasks**

^^^^ END multiple_tasks ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `

CODE:

import logging
from pprint import pprint
from nornir import InitNornir
from nornir.core.filter import F
from nornir.core.plugins.inventory import InventoryPluginRegister
from nornir_netmiko.tasks import netmiko_send_command
from nornir_utils.plugins.functions import print_result

from netdoc.nornir_inventory import AssetInventory

ADDRESS = "x.x.x.x"
ENABLE = True
NORNIR_TIMEOUT = 320
COMMANDS = [
    "admin show inventory",
]

logging.basicConfig(level=logging.DEBUG, format='%(message)s')
logger = logging.getLogger("nornir")
logger.setLevel(logging.DEBUG)
file_h = logging.FileHandler("nornir.log")
file_h.setLevel(logging.DEBUG)
logger.addHandler(file_h)

InventoryPluginRegister.register("asset-inventory", AssetInventory)

nrni = InitNornir(
    core={
        "raise_on_error": True
    },
    runner={
        "plugin": "threaded",
        "options": {
            "num_workers": 1,
        },
    },
    inventory={"plugin": "asset-inventory"},
    logging={"enabled": True, "level": "DEBUG", "log_file": "/tmp/nornir.log"},
)
nrni = nrni.filter(F(hostname=ADDRESS))
pprint(nrni.inventory.dict())

def multiple_tasks(task):
    """Define commands (in order) for the playbook."""
    for command in COMMANDS:
        task.run(
            task=netmiko_send_command,
            name=command,
            command_string=command,
            use_textfsm=True,
            enable=ENABLE,
            use_timing=True,
            read_timeout=NORNIR_TIMEOUT,
        )

aggregated_results = nrni.run(task=multiple_tasks)

print_result(aggregated_results)
ktbyers commented 1 year ago

@andyb2000 You shouldn't use use_timing=True for long-running commands it is not reliably. So you should set that to false and then set read_timeout=n (where n is how long the command takes to run plus some margin that provides sufficient headroom for variation in the response from the device).

andyb2000 commented 1 year ago

Ahh, excellent, yes I'm now getting back data from my test script. Thanks @ktbyers I'll close this.