1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-04-17 21:38:27 +00:00

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/
This commit is contained in:
Wilhelm Schonfeldt 2025-09-26 16:37:51 +02:00
parent 4414d2ec03
commit d025630b83
2 changed files with 6 additions and 10 deletions

2
.gitignore vendored
View file

@ -2,6 +2,8 @@
hyperglass/hyperglass/static hyperglass/hyperglass/static
TODO* TODO*
.env .env
dev-build.sh
dev-docker/
test.py test.py
.DS_Store .DS_Store

View file

@ -9,7 +9,7 @@ from pydantic import ConfigDict, field_validator, model_validator
# Project # Project
from hyperglass.log import log from hyperglass.log import log
from hyperglass.models.data.bgp_route import BGPRouteTable from hyperglass.models.data.bgp_route import BGPRoute, BGPRouteTable
# Local # Local
from ..main import HyperglassModel from ..main import HyperglassModel
@ -318,15 +318,9 @@ def _extract_route_entries(lines: t.List[str]) -> t.List[HuaweiRouteEntry]:
class HuaweiBGPRouteTable(BGPRouteTable): class HuaweiBGPRouteTable(BGPRouteTable):
"""Custom BGP Route Table for Huawei that bypasses validation.""" """Canonical Huawei BGP Route Table."""
def __init__(self, **kwargs): # No custom __init__ needed; inherit from BGPRouteTable (which should be a Pydantic model)
"""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"))
class HuaweiBGPTable(HuaweiBase): 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") 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( return HuaweiBGPRouteTable(
vrf="default", vrf="default",