diff --git a/irrd/routepref/routepref.py b/irrd/routepref/routepref.py index 5ee37dd55..a08426e00 100644 --- a/irrd/routepref/routepref.py +++ b/irrd/routepref/routepref.py @@ -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 diff --git a/irrd/routepref/tests/test_routepref.py b/irrd/routepref/tests/test_routepref.py index 660e17883..46cb97c18 100644 --- a/irrd/routepref/tests/test_routepref.py +++ b/irrd/routepref/tests/test_routepref.py @@ -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": { @@ -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(