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.39k stars 235 forks source link

on_failed on grouping task #910

Closed antoinekh closed 4 months ago

antoinekh commented 4 months ago

Hello,

nornir = "^3.4.1" python = ">=3.10,<3.12"

I have a grouping task where I have several tasks. I want to return the failed task to know what my failed checks are but I also want to do all the checks even if one of them fails.

def multiple_tasks(task):
    task.run(task=check_ntp, on_failed=True)
    task.run(task=check_logs, on_failed=True)
    task.run(task=check_non_bfd_bgp_timers, on_failed=True)
    task.run(task=check_bgp_with_bfd, on_failed=True)
    task.run(task=check_bgp_with_ap_mode, on_failed=True)

nr = InitNornir(config_file="config.yaml")
output = nr.run(task=multiple_tasks, on_failed=True)

I have tried to add the on_failed to each task but the generate this problem

 r = self.task(self, **self.params)
TypeError: check_ntp() got an unexpected keyword argument 'on_failed' failed

And when the on_failed is on the multiple_tasks, it's not take into account.

Is there a way to do it?

antoinekh commented 4 months ago

https://github.com/nornir-automation/nornir/issues/699

This explains the reason for this behaviour, I will probably reorganise my code for this