snmp: Keep get_next method backward-compatible

get_next() method used to get values under scope of a given OID before
high-level API was introduced. This patch makes this method work as
before since iRMC inspection depends on this behavior.

Change-Id: I3b5abc2e7df9283086265df090f23890a409bc1d
This commit is contained in:
Hironori Shiina 2018-07-23 00:16:53 +09:00
parent e19efd8ca5
commit ca6f289571
2 changed files with 21 additions and 14 deletions

View File

@ -320,25 +320,32 @@ class SNMPClient(object):
self._get_auth(),
self._get_transport(),
self._get_context(),
snmp.ObjectType(snmp.ObjectIdentity(oid)))
snmp.ObjectType(snmp.ObjectIdentity(oid)),
lexicographicMode=False)
except snmp_error.PySnmpError as e:
raise exception.SNMPFailure(operation="GET_NEXT", error=e)
(error_indication, error_status, error_index,
var_bind_table) = next(snmp_gen)
vals = []
for (error_indication, error_status, error_index,
var_binds) in snmp_gen:
if error_indication:
# SNMP engine-level error.
raise exception.SNMPFailure(operation="GET_NEXT",
error=error_indication)
if error_indication:
# SNMP engine-level error.
raise exception.SNMPFailure(operation="GET_NEXT",
error=error_indication)
if error_status:
# SNMP PDU error.
raise exception.SNMPFailure(operation="GET_NEXT",
error=error_status.prettyPrint())
if error_status:
# SNMP PDU error.
raise exception.SNMPFailure(operation="GET_NEXT",
error=error_status.prettyPrint())
return [val for row in var_bind_table for name, val in row]
# this is not a table, but a table row
# e.g. 1-D array of tuples
_name, value = var_binds[0]
vals.append(value)
return vals
def set(self, oid, value):
"""Use PySNMP to perform an SNMP SET operation on a single object.

View File

@ -147,8 +147,8 @@ class SNMPClientTestCase(base.TestCase):
def test_get_next(self, mock_auth, mock_context, mock_transport,
mock_nextcmd):
var_bind = (self.oid, self.value)
mock_nextcmd.return_value = iter([("", None, 0,
[[var_bind, var_bind]])])
mock_nextcmd.return_value = iter([("", None, 0, [var_bind]),
("", None, 0, [var_bind])])
client = snmp.SNMPClient(self.address, self.port, snmp.SNMP_V3)
val = client.get_next(self.oid)
self.assertEqual([self.value, self.value], val)