Skip to content

Commit

Permalink
Avoid exception on adding ip device with wrong ip
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Nov 3, 2023
1 parent ccb83d1 commit 17ece24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion python/nav/Snmp/pynetsnmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from pynetsnmp import netsnmp
from pynetsnmp.netsnmp import (
Session,
SnmpError as PynetSnmpError,
SNMP_MSG_GETNEXT,
mkoid,
lib,
Expand Down Expand Up @@ -107,7 +108,10 @@ def __init__(
self.timeout = timeout

self.handle = _MySnmpSession(self._build_cmdline())
self.handle.open()
try:
self.handle.open()
except PynetSnmpError:
raise SnmpError

Check warning on line 114 in python/nav/Snmp/pynetsnmp.py

View check run for this annotation

Codecov / codecov/patch

python/nav/Snmp/pynetsnmp.py#L113-L114

Added lines #L113 - L114 were not covered by tests

def _build_cmdline(self):
try:
Expand Down
2 changes: 1 addition & 1 deletion python/nav/web/seeddb/page/netbox/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ def get_type_id(ip_addr, profile):

def snmp_type(ip_addr, snmp_ro, snmp_version):
"""Query ip for sysobjectid using form data"""
snmp = Snmp(ip_addr, snmp_ro, snmp_version)
try:
snmp = Snmp(ip_addr, snmp_ro, snmp_version)

Check warning on line 269 in python/nav/web/seeddb/page/netbox/edit.py

View check run for this annotation

Codecov / codecov/patch

python/nav/web/seeddb/page/netbox/edit.py#L269

Added line #L269 was not covered by tests
sysobjectid = snmp.get('.1.3.6.1.2.1.1.2.0')
except SnmpError:
return None
Expand Down

0 comments on commit 17ece24

Please sign in to comment.