Skip to content
Snippets Groups Projects
Select Git revision
  • f64a3e749848d60a64548e917d552debf419bd28
  • python3 default protected
  • feature/exabgp_support2
  • feature/exabgp_support2.bgpextcommunity
  • feature/exabgp_support2.django4.2
  • fix/existingcheck_honor_fragtype
  • feature/python3-authz_netmask
  • feature/authz_netmask
  • fix/wrong_ratelimit_stats
  • feature/requirements_version_update2024-01
  • feature/split_celery
  • feature/improved-warning-mails
  • fix/reenable_expireset_via_restapi
  • feature/admin_user_delete_with_owned_rule_reassigning1
  • feature/admin_user_delete_with_owned_rule_reassigning
  • feature/branded_doc
  • fix/forked_snmp_polling_worker_exit_issue
  • fix/false_user_activation_error
  • feature/exabgp_with_docker-compose
  • fix/prefix_overlap_handling
  • fix/js_security_issues-a
  • save1
  • rpm-1.5-7
  • working1
  • myv1.6
  • t12b1
  • v1.5_newnew2
  • merged_final
  • v1.5_newnew
  • startstop_old
  • myadd2
  • tomas3
  • merge_jra2t6_and_RESTAPI
  • mytomas2
  • mynew1
  • new_jra2t6
  • v1.5_final
  • fod16_ruleroutes-merged_old
  • merged_new
  • v1.6_new_old
  • v1.5_new_old_follower
41 results

beanstalkc.py

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