Skip to content

Commit 8a62bca

Browse files
authored
Merge pull request #53 from INSRapperswil/51-move_xxxNornirNutsContext.nornir_filter_up_to_base_class
51 move xxx nornir nuts context.nornir filter up to base class
2 parents 62ba087 + 11bf432 commit 8a62bca

11 files changed

+12
-53
lines changed

nuts/base_tests/napalm_bgp_neighbors.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
from typing import Dict, Callable, List, Any
33

44
import pytest
5-
from nornir.core.filter import F
65
from nornir.core.task import MultiResult, Result
76
from nornir_napalm.plugins.tasks import napalm_get
87

98
from nuts.context import NornirNutsContext
10-
from nuts.helpers.filters import filter_hosts
119
from nuts.helpers.result import AbstractHostResultExtractor, NutsResult
1210

1311

@@ -37,9 +35,6 @@ def nuts_task(self) -> Callable[..., Result]:
3735
def nuts_arguments(self) -> Dict[str, List[str]]:
3836
return {"getters": ["bgp_neighbors"]}
3937

40-
def nornir_filter(self) -> F:
41-
return filter_hosts(self.nuts_parameters["test_data"])
42-
4338
def nuts_extractor(self) -> BgpNeighborsExtractor:
4439
return BgpNeighborsExtractor(self)
4540

nuts/base_tests/napalm_get_users.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
from typing import Dict, Callable, List, Any
33

44
import pytest
5-
from nornir.core.filter import F
65
from nornir.core.task import MultiResult, Result
76
from nornir_napalm.plugins.tasks import napalm_get
87

98
from nuts.context import NornirNutsContext
10-
from nuts.helpers.filters import filter_hosts
119
from nuts.helpers.result import AbstractHostResultExtractor, NutsResult
1210

1311

@@ -23,9 +21,6 @@ def nuts_task(self) -> Callable[..., Result]:
2321
def nuts_arguments(self) -> Dict[str, List[str]]:
2422
return {"getters": ["users"]}
2523

26-
def nornir_filter(self) -> F:
27-
return filter_hosts(self.nuts_parameters["test_data"])
28-
2924
def nuts_extractor(self) -> UsersExtractor:
3025
return UsersExtractor(self)
3126

nuts/base_tests/napalm_interfaces.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
from typing import Dict, Callable, List, Any
33

44
import pytest
5-
from nornir.core.filter import F
65
from nornir.core.task import MultiResult, Result
76
from nornir_napalm.plugins.tasks import napalm_get
87

98
from nuts.context import NornirNutsContext
10-
from nuts.helpers.filters import filter_hosts
119
from nuts.helpers.result import AbstractHostResultExtractor, NutsResult
1210

1311

@@ -23,9 +21,6 @@ def nuts_task(self) -> Callable[..., Result]:
2321
def nuts_arguments(self) -> Dict[str, List[str]]:
2422
return {"getters": ["interfaces"]}
2523

26-
def nornir_filter(self) -> F:
27-
return filter_hosts(self.nuts_parameters["test_data"])
28-
2924
def nuts_extractor(self) -> InterfacesExtractor:
3025
return InterfacesExtractor(self)
3126

nuts/base_tests/napalm_lldp_neighbors.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
from typing import Dict, Callable, List, Any
33

44
import pytest
5-
from nornir.core.filter import F
65
from nornir.core.task import MultiResult, Result
76
from nornir_napalm.plugins.tasks import napalm_get
87

98
from nuts.context import NornirNutsContext
109
from nuts.helpers.converters import InterfaceNameConverter
11-
from nuts.helpers.filters import filter_hosts
1210
from nuts.helpers.result import AbstractHostResultExtractor, NutsResult
1311

1412

@@ -43,9 +41,6 @@ def nuts_task(self) -> Callable[..., Result]:
4341
def nuts_arguments(self) -> Dict[str, List[str]]:
4442
return {"getters": ["lldp_neighbors_detail"]}
4543

46-
def nornir_filter(self) -> F:
47-
return filter_hosts(self.nuts_parameters["test_data"])
48-
4944
def nuts_extractor(self) -> LldpNeighborsExtractor:
5045
return LldpNeighborsExtractor(self)
5146

nuts/base_tests/napalm_network_instances.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
from typing import Dict, List, Callable, Any
33

44
import pytest
5-
from nornir.core.filter import F
65
from nornir.core.task import MultiResult, Result
76
from nornir_napalm.plugins.tasks import napalm_get
87

9-
from nuts.helpers.filters import filter_hosts
108
from nuts.helpers.result import AbstractHostResultExtractor, NutsResult
119
from nuts.context import NornirNutsContext
1210

@@ -35,9 +33,6 @@ def nuts_task(self) -> Callable[..., Result]:
3533
def nuts_arguments(self) -> Dict[str, List[str]]:
3634
return {"getters": ["network_instances"]}
3735

