From fc024c16ea3f8e9204c3370c2f258d89db18bc34 Mon Sep 17 00:00:00 2001
From: Robert Latta <robert.latta@geant.org>
Date: Tue, 17 Dec 2024 14:55:00 +0000
Subject: [PATCH] separated communities for retrieving peerings vs active
 polling. RE DBOARD3-1086

---
 inventory_provider/snmp.py            | 10 ++++++----
 inventory_provider/tasks/worker.py    |  3 ++-
 test/conftest.py                      |  2 +-
 test/per_router/test_celery_worker.py |  2 +-
 test/per_router/test_snmp_handling.py |  2 +-
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/inventory_provider/snmp.py b/inventory_provider/snmp.py
index 89758f1..2bbbf1d 100644
--- a/inventory_provider/snmp.py
+++ b/inventory_provider/snmp.py
@@ -253,7 +253,7 @@ def get_peer_state_info_juniper(hostname, community, logical_systems):
         hostname, community, logical_systems, _get_peer_state_info_juniper)
 
 
-def get_peer_state_info_nokia(hostname, community):
+def get_peer_state_info_nokia(hostname, walk_community, poll_community):
     """
     return peering info
 
@@ -261,11 +261,13 @@ def get_peer_state_info_nokia(hostname, community):
         {remote: str, oid: str, community: str}
 
     :param hostname:
-    :param community:
+    :param walk_community: community string used when querying the router for peerings
+    :param poll_community: community string added to the peer info for classification,
+    which is then used in dashboard for active state checking
     :return: generator yielding dicts
     """
     oid_prefix = f'.{NOKIA_BGP_PEER_STATE}.'
-    for ifc in walk(hostname, community, NOKIA_BGP_PEER_STATE):
+    for ifc in walk(hostname, walk_community, NOKIA_BGP_PEER_STATE):
         oid = ifc['oid']
         rest = oid[len(oid_prefix):]
         splits = rest.split('.')
@@ -294,5 +296,5 @@ def get_peer_state_info_nokia(hostname, community):
         yield {
             'remote': peer_address.exploded,
             'oid': oid,
-            'community': community
+            'community': poll_community
         }
diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py
index bd482a2..4923f3f 100644
--- a/inventory_provider/tasks/worker.py
+++ b/inventory_provider/tasks/worker.py
@@ -627,7 +627,8 @@ def _reload_router_config_nokia(
 def snmp_refresh_peerings_nokia(hostname, communities, update_callback=lambda S: None):
     get_peerings_func = functools.partial(
         snmp.get_peer_state_info_nokia,
-        community=communities['dashboard'],
+        walk_community=communities['inventory-provider'],
+        poll_community=communities['dashboard'],
     )
     snmp_refresh_peerings(
         get_peerings_func, hostname, 'nokia', update_callback=update_callback
diff --git a/test/conftest.py b/test/conftest.py
index ee51ec4..a2661d0 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -332,7 +332,7 @@ def mocked_worker_module(
         keys = filter(_wanted, cached_test_data.keys())
         return [json.loads(cached_test_data[k]) for k in keys]
 
-    def _mocked_snmp_peerings_nokia(hostname, community):
+    def _mocked_snmp_peerings_nokia(hostname, walk_community, poll_community):
         def _wanted(s):
             return re.match(r'^snmp-peerings:hosts:nokia\d.*', s)
 
diff --git a/test/per_router/test_celery_worker.py b/test/per_router/test_celery_worker.py
index f60e875..450db07 100644
--- a/test/per_router/test_celery_worker.py
+++ b/test/per_router/test_celery_worker.py
@@ -81,7 +81,7 @@ def test_snmp_refresh_peerings_nokia(mocked_worker_module, nokia_router):
     for k in list(_ifc_keys()):
         del backend_db()[k]
 
-    communities = {'dashboard': 'fake-community'}
+    communities = {'dashboard': 'fake-community', 'inventory-provider': 'fake-community'}
 
     worker.snmp_refresh_peerings_nokia(nokia_router, communities)
     assert list(_ifc_keys())
diff --git a/test/per_router/test_snmp_handling.py b/test/per_router/test_snmp_handling.py
index b813448..215982b 100644
--- a/test/per_router/test_snmp_handling.py
+++ b/test/per_router/test_snmp_handling.py
@@ -118,6 +118,6 @@ def test_peer_info_nokia(mocker):
     with open(os.path.join(TEST_DATA_DIRNAME, "snmp-peer-info-nokia.json")) as f:
         test_data = json.load(f)
     mocker.patch('inventory_provider.snmp.walk', lambda *args: test_data)
-    res = list(snmp.get_peer_state_info_nokia('ignored', 'ignored'))
+    res = list(snmp.get_peer_state_info_nokia('ignored', 'ignored', 'ignored'))
     jsonschema.validate(res, PEERING_RESULT_SCHEMA)
     assert len(res) == len(test_data)
-- 
GitLab