Skip to content
Snippets Groups Projects
Select Git revision
  • 0f2283b9a2f863971f74f3c40912d3e1d7ca748d
  • develop default
  • master protected
  • feature/frontend-tests
  • 0.99
  • 0.98
  • 0.97
  • 0.96
  • 0.95
  • 0.94
  • 0.93
  • 0.92
  • 0.91
  • 0.90
  • 0.89
  • 0.88
  • 0.87
  • 0.86
  • 0.85
  • 0.84
  • 0.83
  • 0.82
  • 0.81
  • 0.80
24 results

ECProjects.tsx

Blame
  • conftest.py 2.48 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"}
            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