napalm-automation-community / napalm-arubaos-switch

NAPALM driver for ArubaOS-Switch
MIT License
16 stars 9 forks source link

Nornir and Thread Safety Question #23

Open netdemux opened 1 year ago

netdemux commented 1 year ago

Expected Behavior

This is more of a question than an expectation. I'm attempting to use napalm-arubaos-switch with nornir (with multithreading). I'm seeing non-deterministic output and suspect that some part of the arubaoss napalm library is not thread-safe. I think the issue may arise from the way api connections are implemented. If this is the case, I expect it would be no simple task to rewrite; I'd just like to confirm whether I'm on the right track or if there's a gap in my understanding somewhere.

Actual Behavior

When called through Nornir, napalm-arubaos-switch exhibits seemingly non-deterministic behavior. Hosts will return the expected output some of the time, but then return empty dictionaries when the same script is run again immediately after. No errors are logged, no exceptions are raised, and the maximum number of https/rest sessions is not exceeded. The non-deterministic behavior affects all different devices in nornir's hosts.yml file; it is not isolated to one specific host. No host returns expected output 100% of the time.

Steps to Reproduce the Problem

  1. Run a basic Nornir task with napalm_get on two or more hosts with platform="arubaoss"
    
    nr = InitNornir(
        runner={
            "plugin": "threaded",
            "options": {
                "num_workers": 20,
            },
        },
        inventory={

...

... ) results = nr.run( task=napalm_get, getters=["lldp_neighbors"] ) print_result(results) nr.close_connections() ``` 2. Repeat step 1 to see variation in the output. 3. Edit the script to use a single thread with "num_workers": 1 4. Note that tasks now consistently return expected results for all hosts ## Specifications - Version: napalm-arubaos-switch 0.2.0 nornir 3.3.0 Python 3.10.6 - Platform: Windows 10 22H2 - Subsystem: WSL 0.2.1