Skip to content

Commit

Permalink
Add property for optional runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ogenstad committed Jun 8, 2024
1 parent a4aa92a commit 46ecb53
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 9 additions & 1 deletion nornir/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, List, Optional, Type

from nornir.core.configuration import Config
from nornir.core.exceptions import PluginNotRegistered
from nornir.core.inventory import Inventory
from nornir.core.plugins.runners import RunnerPlugin
from nornir.core.processor import Processor, Processors
Expand Down Expand Up @@ -142,7 +143,7 @@ def run(
else:
logger.warning("Task %r has not been run – 0 hosts selected", task.name)

result = self.runner.run(task, run_on)
result = self._runner.run(task, run_on)

raise_on_error = (
raise_on_error
Expand All @@ -168,6 +169,13 @@ def close_connections_task(task):

self.run(task=close_connections_task, on_good=on_good, on_failed=on_failed)

@property
def _runner(self) -> RunnerPlugin:
if self.runner:
return self.runner

raise PluginNotRegistered("Runner plugin not registered")

@classmethod
def get_validators(cls) -> Generator[Callable[["Nornir"], "Nornir"], None, None]:
yield cls.validate
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ warn_redundant_casts = True
[mypy-nornir.core]
disallow_untyped_defs = False
disallow_incomplete_defs = False
strict_optional = False

[mypy-tests.*]
ignore_errors = True

0 comments on commit 46ecb53

Please sign in to comment.