Skip to content

Commit

Permalink
fix to_dict when there is no value
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-sahlmann committed Jul 27, 2023
1 parent 8f75dc4 commit 69935d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mb_netmgmt/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ def decode(value):


def to_dict(varbind):
val = None
tag = None
if varbind.value:
val = decode(varbind.value.val)
tag = str(varbind.value.tag)
return {
"val": decode(varbind.value.val),
"tag": str(varbind.value.tag),
"val": val,
"tag": tag,
}
6 changes: 6 additions & 0 deletions test/test_mb_netmgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,9 @@ def test_to_dict():
varbind = SNMPvarbind()
result = snmp.to_dict(varbind)
assert result == {"tag": "NULL", "val": 0}


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

0 comments on commit 69935d1

Please sign in to comment.