etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
582 stars 200 forks source link

WrongValueError() in trying to write ifEntry in pysnmp 4.4.12 #316

Open mjrauhal opened 5 years ago

mjrauhal commented 5 years ago

With code that works with pysnmp 4.3.3, in 4.4.12 I get a WrongValueError() in trying to write ifEntry (((1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 1), 1),) with writeVars(). (Original code would write also other records into the ifEntry but found that the error persists even with just the first entry, so I reduced the problem to that for the purposes of this issue.)

What confuses me is the error references (1, 3, 6, 1, 2, 1, 31, 1, 3, 1, 1, 1) (under ifTestEntry, apparently) which is not referenced by my code at all.

Writing system records, system description 1.3.6.1.2.1.1.1.0 and friends, works fine.

Code snippet below; ifIndex is 1 and write_vars content verified by debug output to be (((1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 1), 1),)

        ifEntry, = self.instr.mibBuilder.importSymbols('IF-MIB', 'ifEntry')
        tbl_ndx = ifEntry.getInstIdFromIndices(ifindex)
        write_vars = (
            (ifEntry.name + (1,) + tbl_ndx, ifindex),  # ifIndex
        )
        var_binds = self.instr.writeVars(write_vars)

This is the error output (path beginnings sanitized):

2019-10-18 09:10:14,987 ERROR /usr/local/lib/python3.7/asyncio/base_events.py:1604 § Task exception was never retrieved
future: <Task finished coro=<SnmpAgent.config_check() done, defined at env/lib/python3.7/site-packages/mgmt/snmp/agent.py:137> exception=WrongValueError()>
Traceback (most recent call last):
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 1182, in __delegate
    name, val, idx, acInfo
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 995, in writeCleanup
    raise e
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 1182, in __delegate
    name, val, idx, acInfo
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 972, in writeTest
    raise self.__rowOpWanted[name]
pysnmp.smi.error.RowCreationWanted: RowCreationWanted({})
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 659, in setValue
    return self.syntax.setValue(value)
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-TC.py", line 409, in setValue
    if value != self:
  File "env/lib/python3.7/site-packages/pyasn1/type/base.py", line 214, in plug
    raise error.PyAsn1Error('Attempted "%s" operation on ASN.1 schema object' % name)
pyasn1.error.PyAsn1Error: Attempted "__ne__" operation on ASN.1 schema object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 772, in createTest
    self.__newSyntax = self.setValue(val, name, idx)
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 669, in setValue
    raise error.WrongValueError(idx=idx, name=name, msg=exc_v)
pysnmp.smi.error.WrongValueError: WrongValueError({'idx': 0, 'name': (1, 3, 6, 1, 2, 1, 31, 1, 3, 1, 1, 1), 'msg': PyAsn1Error('Attempted "__ne__" operation on ASN.1 schema object')})
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "env/lib/python3.7/site-packages/mgmt/snmp/agent.py", line 143, in config_check
    await self.apply_new_config()
  File "env/lib/python3.7/site-packages/mgmt/snmp/agent.py", line 445, in apply_new_config
    await self.mibs_from_config(update, ports)
  File "env/lib/python3.7/site-packages/mgmt/snmp/agent.py", line 536, in mibs_from_config
    update)
  File "env/lib/python3.7/site-packages/mgmt/snmp/mibs.py", line 253, in set_iface_mib
    var_binds = self.instr.writeVars(write_vars)
  File "env/lib/python3.7/site-packages/pysnmp/smi/instrum.py", line 256, in writeVars
    return self.flipFlopFsm(self.fsmWriteVar, varBinds, acInfo)
  File "env/lib/python3.7/site-packages/pysnmp/smi/instrum.py", line 242, in flipFlopFsm
    raise origExc.with_traceback(origTraceback)
  File "env/lib/python3.7/site-packages/pysnmp/smi/instrum.py", line 221, in flipFlopFsm
    rval = f(tuple(name), val, idx, acInfo)
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 532, in writeTest
    node.writeTest(name, val, idx, acInfo)
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 1211, in writeTest
    self.__delegate('Test', name, val, idx, acInfo)
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 1192, in __delegate
    'create' + subAction, name, None, idx, acInfo
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 1114, in announceManagementEvent
    action, baseIndices, val, idx, acInfo
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 1132, in receiveManagementEvent
    self.__manageColumns(action, (), newSuffix, val, idx, acInfo)
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 1172, in __manageColumns
    getattr(var, action)(name + nameSuffix, val, idx, acInfo)
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 872, in createTest
    self.__createdInstances[name].createTest(name, val, idx, acInfo)
  File "env/lib/python3.7/site-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 779, in createTest
    raise error.WrongValueError(idx=idx, name=name, msg=sys.exc_info()[1])
pysnmp.smi.error.WrongValueError: WrongValueError({'idx': 0, 'name': (1, 3, 6, 1, 2, 1, 31, 1, 3, 1, 1, 1), 'msg': WrongValueError()})

Any idea what I should be doing differently from 4.3.3? Thanks.

etingof commented 4 years ago

I think the root of the problem is here:

pyasn1.error.PyAsn1Error: Attempted "__ne__" operation on ASN.1 schema object

I have two suggestions to play with:

mjrauhal commented 4 years ago

ifindex is type <class 'int'> and its value is 1. Same result if I fill in all the ifEntry columns (or even all the ifXEntry columns as well) at once.

DaraChang commented 4 years ago

@mjrauhal I have faced the same problem as you did while trying to writeVars() to object ifEntry. Have you figured out any solution to this error?

peci1 commented 3 months ago

This can be worked around by

del ifEntry.augmentingRows[("IF-MIB", "ifTestEntry")]