Skip to content
Snippets Groups Projects
Select Git revision
  • 570470f035a3326eb2e108248aaaee325b3bb322
  • develop default protected
  • master protected
  • authorship-fix-from-develop
  • 1048-service-config-backfilling
  • feature/nat-1211-edgeport-lacp-xmit
  • fix/nat-1120-sdp-validation
  • NAT-1154-import-edge-port-update
  • fix/l3-imports
  • feature/10GGBS-NAT-980
  • fix/NAT-1009/fix-redeploy-base-config-if-there-is-a-vprn
  • 4.24
  • 4.23
  • 4.22
  • 4.21
  • 4.20
  • 4.19
  • 4.18
  • 4.17
  • 4.16
  • 4.15
  • 4.14
  • 4.13
  • 4.12
  • 4.11
  • 4.10
  • 4.8
  • 4.5
  • 4.4
  • 4.3
  • 4.2
31 results

build-docs.sh

Blame
  • conftest.py 2.58 KiB
    import json
    import pathlib
    from unittest.mock import patch
    from brian_polling_manager.interface_stats import cli
    from brian_polling_manager.interface_stats.vendors import juniper, nokia
    import pytest
    
    
    DATA_DIR = pathlib.Path(__file__).parent / "data"
    JUNIPER_DATA_FILENAME_EXTENSION = "-interface-info.xml"
    
    JUNIPER_ROUTERS = [
        path.name[: -len(JUNIPER_DATA_FILENAME_EXTENSION)]
        for path in DATA_DIR.iterdir()
        if path.name.endswith(JUNIPER_DATA_FILENAME_EXTENSION)
    ]
    
    NOKIA_ROUTERS = list(
        {
            path.name[: -len(suffix)]
            for suffix in {
                "-ports.xml",
                "-lags.xml",
                "-router-interfaces.xml",
                "-iess.xml",
                "-vprns.xml",
            }
            for path in DATA_DIR.iterdir()
            if path.name.endswith(suffix)
        }
    )
    
    
    @pytest.fixture
    def data_dir():
        return DATA_DIR
    
    
    @pytest.fixture
    def mocked_get_netconf(data_dir):
        def get_netconf(vendor, router_name, **_):
            if vendor == cli.Vendor.JUNIPER:
                return juniper.get_netconf_interface_info_from_source_dir(
                    router_name, source_dir=data_dir
                )
    
            else:
                return nokia.get_netconf_interface_info_from_source_dir(
                    router_name, source_dir=data_dir
                )
    
        with patch.object(
            cli.Vendor, "get_netconf", autospec=True, side_effect=get_netconf
        ) as mock:
            yield mock
    
    
    def poller_interfaces():
        file = DATA_DIR / "poller-interfaces.json"
        return json.loads(file.read_text())
    
    
    @pytest.fixture(scope="session")
    def juniper_inventory():
        def _excluded(ifc):
            return ifc["name"].startswith("dsc")
    
        polled = {}
        for ifc in poller_interfaces():
            if _excluded(ifc):
                continue
            polled.setdefault(ifc["router"], set()).add(ifc["name"])
        return polled
    
    
    @pytest.fixture
    def all_juniper_routers():
        return JUNIPER_ROUTERS
    
    
    @pytest.fixture
    def all_nokia_routers():
        return NOKIA_ROUTERS
    
    
    @pytest.fixture(params=JUNIPER_ROUTERS)
    def juniper_router_fqdn(request):
        # This fixture passes all juniper router fqdn's as a parametrized fixture. We could
        # do a pytest.mark.parametrize instead but we'd have to redefine JUNIPER_ROUTERS in
        # the test module or import from this conftest directly
        return request.param
    
    
    @pytest.fixture(params=NOKIA_ROUTERS)
    def nokia_router_fqdn(request):
        # This fixture passes all nokia router fqdn's as a parametrized fixture. We could
        # do a pytest.mark.parametrize instead but we'd have to redefine NOKIA_ROUTERS in
        # the test module or import from this conftest directly
        return request.param