diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index f5ac4b26f1330f516f288706a378d54e37580a36..9561ce47a0c4a0de06a5f62fc97e00d6fb104065 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -402,7 +402,9 @@ def _load_interfaces(hostname): base_key_pattern = f'netconf:{hostname}*' if hostname else 'netconf:*' yield from _load_docs(base_key_pattern) - yield from _load_docs(f'lab:{base_key_pattern}') + no_lab = common.get_bool_request_arg('no-lab', False) + if not no_lab: + yield from _load_docs(f'lab:{base_key_pattern}') def _add_bundle_parents(interfaces, hostname=None): @@ -495,6 +497,9 @@ def interfaces(hostname=None): which returns information for either all interfaces or those on the requested hostname. + The optional `no-lab` parameter omits lab routers + if it's truthiness evaluates to True. + The response is a list of information for all interfaces that should be polled, including service information and snmp information. @@ -509,6 +514,10 @@ def interfaces(hostname=None): cache_key = f'classifier-cache:poller-interfaces:{hostname}' \ if hostname else 'classifier-cache:poller-interfaces:all' + no_lab = common.get_bool_request_arg('no-lab', False) + if no_lab: + cache_key = f'{cache_key}:no_lab' + r = common.get_current_redis() result = _ignore_cache_or_retrieve(request, cache_key, r) diff --git a/test/test_general_poller_routes.py b/test/test_general_poller_routes.py index 7373ac26739871269ec05f68214a571c2d4c2187..e17d8f3f6c1cbd2438020a7b21740bf7390bd05b 100644 --- a/test/test_general_poller_routes.py +++ b/test/test_general_poller_routes.py @@ -20,6 +20,21 @@ def test_get_all_interfaces(client): response_routers = {ifc['router'] for ifc in response_data} assert len(response_routers) > 1, \ 'there should data from be lots of routers' + assert any('.lab.' in name for name in response_routers) + + +def test_get_all_interfaces_no_lab(client): + rv = client.get( + '/poller/interfaces?no-lab=1', + headers=DEFAULT_REQUEST_HEADERS) + assert rv.status_code == 200 + assert rv.is_json + response_data = json.loads(rv.data.decode('utf-8')) + jsonschema.validate(response_data, poller.INTERFACE_LIST_SCHEMA) + response_routers = {ifc['router'] for ifc in response_data} + assert len(response_routers) > 1, \ + 'there should data from be lots of routers' + assert all('.lab.' not in name for name in response_routers) def test_all_router_interface_speeds(client):