Skip to content

Commit

Permalink
Remove validate_single from RoutePreferenceValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsasha committed Jan 31, 2023
1 parent 265e620 commit f1ff0ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
13 changes: 0 additions & 13 deletions irrd/routepref/routepref.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ def _build_tree(self, route_objects: Iterable[Dict[str, str]]) -> None:
rnode.data = {}
rnode.data[route_object["pk"]] = (preference, route_object["route_preference_status"])

def validate_single(self, prefix: IP, source: str) -> RoutePreferenceStatus:
# TODO: we might not need this at all?
if not self.source_preferences:
return RoutePreferenceStatus.visible
try:
preference = self.source_preferences[source]
except KeyError:
return RoutePreferenceStatus.visible

search_args = {"network": str(prefix)}
overlapping_nodes = self.rtree.search_covered(**search_args) + self.rtree.search_covering(**search_args)
return self._evaluate_route(preference, overlapping_nodes)

def validate_known_routes(self) -> Tuple[List[str], List[str]]:
"""
Validate all routes known to this validator, based on the
Expand Down
25 changes: 9 additions & 16 deletions irrd/routepref/tests/test_routepref.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ def test_route_preference_validator(config_override):
"pk": "route-H",
"route_preference_status": RoutePreferenceStatus.visible,
},
{
# No overlaps
"source": "SRC-LOWEST",
"prefix": "198.51.100.0/24",
"pk": "route-I",
"route_preference_status": RoutePreferenceStatus.suppressed,
},
]

validator = RoutePreferenceValidator(route_objects)
to_be_visible, to_be_suppressed = validator.validate_known_routes()
assert validator.excluded_currently_suppressed == ["route-G"]
assert to_be_visible == ["route-A", "route-B"]
assert to_be_visible == ["route-A", "route-B", "route-I"]
assert to_be_suppressed == ["route-D", "route-C", "route-E", "route-F"]

assert validator.validate_single(IP("192.0.0.0/26"), "SRC-NOPREF") == RoutePreferenceStatus.visible
assert validator.validate_single(IP("192.0.0.0/26"), "SRC-HIGH-A") == RoutePreferenceStatus.visible
assert validator.validate_single(IP("192.0.0.0/26"), "SRC-LOWEST") == RoutePreferenceStatus.suppressed
assert validator.validate_single(IP("192.0.0.0/8"), "SRC-HIGH-A") == RoutePreferenceStatus.visible
assert validator.validate_single(IP("192.0.0.0/8"), "SRC-LOWEST") == RoutePreferenceStatus.suppressed
assert validator.validate_single(IP("191.0.0.0/8"), "SRC-LOWEST") == RoutePreferenceStatus.visible

config_override(
{
"sources": {
Expand All @@ -94,16 +94,9 @@ def test_route_preference_validator(config_override):

validator = RoutePreferenceValidator(route_objects)
to_be_visible, to_be_suppressed = validator.validate_known_routes()
assert validator.excluded_currently_suppressed == ["route-A", "route-B", "route-G"]
assert validator.excluded_currently_suppressed == ["route-A", "route-B", "route-G", "route-I"]
assert to_be_suppressed == []

assert validator.validate_single(IP("192.0.0.0/26"), "SRC-NOPREF") == RoutePreferenceStatus.visible
assert validator.validate_single(IP("192.0.0.0/26"), "SRC-HIGH-A") == RoutePreferenceStatus.visible
assert validator.validate_single(IP("192.0.0.0/26"), "SRC-LOWEST") == RoutePreferenceStatus.visible
assert validator.validate_single(IP("192.0.0.0/8"), "SRC-HIGH-A") == RoutePreferenceStatus.visible
assert validator.validate_single(IP("192.0.0.0/8"), "SRC-LOWEST") == RoutePreferenceStatus.visible
assert validator.validate_single(IP("191.0.0.0/8"), "SRC-LOWEST") == RoutePreferenceStatus.visible


def test_update_route_preference_status(config_override):
config_override(
Expand Down

0 comments on commit f1ff0ef

Please sign in to comment.