2021-09-13 02:39:37 -07:00
|
|
|
"""Juniper BGP Route Parsing Tests."""
|
|
|
|
|
|
|
|
# flake8: noqa
|
|
|
|
# Standard Library
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
# Third Party
|
2021-09-16 13:46:50 -07:00
|
|
|
import pytest
|
2021-09-13 02:39:37 -07:00
|
|
|
|
|
|
|
# Project
|
|
|
|
from hyperglass.log import log
|
|
|
|
from hyperglass.models.config.devices import Device
|
|
|
|
from hyperglass.models.data.bgp_route import BGPRouteTable
|
|
|
|
|
|
|
|
# Local
|
|
|
|
from .._builtin.bgp_route_juniper import BGPRoutePluginJuniper
|
|
|
|
|
2021-09-16 13:46:50 -07:00
|
|
|
DEPENDS_KWARGS = {
|
|
|
|
"depends": ["hyperglass/external/tests/test_rpki.py::test_rpki"],
|
|
|
|
"scope": "session",
|
|
|
|
}
|
|
|
|
|
2021-09-13 02:39:37 -07:00
|
|
|
DIRECT = Path(__file__).parent.parent.parent.parent / ".samples" / "juniper_route_direct.xml"
|
|
|
|
INDIRECT = Path(__file__).parent.parent.parent.parent / ".samples" / "juniper_route_indirect.xml"
|
|
|
|
AS_PATH = Path(__file__).parent.parent.parent.parent / ".samples" / "juniper_route_aspath.xml"
|
|
|
|
|
|
|
|
|
|
|
|
def _tester(sample: str):
|
|
|
|
plugin = BGPRoutePluginJuniper()
|
|
|
|
|
|
|
|
device = Device(
|
|
|
|
name="Test Device",
|
|
|
|
address="127.0.0.1",
|
|
|
|
network={"name": "Test Network", "display_name": "Test Network"},
|
|
|
|
credential={"username": "", "password": ""},
|
2021-09-13 10:00:21 -07:00
|
|
|
type="juniper",
|
2021-09-13 02:39:37 -07:00
|
|
|
structured_output=True,
|
|
|
|
commands=[{"id": "test", "name": "Test", "rules": []}],
|
|
|
|
)
|
|
|
|
|
2021-09-13 14:11:55 -07:00
|
|
|
# Override has_directives method for testing.
|
|
|
|
device.has_directives = lambda *x: True
|
|
|
|
|
2021-09-13 02:39:37 -07:00
|
|
|
result = plugin.process((sample,), device)
|
|
|
|
assert isinstance(result, BGPRouteTable), "Invalid parsed result"
|
|
|
|
assert hasattr(result, "count"), "BGP Table missing count"
|
|
|
|
assert result.count > 0, "BGP Table count is 0"
|
|
|
|
|
|
|
|
|
2021-09-16 13:46:50 -07:00
|
|
|
@pytest.mark.dependency(**DEPENDS_KWARGS)
|
2021-09-13 02:39:37 -07:00
|
|
|
def test_juniper_bgp_route_direct():
|
|
|
|
with DIRECT.open("r") as file:
|
|
|
|
sample = file.read()
|
|
|
|
return _tester(sample)
|
|
|
|
|
|
|
|
|
2021-09-16 13:46:50 -07:00
|
|
|
@pytest.mark.dependency(**DEPENDS_KWARGS)
|
2021-09-13 02:39:37 -07:00
|
|
|
def test_juniper_bgp_route_indirect():
|
|
|
|
with INDIRECT.open("r") as file:
|
|
|
|
sample = file.read()
|
|
|
|
return _tester(sample)
|
|
|
|
|
|
|
|
|
2021-09-16 13:46:50 -07:00
|
|
|
@pytest.mark.dependency(**DEPENDS_KWARGS)
|
2021-09-13 02:39:37 -07:00
|
|
|
def test_juniper_bgp_route_aspath():
|
|
|
|
with AS_PATH.open("r") as file:
|
|
|
|
sample = file.read()
|
|
|
|
return _tester(sample)
|