From d025630b83d89dfda18cf9c4d54af6cd52d8afa7 Mon Sep 17 00:00:00 2001 From: Wilhelm Schonfeldt Date: Fri, 26 Sep 2025 16:37:51 +0200 Subject: [PATCH] Fix: Make Huawei BGP parser conform to MikroTik approach - Remove custom __init__ from HuaweiBGPRouteTable class - Use standard BGPRouteTable inheritance like MikroTik does - Add BGPRoute import and instantiate BGPRoute objects in bgp_table() - Enable proper Pydantic validation for both table and routes - Ensure consistent behavior across all BGP parsers - Update .gitignore to exclude dev-build.sh and dev-docker/ --- .gitignore | 2 ++ hyperglass/models/parsing/huawei.py | 14 ++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index dff8f8c..2a0786d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ hyperglass/hyperglass/static TODO* .env +dev-build.sh +dev-docker/ test.py .DS_Store diff --git a/hyperglass/models/parsing/huawei.py b/hyperglass/models/parsing/huawei.py index 5b7671e..c93c1d0 100644 --- a/hyperglass/models/parsing/huawei.py +++ b/hyperglass/models/parsing/huawei.py @@ -9,7 +9,7 @@ from pydantic import ConfigDict, field_validator, model_validator # Project from hyperglass.log import log -from hyperglass.models.data.bgp_route import BGPRouteTable +from hyperglass.models.data.bgp_route import BGPRoute, BGPRouteTable # Local from ..main import HyperglassModel @@ -318,15 +318,9 @@ def _extract_route_entries(lines: t.List[str]) -> t.List[HuaweiRouteEntry]: class HuaweiBGPRouteTable(BGPRouteTable): - """Custom BGP Route Table for Huawei that bypasses validation.""" + """Canonical Huawei BGP Route Table.""" - def __init__(self, **kwargs): - """Initialize without calling parent validation.""" - # Set attributes directly without validation using object.__setattr__ - object.__setattr__(self, "vrf", kwargs.get("vrf", "default")) - object.__setattr__(self, "count", kwargs.get("count", 0)) - object.__setattr__(self, "routes", kwargs.get("routes", [])) - object.__setattr__(self, "winning_weight", kwargs.get("winning_weight", "low")) + # No custom __init__ needed; inherit from BGPRouteTable (which should be a Pydantic model) class HuaweiBGPTable(HuaweiBase): @@ -388,7 +382,7 @@ class HuaweiBGPTable(HuaweiBase): RPKI_STATE_MAP.get("unknown") if route.is_valid else RPKI_STATE_MAP.get("valid") ), } - routes.append(route_data) + routes.append(BGPRoute(**route_data)) return HuaweiBGPRouteTable( vrf="default",