From 137ffef77e2eff4661c56a55204a7bc463f32b74 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Fri, 8 Feb 2019 11:16:52 +0100 Subject: Add missing SNMP PDU error classes Added missing SNMP PDU error classes and their handling in Command Responder --- pysnmp/entity/rfc3413/cmdrsp.py | 16 ++++++++++++++-- pysnmp/proto/rfc1905.py | 13 +++++++------ pysnmp/smi/error.py | 29 +++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 14 deletions(-) (limited to 'pysnmp') diff --git a/pysnmp/entity/rfc3413/cmdrsp.py b/pysnmp/entity/rfc3413/cmdrsp.py index 772cc5ea..44d73d50 100644 --- a/pysnmp/entity/rfc3413/cmdrsp.py +++ b/pysnmp/entity/rfc3413/cmdrsp.py @@ -18,6 +18,12 @@ class CommandResponderBase(object): acmID = 3 # default MIB access control method to use SUPPORTED_PDU_TYPES = () SMI_ERROR_MAP = { + pysnmp.smi.error.TooBigError: 'tooBig', + # this should never bubble up, SNMP exception objects should be passed as values + pysnmp.smi.error.NoSuchNameError: 'noSuchName', + pysnmp.smi.error.BadValueError: 'badValue', + pysnmp.smi.error.ReadOnlyError: 'readOnly', + pysnmp.smi.error.GenError: 'genErr', pysnmp.smi.error.NoAccessError: 'noAccess', pysnmp.smi.error.WrongTypeError: 'wrongType', pysnmp.smi.error.WrongLengthError: 'wrongLength', @@ -248,6 +254,11 @@ class CommandResponderBase(object): errorIndication = str(err) elif isinstance(err, pysnmp.smi.error.SmiError): + + if isinstance(err, pysnmp.smi.error.TooBigError): + # rfc1905: 4.2.1.3 + varBinds = [] + errorStatus = self.SMI_ERROR_MAP.get(err.__class__, 'genErr') try: @@ -256,12 +267,13 @@ class CommandResponderBase(object): except IndexError: errorIndex = len(varBinds) and 1 or 0 - return errorIndication, errorStatus, errorIndex + return errorIndication, errorStatus, errorIndex, varBinds def completeMgmtOperation(self, varBinds, **context): (errorIndication, - errorStatus, errorIndex) = self._mapSmiErrors(varBinds, **context) + errorStatus, errorIndex, + varBinds) = self._mapSmiErrors(varBinds, **context) stateReference = context['stateReference'] diff --git a/pysnmp/proto/rfc1905.py b/pysnmp/proto/rfc1905.py index 4a229495..d5da3982 100644 --- a/pysnmp/proto/rfc1905.py +++ b/pysnmp/proto/rfc1905.py @@ -84,12 +84,13 @@ class VarBindList(univ.SequenceOf): errorStatus = univ.Integer( - namedValues=namedval.NamedValues(('noError', 0), ('tooBig', 1), ('noSuchName', 2), ('badValue', 3), ('readOnly', 4), - ('genErr', 5), ('noAccess', 6), ('wrongType', 7), ('wrongLength', 8), - ('wrongEncoding', 9), ('wrongValue', 10), ('noCreation', 11), - ('inconsistentValue', 12), ('resourceUnavailable', 13), ('commitFailed', 14), - ('undoFailed', 15), ('authorizationError', 16), ('notWritable', 17), - ('inconsistentName', 18)) + namedValues=namedval.NamedValues( + ('noError', 0), ('tooBig', 1), ('noSuchName', 2), ('badValue', 3), ('readOnly', 4), + ('genErr', 5), ('noAccess', 6), ('wrongType', 7), ('wrongLength', 8), + ('wrongEncoding', 9), ('wrongValue', 10), ('noCreation', 11), + ('inconsistentValue', 12), ('resourceUnavailable', 13), ('commitFailed', 14), + ('undoFailed', 15), ('authorizationError', 16), ('notWritable', 17), + ('inconsistentName', 18)) ) diff --git a/pysnmp/smi/error.py b/pysnmp/smi/error.py index 3ae9f2a2..df4682fc 100644 --- a/pysnmp/smi/error.py +++ b/pysnmp/smi/error.py @@ -43,7 +43,24 @@ class MibOperationError(SmiError): self.__outArgs.update(d) -# Aligned with SNMPv2 PDU error-status +# Aligned with SNMPv2 PDU error-status values + +class TooBigError(MibOperationError): + pass + + +class NoSuchNameError(MibOperationError): + pass + + +class BadValueError(MibOperationError): + pass + + +class ReadOnlyError(MibOperationError): + pass + + class GenError(MibOperationError): pass @@ -100,21 +117,21 @@ class InconsistentNameError(MibOperationError): pass -# Aligned with SNMPv2 Var-Bind exceptions +# Aligned with SNMPv2 PDU exceptions or error-status values -class NoSuchObjectError(MibOperationError): +class NoSuchObjectError(NoSuchNameError): pass -class NoSuchInstanceError(MibOperationError): +class NoSuchInstanceError(NoSuchNameError): pass -class EndOfMibViewError(MibOperationError): +class EndOfMibViewError(NoSuchNameError): pass -# Row management +# SNMP table management exceptions class TableRowManagement(MibOperationError): pass -- cgit v1.2.1