From 55c77b81cbd6183d15da4afd1bc1dae8109f40e6 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Fri, 10 Nov 2023 13:07:32 +0100 Subject: [PATCH] Use get_snmp_session_for_profile for write test This just makes the SeedDB write profile test work by delegating SNMP session establishment to the new get_snmp_session_for_profile function. --- python/nav/web/seeddb/page/netbox/edit.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/nav/web/seeddb/page/netbox/edit.py b/python/nav/web/seeddb/page/netbox/edit.py index fb364c362c..0fec26366a 100644 --- a/python/nav/web/seeddb/page/netbox/edit.py +++ b/python/nav/web/seeddb/page/netbox/edit.py @@ -186,7 +186,11 @@ def get_snmp_read_only_variables(ip_address: str, profile: ManagementProfile): def snmp_write_test(ip, profile): - """Test that snmp write works""" + """Tests that an SNMP profile really has write access. + + Tests by fetching sysLocation.0 and setting the same value. This will fail if + the device only allows writing to other parts of its mib view. + """ testresult = { 'error_message': '', @@ -198,11 +202,7 @@ def snmp_write_test(ip, profile): syslocation = '1.3.6.1.2.1.1.6.0' value = '' try: - snmp = Snmp( - ip, - profile.configuration.get("community"), - profile.configuration.get("version"), - ) + snmp = get_snmp_session_for_profile(profile)(ip) value = safestring(snmp.get(syslocation)) snmp.set(syslocation, 's', value.encode('utf-8')) except SnmpError as error: