Skip to content

Commit

Permalink
Rename ParallelRunner -> ThreadedRunner (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogenstad authored and dbarrosop committed Sep 6, 2020
1 parent 5901b09 commit 401cad3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion nornir/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class RunnerConfig(object):
__slots__ = ("plugin", "options")

class Parameters:
plugin = Parameter(default="parallel", envvar="NORNIR_RUNNER_PLUGIN")
plugin = Parameter(default="threaded", envvar="NORNIR_RUNNER_PLUGIN")
options = Parameter(default={}, envvar="NORNIR_RUNNER_OPTIONS")

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions nornir/plugins/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def run(self, task: Task, hosts: List[Host]) -> AggregatedResult:
return result


class ParallelRunner:
class ThreadedRunner:
"""
ParallelRunner runs the task over each host using threads
ThreadedRunner runs the task over each host using threads
Arguments:
num_workers: number of threads to use
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api"

[tool.poetry.plugins."nornir.plugins.runners"]
"serial" = "nornir.plugins.runners:SerialRunner"
"parallel" = "nornir.plugins.runners:ParallelRunner"
"threaded" = "nornir.plugins.runners:ThreadedRunner"

[tool.poetry]
name = "nornir"
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_config_defaults(self):
c = Config()
assert c.dict() == {
"core": {"raise_on_error": False},
"runner": {"options": {}, "plugin": "parallel"},
"runner": {"options": {}, "plugin": "threaded"},
"inventory": {
"plugin": "",
"options": {},
Expand All @@ -42,7 +42,7 @@ def test_config_from_dict_defaults(self):
c = Config.from_dict()
assert c.dict() == {
"core": {"raise_on_error": False},
"runner": {"options": {}, "plugin": "parallel"},
"runner": {"options": {}, "plugin": "threaded"},
"inventory": {
"plugin": "",
"options": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time

from nornir.core.exceptions import NornirExecutionError
from nornir.plugins.runners import ParallelRunner
from nornir.plugins.runners import ThreadedRunner

import pytest

Expand Down Expand Up @@ -42,15 +42,15 @@ def verify_data_change(task):
class Test(object):
def test_blocking_task_multithreading(self, nornir):
t1 = datetime.datetime.now()
nornir.with_runner(ParallelRunner(num_workers=NUM_WORKERS)).run(
nornir.with_runner(ThreadedRunner(num_workers=NUM_WORKERS)).run(
blocking_task, wait=2
)
t2 = datetime.datetime.now()
delta = t2 - t1
assert delta.seconds == 2, delta

def test_failing_task_simple_multithread(self, nornir):
result = nornir.with_runner(ParallelRunner(num_workers=NUM_WORKERS)).run(
result = nornir.with_runner(ThreadedRunner(num_workers=NUM_WORKERS)).run(
failing_task_simple,
)
processed = False
Expand All @@ -61,7 +61,7 @@ def test_failing_task_simple_multithread(self, nornir):
assert processed

def test_failing_task_complex_multithread(self, nornir):
result = nornir.with_runner(ParallelRunner(num_workers=NUM_WORKERS)).run(
result = nornir.with_runner(ThreadedRunner(num_workers=NUM_WORKERS)).run(
failing_task_complex,
)
processed = False
Expand All @@ -73,15 +73,15 @@ def test_failing_task_complex_multithread(self, nornir):

def test_failing_task_complex_multithread_raise_on_error(self, nornir):
with pytest.raises(NornirExecutionError) as e:
nornir.with_runner(ParallelRunner(num_workers=NUM_WORKERS)).run(
nornir.with_runner(ThreadedRunner(num_workers=NUM_WORKERS)).run(
failing_task_complex, raise_on_error=True
)
for k, v in e.value.result.items():
assert isinstance(k, str), k
assert isinstance(v.exception, CustomException), v

def test_change_data_in_thread(self, nornir):
nornir.with_runner(ParallelRunner(num_workers=NUM_WORKERS)).run(change_data,)
nornir.with_runner(ParallelRunner(num_workers=NUM_WORKERS)).run(
nornir.with_runner(ThreadedRunner(num_workers=NUM_WORKERS)).run(change_data,)
nornir.with_runner(ThreadedRunner(num_workers=NUM_WORKERS)).run(
verify_data_change,
)

0 comments on commit 401cad3

Please sign in to comment.