Skip to content

Commit

Permalink
save varbind error messages to dict
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-sahlmann committed Jul 27, 2023
1 parent 69935d1 commit 4cee78a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion mb_netmgmt/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ def to_dict(varbind):
if varbind.value:
val = decode(varbind.value.val)
tag = str(varbind.value.tag)
return {
result = {
"val": val,
"tag": tag,
}
if varbind.noSuchObject:
result["noSuchObject"] = 0
if varbind.noSuchInstance:
result["noSuchInstance"] = 0
if varbind.endOfMibView:
result["endOfMibView"] = 0
return result
6 changes: 3 additions & 3 deletions test/test_mb_netmgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytest
from ncclient.transport.session import BASE_NS_1_0, to_ele
from ncclient.transport.ssh import MSG_DELIM
from scapy.layers.snmp import SNMPvarbind
from scapy.layers.snmp import ASN1_NULL, SNMPvarbind

from mb_netmgmt import mb, netconf, snmp, ssh, use_scalar_strings, yaml
from mb_netmgmt.__main__ import create_server, get_cli_patterns
Expand Down Expand Up @@ -256,6 +256,6 @@ def test_to_dict():


def test_no_such_instance_to_dict():
varbind = SNMPvarbind(value=None, noSuchInstance=0)
varbind = SNMPvarbind(value=None, noSuchInstance=ASN1_NULL(0))
result = snmp.to_dict(varbind)
assert result == {"tag": None, "val": None}
assert result == {"tag": None, "val": None, "noSuchInstance": 0}

0 comments on commit 4cee78a

Please sign in to comment.