38-
def nornir_filter(self) -> F:
39-
return filter_hosts(self.nuts_parameters["test_data"])
40-
4136
def nuts_extractor(self) -> NetworkInstancesExtractor:
4237
return NetworkInstancesExtractor(self)
4338

nuts/base_tests/napalm_ping.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
import pytest
66
from nornir.core import Task
7-
from nornir.core.filter import F
87
from nornir.core.task import Result
98
from nornir_napalm.plugins.tasks import napalm_ping
109

1110
from nuts.context import NornirNutsContext
12-
from nuts.helpers.filters import filter_hosts
1311
from nuts.helpers.result import (
1412
NutsResult,
1513
AbstractHostDestResultExtractor,
@@ -110,9 +108,6 @@ def napalm_ping_multi_dests(self, task: Task, **kwargs: Any) -> Result:
110108
result[0].destination = destination # type: ignore[attr-defined]
111109
return Result(host=task.host, result="All pings executed")
112110

113-
def nornir_filter(self) -> F:
114-
return filter_hosts(self.nuts_parameters["test_data"])
115-
116111
def nuts_extractor(self) -> PingExtractor:
117112
return PingExtractor(self)
118113

nuts/base_tests/netmiko_cdp_neighbors.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
from typing import Callable, Dict, Any
33

44
import pytest
5-
from nornir.core.filter import F
65
from nornir.core.task import MultiResult, Result
76
from nornir_netmiko import netmiko_send_command
87

9-
from nuts.helpers.filters import filter_hosts
108
from nuts.helpers.result import AbstractHostResultExtractor, NutsResult
119
from nuts.context import NornirNutsContext
1210

@@ -24,9 +22,6 @@ def nuts_task(self) -> Callable[..., Result]:
2422
def nuts_arguments(self) -> Dict[str, Any]:
2523
return {"command_string": "show cdp neighbors detail", "use_textfsm": True}
2624

27-
def nornir_filter(self) -> F:
28-
return filter_hosts(self.nuts_parameters["test_data"])
29-
3025
def nuts_extractor(self) -> CdpNeighborsExtractor:
3126
return CdpNeighborsExtractor(self)
3227

nuts/base_tests/netmiko_iperf.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
from typing import Dict, Callable, Any
55
import shlex
66

7-
from nornir.core.filter import F
87
from nornir.core.task import Task, Result
8+
from nornir.core.filter import F
99
from nornir_netmiko import netmiko_send_command
1010

1111
from nuts.context import NornirNutsContext
12-
from nuts.helpers.filters import filter_hosts
1312
from nuts.helpers.errors import Error
1413
from nuts.helpers.result import NutsResult, AbstractHostDestResultExtractor
1514

@@ -70,9 +69,6 @@ def netmiko_run_iperf(self, task: Task) -> Result:
7069
result[0].destination = destination # type: ignore[attr-defined]
7170
return Result(host=task.host, result=f"iperf executed for {task.host}")
7271

73-
def nornir_filter(self) -> F:
74-
return filter_hosts(self.nuts_parameters["test_data"])
75-
7672
def setup(self) -> None:
7773
"""
7874
Sets up the all destinations to act as iperf servers.

nuts/base_tests/netmiko_ospf_neighbors.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
from typing import Callable, Dict, Any
33

44
import pytest
5-
from nornir.core.filter import F
65
from nornir.core.task import MultiResult, Result
76
from nornir_netmiko import netmiko_send_command
87

98
from nuts.context import NornirNutsContext
10-
from nuts.helpers.filters import filter_hosts
119
from nuts.helpers.result import AbstractHostResultExtractor, NutsResult
1210

1311

@@ -24,9 +22,6 @@ def nuts_task(self) -> Callable[..., Result]:
2422
def nuts_arguments(self) -> Dict[str, Any]:
2523
return {"command_string": "show ip ospf neighbor", "use_textfsm": True}
2624

27-
def nornir_filter(self) -> F:
28-
return filter_hosts(self.nuts_parameters["test_data"])
29-
3025
def nuts_extractor(self) -> OspfNeighborsExtractor:
3126
return OspfNeighborsExtractor(self)
3227

nuts/context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from nuts.helpers.errors import NutsSetupError
1212
from nuts.helpers.result import AbstractResultExtractor
13+
from nuts.helpers.filters import filter_hosts
1314

1415

1516
class NutsContext:
@@ -109,11 +110,11 @@ def nuts_task(self) -> Callable[..., Result]:
109110
"""
110111
raise NotImplementedError
111112

112-
def nornir_filter(self) -> Optional[F]:
113+
def nornir_filter(self) -> F:
113114
"""
114115
:return: A nornir filter that is applied to the nornir instance
115116
"""
116-
return None
117+
return filter_hosts(self.nuts_parameters["test_data"])
117118

118119
def general_result(self) -> AggregatedResult:
119120
"""

0 commit comments

Comments
 (0)