Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ParallelRunner -> ThreadedRunner #544

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)