Skip to content

Commit

Permalink
Clarify error message in bulkwalk
Browse files Browse the repository at this point in the history
This will avoid users of running into a cryptic error-message when
calling bulkwalk with only one OID.

References #22
  • Loading branch information
exhuma committed Jun 8, 2018
1 parent fec9496 commit ba20259
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions puresnmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ def bulkwalk(ip, community, oids, bulk_size=10, port=161):
VarBind(oid=ObjectIdentifier((1, 3, 6, 1, 2, 1, 2, 2, 1, 22, 38)), value='0.0')
"""

if not isinstance(oids, list):
raise TypeError('OIDS need to be passed as list!')

result = multiwalk(ip, community, oids, port=161,
fetcher=_bulkwalk_fetcher(bulk_size))
for oid, value in result:
Expand Down
15 changes: 15 additions & 0 deletions puresnmp/test/test_package_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,21 @@ def test_get_call_args(self):
bulk_size=2))
mck.assert_called_with('::1', 161, bytes(packet), timeout=2)

def test_get_call_args_issue_22(self):
data = readbytes('dummy.hex') # any dump would do
packet = Sequence(
Integer(Version.V2C),
OctetString('public'),
BulkGetRequest(0, 0, 2, ObjectIdentifier(1, 2, 3))
)
with patch('puresnmp.send') as mck, \
patch('puresnmp.get_request_id') as mck2:
mck2.return_value = 0
mck.return_value = data

with self.assertRaisesRegex(TypeError, 'OIDS.*list'):
# we need to wrap this in a list to consume the generator.
list(bulkwalk('::1', 'public', '1.2.3', bulk_size=2))

@patch('puresnmp.send')
@patch('puresnmp.get_request_id')
Expand Down

0 comments on commit ba20259

Please sign in to comment.