Compare commits
1 Commits
master
...
add-hlapi-
Author | SHA1 | Date |
---|---|---|
Ilya Etingof | 7afa36942e |
|
@ -47,8 +47,13 @@ matrix:
|
|||
# sudo: false
|
||||
# python: 'pypy3'
|
||||
install:
|
||||
- pip install codecov
|
||||
- pip install -r requirements.txt -r devel-requirements.txt
|
||||
- pip install -e .
|
||||
- pip install pysnmp-mibs
|
||||
script:
|
||||
- PYTHONPATH=.:$PYTHONPATH python tests/__main__.py
|
||||
- travis_wait 20 sh runtests.sh
|
||||
after_success:
|
||||
- PYTHONPATH=.:$PYTHONPATH coverage run --omit=*test* tests/__main__.py
|
||||
- codecov
|
||||
|
|
|
@ -8,3 +8,4 @@ twisted < 17.9; python_version == '3.1'
|
|||
twisted < 17.9; python_version == '3.2'
|
||||
twisted <= 17.9; python_version == '3.3'
|
||||
twisted; python_version >= '3.4'
|
||||
mock; python_version < '3.3'
|
||||
|
|
32
setup.py
32
setup.py
|
@ -8,6 +8,11 @@
|
|||
import sys
|
||||
import os
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
classifiers = """\
|
||||
Development Status :: 5 - Production/Stable
|
||||
Environment :: Console
|
||||
|
@ -62,7 +67,7 @@ if py_version < (2, 7):
|
|||
requires.append('ordereddict')
|
||||
|
||||
try:
|
||||
from setuptools import setup
|
||||
from setuptools import setup, Command
|
||||
|
||||
params = {
|
||||
'install_requires': requires,
|
||||
|
@ -75,7 +80,7 @@ except ImportError:
|
|||
howto_install_setuptools()
|
||||
sys.exit(1)
|
||||
|
||||
from distutils.core import setup
|
||||
from distutils.core import setup, Command
|
||||
|
||||
params = {}
|
||||
if py_version > (2, 4):
|
||||
|
@ -133,4 +138,27 @@ params.update({
|
|||
'pysnmp.proto.api']
|
||||
})
|
||||
|
||||
# handle unittest discovery feature
|
||||
|
||||
class PyTest(Command):
|
||||
user_options = []
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
suite = unittest.TestLoader().loadTestsFromNames(
|
||||
['tests.__main__.suite']
|
||||
)
|
||||
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
||||
params['cmdclass'] = {
|
||||
'test': PyTest,
|
||||
'tests': PyTest,
|
||||
}
|
||||
|
||||
setup(**params)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
# This file is necessary to make this directory a package.
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# This file is part of pysnmp software.
|
||||
#
|
||||
# Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
|
||||
# License: http://snmplabs.com/pysnmp/license.html
|
||||
#
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromNames(
|
||||
['tests.test_debug.suite',
|
||||
'tests.hlapi.test_auth.suite',
|
||||
'tests.hlapi.test_context.suite',
|
||||
'tests.hlapi.test_varbinds.suite',
|
||||
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# This file is part of pysnmp software.
|
||||
#
|
||||
# Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
|
||||
# License: http://snmplabs.com/pysnmp/license.html
|
||||
#
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
from pyasn1 import debug
|
||||
|
||||
|
||||
class BaseTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
debug.setLogger(debug.Debug('all', printer=lambda *x: None))
|
||||
|
||||
def tearDown(self):
|
||||
debug.setLogger(None)
|
|
@ -0,0 +1 @@
|
|||
# This file is necessary to make this directory a package.
|
|
@ -0,0 +1,22 @@
|
|||
#
|
||||
# This file is part of pysnmp software.
|
||||
#
|
||||
# Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
|
||||
# License: http://snmplabs.com/pysnmp/license.html
|
||||
#
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromNames(
|
||||
['tests.hlapi.test_auth.suite',
|
||||
'tests.hlapi.test_context.suite',
|
||||
'tests.hlapi.test_lcd.suite',
|
||||
'tests.hlapi.test_varbinds.suite']
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
|
@ -0,0 +1,143 @@
|
|||
#
|
||||
# This file is part of pysnmp software.
|
||||
#
|
||||
# Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
|
||||
# License: http://snmplabs.com/pysnmp/license.html
|
||||
#
|
||||
import sys
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
from tests.base import BaseTestCase
|
||||
|
||||
from pysnmp import hlapi
|
||||
from pysnmp import debug
|
||||
from pysnmp import error
|
||||
|
||||
|
||||
class ProtocolConstantsTestCase(BaseTestCase):
|
||||
def testEnsureProtocols(self):
|
||||
self.assertTrue(hasattr(hlapi, 'usm3DESEDEPrivProtocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usm3DESEDEPrivProtocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmAesCfb128Protocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmAesCfb192Protocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmAesCfb256Protocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmAesBlumenthalCfb192Protocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmAesBlumenthalCfb256Protocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmDESPrivProtocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmHMACMD5AuthProtocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmHMACSHAAuthProtocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmHMAC128SHA224AuthProtocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmHMAC192SHA256AuthProtocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmHMAC256SHA384AuthProtocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmHMAC384SHA512AuthProtocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmNoAuthProtocol'))
|
||||
self.assertTrue(hasattr(hlapi, 'usmNoPrivProtocol'))
|
||||
|
||||
|
||||
class CommunityDataTestCase(BaseTestCase):
|
||||
def testVersionOne(self):
|
||||
auth = hlapi.CommunityData(
|
||||
'public', mpModel=0, contextEngineId='0123456789', contextName='abc', tag='x'
|
||||
)
|
||||
self.assertTrue(auth.communityIndex)
|
||||
self.assertEqual(auth.communityName, 'public')
|
||||
self.assertEqual(auth.contextEngineId, '0123456789')
|
||||
self.assertEqual(auth.contextName, 'abc')
|
||||
self.assertEqual(auth.mpModel, 0)
|
||||
self.assertEqual(auth.securityLevel, 'noAuthNoPriv')
|
||||
self.assertEqual(auth.securityModel, 1)
|
||||
self.assertTrue(auth.securityName)
|
||||
self.assertEqual(auth.tag, 'x')
|
||||
|
||||
def testVersionTwoC(self):
|
||||
auth = hlapi.CommunityData(
|
||||
'public', contextEngineId='0123456789', contextName='abc', tag='x'
|
||||
)
|
||||
self.assertTrue(auth.communityIndex)
|
||||
self.assertEqual(auth.communityName, 'public')
|
||||
self.assertEqual(auth.contextEngineId, '0123456789')
|
||||
self.assertEqual(auth.contextName, 'abc')
|
||||
self.assertEqual(auth.mpModel, 1)
|
||||
self.assertEqual(auth.securityLevel, 'noAuthNoPriv')
|
||||
self.assertEqual(auth.securityModel, 2)
|
||||
self.assertTrue(auth.securityName)
|
||||
self.assertEqual(auth.tag, 'x')
|
||||
|
||||
def testClone(self):
|
||||
auth = hlapi.CommunityData('public').clone('private')
|
||||
self.assertTrue(auth.communityIndex)
|
||||
self.assertEqual(auth.communityName, 'private')
|
||||
self.assertEqual(auth.contextEngineId, None)
|
||||
self.assertEqual(auth.contextName, hlapi.OctetString(''))
|
||||
self.assertEqual(auth.mpModel, 1)
|
||||
self.assertEqual(auth.securityLevel, 'noAuthNoPriv')
|
||||
self.assertEqual(auth.securityModel, 2)
|
||||
self.assertTrue(auth.securityName)
|
||||
self.assertEqual(auth.tag, hlapi.OctetString(''))
|
||||
|
||||
|
||||
class UsmUserDataTestCase(BaseTestCase):
|
||||
def testAuthPrivDefaults(self):
|
||||
auth = hlapi.UsmUserData('testuser', 'authkey1', 'privkey1')
|
||||
self.assertEqual(auth.authKey, 'authkey1')
|
||||
self.assertEqual(auth.authProtocol, (1, 3, 6, 1, 6, 3, 10, 1, 1, 2))
|
||||
self.assertEqual(auth.mpModel, 3)
|
||||
self.assertEqual(auth.privKey, 'privkey1')
|
||||
self.assertEqual(auth.privProtocol, (1, 3, 6, 1, 6, 3, 10, 1, 2, 2))
|
||||
self.assertFalse(auth.securityEngineId)
|
||||
self.assertEqual(auth.securityLevel, 'authPriv')
|
||||
self.assertEqual(auth.securityModel, 3)
|
||||
self.assertEqual(auth.securityName, 'testuser')
|
||||
self.assertEqual(auth.userName, 'testuser')
|
||||
|
||||
def testAuthNoPrivDefaults(self):
|
||||
auth = hlapi.UsmUserData('testuser', 'authkey1')
|
||||
self.assertEqual(auth.authKey, 'authkey1')
|
||||
self.assertEqual(auth.authProtocol, (1, 3, 6, 1, 6, 3, 10, 1, 1, 2))
|
||||
self.assertEqual(auth.mpModel, 3)
|
||||
self.assertFalse(auth.privKey)
|
||||
self.assertEqual(auth.privProtocol, (1, 3, 6, 1, 6, 3, 10, 1, 2, 1))
|
||||
self.assertFalse(auth.securityEngineId)
|
||||
self.assertEqual(auth.securityLevel, 'authNoPriv')
|
||||
self.assertEqual(auth.securityModel, 3)
|
||||
self.assertEqual(auth.securityName, 'testuser')
|
||||
self.assertEqual(auth.userName, 'testuser')
|
||||
|
||||
def testNoAuthNoPrivDefaults(self):
|
||||
auth = hlapi.UsmUserData('testuser')
|
||||
self.assertFalse(auth.authKey)
|
||||
self.assertEqual(auth.authProtocol, (1, 3, 6, 1, 6, 3, 10, 1, 1, 1))
|
||||
self.assertEqual(auth.mpModel, 3)
|
||||
self.assertFalse(auth.privKey)
|
||||
self.assertEqual(auth.privProtocol, (1, 3, 6, 1, 6, 3, 10, 1, 2, 1))
|
||||
self.assertFalse(auth.securityEngineId)
|
||||
self.assertEqual(auth.securityLevel, 'noAuthNoPriv')
|
||||
self.assertEqual(auth.securityModel, 3)
|
||||
self.assertEqual(auth.securityName, 'testuser')
|
||||
self.assertEqual(auth.userName, 'testuser')
|
||||
|
||||
def testAuthPriv(self):
|
||||
auth = hlapi.UsmUserData('testuser', 'authkey1', 'privkey1',
|
||||
authProtocol=hlapi.usmHMACSHAAuthProtocol,
|
||||
privProtocol=hlapi.usmAesCfb256Protocol)
|
||||
self.assertEqual(auth.authKey, 'authkey1')
|
||||
self.assertEqual(auth.authProtocol, (1, 3, 6, 1, 6, 3, 10, 1, 1, 3))
|
||||
self.assertEqual(auth.mpModel, 3)
|
||||
self.assertEqual(auth.privKey, 'privkey1')
|
||||
self.assertEqual(auth.privProtocol, (1, 3, 6, 1, 4, 1, 9, 12, 6, 1, 102))
|
||||
self.assertFalse(auth.securityEngineId)
|
||||
self.assertEqual(auth.securityLevel, 'authPriv')
|
||||
self.assertEqual(auth.securityModel, 3)
|
||||
self.assertEqual(auth.securityName, 'testuser')
|
||||
self.assertEqual(auth.userName, 'testuser')
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
|
@ -0,0 +1,42 @@
|
|||
#
|
||||
# This file is part of pysnmp software.
|
||||
#
|
||||
# Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
|
||||
# License: http://snmplabs.com/pysnmp/license.html
|
||||
#
|
||||
import sys
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
from tests.base import BaseTestCase
|
||||
|
||||
from pysnmp import hlapi
|
||||
from pysnmp import debug
|
||||
from pysnmp import error
|
||||
|
||||
|
||||
class ContextDataTestCase(BaseTestCase):
|
||||
def testDefaults(self):
|
||||
context = hlapi.ContextData()
|
||||
self.assertFalse(context.contextEngineId)
|
||||
self.assertFalse(context.contextName)
|
||||
|
||||
def testContextEngineId(self):
|
||||
context = hlapi.ContextData(hlapi.OctetString('abc'))
|
||||
self.assertEqual(context.contextEngineId, hlapi.OctetString('abc'))
|
||||
self.assertFalse(context.contextName)
|
||||
|
||||
def testContextName(self):
|
||||
context = hlapi.ContextData(contextName=hlapi.OctetString('abc'))
|
||||
self.assertFalse(context.contextEngineId)
|
||||
self.assertEqual(context.contextName, hlapi.OctetString('abc'))
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
|
@ -0,0 +1,135 @@
|
|||
#
|
||||
# This file is part of pysnmp software.
|
||||
#
|
||||
# Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
|
||||
# License: http://snmplabs.com/pysnmp/license.html
|
||||
#
|
||||
import sys
|
||||
|
||||
try:
|
||||
from unittest import mock
|
||||
|
||||
except ImportError:
|
||||
try:
|
||||
import mock
|
||||
|
||||
except ImportError:
|
||||
mock = None
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
from tests.base import BaseTestCase
|
||||
|
||||
from pysnmp import hlapi
|
||||
from pysnmp.hlapi import lcd
|
||||
from pysnmp import debug
|
||||
from pysnmp import error
|
||||
|
||||
if mock:
|
||||
|
||||
@mock.patch('pysnmp.entity.config.addV1System', autospec=True)
|
||||
@mock.patch('pysnmp.entity.config.addV3User', autospec=True)
|
||||
@mock.patch('pysnmp.entity.config.addTargetParams', autospec=True)
|
||||
@mock.patch('pysnmp.entity.config.addTransport', autospec=True)
|
||||
@mock.patch('pysnmp.entity.config.addTargetAddr', autospec=True)
|
||||
class ConfigureCommandGeneratorTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
self.snmpEngine = hlapi.SnmpEngine()
|
||||
self.communityData = hlapi.CommunityData('public')
|
||||
self.usmUserData = hlapi.UsmUserData('testuser', 'authkey1', 'privkey1')
|
||||
self.transportTarget = hlapi.UdpTransportTarget(('127.0.0.1', 161))
|
||||
|
||||
def testCommunityData(self, mock_address, mock_transport, mock_target,
|
||||
mock_v3user, mock_v1system):
|
||||
|
||||
cfg = lcd.CommandGeneratorLcdConfigurator()
|
||||
addrName, paramsName = cfg.configure(self.snmpEngine, self.communityData,
|
||||
self.transportTarget)
|
||||
|
||||
self.assertTrue(addrName)
|
||||
self.assertTrue(paramsName)
|
||||
mock_v1system.assert_called_once_with(
|
||||
self.snmpEngine,
|
||||
mock.ANY,
|
||||
'public',
|
||||
None,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY
|
||||
)
|
||||
mock_v3user.assert_not_called()
|
||||
mock_target.assert_called_once_with(
|
||||
self.snmpEngine,
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
'noAuthNoPriv',
|
||||
1
|
||||
)
|
||||
mock_transport.assert_called_once_with(
|
||||
self.snmpEngine,
|
||||
(1, 3, 6, 1, 6, 1, 1),
|
||||
mock.ANY
|
||||
)
|
||||
mock_address.assert_called_once_with(
|
||||
self.snmpEngine,
|
||||
mock.ANY,
|
||||
(1, 3, 6, 1, 6, 1, 1), ('127.0.0.1', 161),
|
||||
mock.ANY,
|
||||
100, 5,
|
||||
mock.ANY
|
||||
)
|
||||
|
||||
def testUsmUserData(self, mock_address, mock_transport, mock_target,
|
||||
mock_v3user, mock_v1system):
|
||||
|
||||
cfg = lcd.CommandGeneratorLcdConfigurator()
|
||||
addrName, paramsName = cfg.configure(self.snmpEngine, self.usmUserData,
|
||||
self.transportTarget)
|
||||
|
||||
self.assertTrue(addrName)
|
||||
self.assertTrue(paramsName)
|
||||
mock_v1system.assert_not_called()
|
||||
mock_v3user.assert_called_once_with(
|
||||
self.snmpEngine,
|
||||
'testuser',
|
||||
(1, 3, 6, 1, 6, 3, 10, 1, 1, 2),
|
||||
'authkey1',
|
||||
(1, 3, 6, 1, 6, 3, 10, 1, 2, 2),
|
||||
'privkey1',
|
||||
None,
|
||||
securityName='testuser'
|
||||
)
|
||||
mock_target.assert_called_once_with(
|
||||
self.snmpEngine,
|
||||
mock.ANY,
|
||||
'testuser',
|
||||
'authPriv',
|
||||
3
|
||||
)
|
||||
mock_transport.assert_called_once_with(
|
||||
self.snmpEngine,
|
||||
(1, 3, 6, 1, 6, 1, 1),
|
||||
mock.ANY
|
||||
)
|
||||
mock_address.assert_called_once_with(
|
||||
self.snmpEngine,
|
||||
mock.ANY,
|
||||
(1, 3, 6, 1, 6, 1, 1), ('127.0.0.1', 161),
|
||||
mock.ANY,
|
||||
100, 5,
|
||||
mock.ANY
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
|
@ -0,0 +1,131 @@
|
|||
#
|
||||
# This file is part of pysnmp software.
|
||||
#
|
||||
# Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
|
||||
# License: http://snmplabs.com/pysnmp/license.html
|
||||
#
|
||||
import sys
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
from tests.base import BaseTestCase
|
||||
|
||||
from pysnmp import hlapi
|
||||
from pysnmp.hlapi import varbinds
|
||||
from pysnmp import debug
|
||||
from pysnmp import error
|
||||
|
||||
|
||||
class CommandGeneratorVarBindsTestCase(BaseTestCase):
|
||||
def testResolveFromObjectType(self):
|
||||
cg = varbinds.CommandGeneratorVarBinds()
|
||||
vb = cg.makeVarBinds(
|
||||
hlapi.SnmpEngine(),
|
||||
[hlapi.ObjectType(hlapi.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
|
||||
hlapi.ObjectType(hlapi.ObjectIdentity('SNMPv2-MIB', 'sysUpTime', 0))]
|
||||
)
|
||||
self.assertEqual(tuple(vb[0][0]), (1, 3, 6, 1, 2, 1, 1, 1, 0))
|
||||
self.assertEqual(tuple(vb[1][0]), (1, 3, 6, 1, 2, 1, 1, 3, 0))
|
||||
self.assertFalse(vb[0][1])
|
||||
self.assertFalse(vb[1][1])
|
||||
|
||||
def testResolveFromObjectIdentity(self):
|
||||
cg = varbinds.CommandGeneratorVarBinds()
|
||||
vb = cg.makeVarBinds(
|
||||
hlapi.SnmpEngine(),
|
||||
[(hlapi.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0), 'abc'),
|
||||
(hlapi.ObjectIdentity('SNMPv2-MIB', 'sysUpTime', 0), 123)]
|
||||
)
|
||||
self.assertEqual(tuple(vb[0][0]), (1, 3, 6, 1, 2, 1, 1, 1, 0))
|
||||
self.assertEqual(tuple(vb[1][0]), (1, 3, 6, 1, 2, 1, 1, 3, 0))
|
||||
self.assertEqual(str(vb[0]), 'SNMPv2-MIB::sysDescr.0 = abc')
|
||||
self.assertEqual(str(vb[1]), 'SNMPv2-MIB::sysUpTime.0 = 123')
|
||||
self.assertEqual(vb[0][1], hlapi.OctetString('abc'))
|
||||
self.assertEqual(vb[1][1], 123)
|
||||
|
||||
def testUnresolveWithMibLookup(self):
|
||||
cg = varbinds.CommandGeneratorVarBinds()
|
||||
vb = cg.unmakeVarBinds(
|
||||
hlapi.SnmpEngine(),
|
||||
[(hlapi.ObjectIdentifier((1, 3, 6, 1, 2, 1, 1, 1, 0)), hlapi.OctetString('abc')),
|
||||
(hlapi.ObjectIdentifier((1, 3, 6, 1, 2, 1, 1, 3, 0)), hlapi.Integer(123))]
|
||||
)
|
||||
self.assertEqual(str(vb[0]), 'SNMPv2-MIB::sysDescr.0 = abc')
|
||||
self.assertEqual(str(vb[1]), 'SNMPv2-MIB::sysUpTime.0 = 123')
|
||||
self.assertEqual(vb[0][1], hlapi.OctetString('abc'))
|
||||
self.assertEqual(vb[1][1], 123)
|
||||
|
||||
def testUnresolveWithoutMibLookup(self):
|
||||
cg = varbinds.CommandGeneratorVarBinds()
|
||||
vb = cg.unmakeVarBinds(
|
||||
hlapi.SnmpEngine(),
|
||||
[(hlapi.ObjectIdentifier((1, 3, 6, 1, 2, 1, 1, 1, 0)), hlapi.OctetString('abc')),
|
||||
(hlapi.ObjectIdentifier((1, 3, 6, 1, 2, 1, 1, 3, 0)), hlapi.Integer(123))],
|
||||
lookupMib=False
|
||||
)
|
||||
self.assertEqual(str(vb[0][0]), '1.3.6.1.2.1.1.1.0')
|
||||
self.assertEqual(str(vb[1][0]), '1.3.6.1.2.1.1.3.0')
|
||||
self.assertEqual(vb[0][1], hlapi.OctetString('abc'))
|
||||
self.assertEqual(vb[1][1], 123)
|
||||
|
||||
|
||||
class NotificationOriginatorVarBindsTestCase(BaseTestCase):
|
||||
def testResolveFromNotificationType(self):
|
||||
cg = varbinds.NotificationOriginatorVarBinds()
|
||||
vb = cg.makeVarBinds(
|
||||
hlapi.SnmpEngine(),
|
||||
hlapi.NotificationType(hlapi.ObjectIdentity('SNMPv2-MIB', 'coldStart'))
|
||||
)
|
||||
self.assertEqual(tuple(vb[0][0]), (1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0))
|
||||
self.assertEqual(tuple(vb[0][1]), (1, 3, 6, 1, 6, 3, 1, 1, 5, 1))
|
||||
|
||||
def testResolveFromObjectType(self):
|
||||
cg = varbinds.NotificationOriginatorVarBinds()
|
||||
vb = cg.makeVarBinds(
|
||||
hlapi.SnmpEngine(),
|
||||
[hlapi.ObjectType(hlapi.ObjectIdentity('SNMPv2-MIB', 'snmpTrapOID', 0),
|
||||
'1.3.6.1.6.3.1.1.5.1')]
|
||||
)
|
||||
self.assertEqual(tuple(vb[0][0]), (1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0))
|
||||
self.assertEqual(tuple(vb[0][1]), (1, 3, 6, 1, 6, 3, 1, 1, 5, 1))
|
||||
|
||||
def testResolveFromObjectIdentity(self):
|
||||
cg = varbinds.NotificationOriginatorVarBinds()
|
||||
vb = cg.makeVarBinds(
|
||||
hlapi.SnmpEngine(),
|
||||
[(hlapi.ObjectIdentity('SNMPv2-MIB', 'snmpTrapOID', 0), '1.3.6.1.6.3.1.1.5.1')]
|
||||
)
|
||||
self.assertEqual(tuple(vb[0][0]), (1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0))
|
||||
self.assertEqual(tuple(vb[0][1]), (1, 3, 6, 1, 6, 3, 1, 1, 5, 1))
|
||||
|
||||
def testUnresolveWithMibLookup(self):
|
||||
cg = varbinds.NotificationOriginatorVarBinds()
|
||||
vb = cg.unmakeVarBinds(
|
||||
hlapi.SnmpEngine(),
|
||||
[(hlapi.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0)),
|
||||
hlapi.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1)))]
|
||||
)
|
||||
# TODO(etingof): why not resolve into NotificationType?
|
||||
self.assertEqual(str(vb[0][0]), '1.3.6.1.6.3.1.1.4.1.0')
|
||||
self.assertEqual(str(vb[0][1]), '1.3.6.1.6.3.1.1.5.1')
|
||||
|
||||
def testUnresolveWithoutMibLookup(self):
|
||||
cg = varbinds.NotificationOriginatorVarBinds()
|
||||
vb = cg.unmakeVarBinds(
|
||||
hlapi.SnmpEngine(),
|
||||
[(hlapi.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0)),
|
||||
hlapi.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1)))],
|
||||
lookupMib=False
|
||||
)
|
||||
self.assertEqual(str(vb[0][0]), '1.3.6.1.6.3.1.1.4.1.0')
|
||||
self.assertEqual(str(vb[0][1]), '1.3.6.1.6.3.1.1.5.1')
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
|
@ -0,0 +1,45 @@
|
|||
#
|
||||
# This file is part of pysnmp software.
|
||||
#
|
||||
# Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
|
||||
# License: http://snmplabs.com/pysnmp/license.html
|
||||
#
|
||||
import sys
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
from tests.base import BaseTestCase
|
||||
|
||||
from pysnmp import debug
|
||||
from pysnmp import error
|
||||
|
||||
|
||||
class DebugTestCase(BaseTestCase):
|
||||
def testKnownFlags(self):
|
||||
debug.setLogger(0)
|
||||
debug.setLogger(debug.Debug('all', 'io', 'dsp', 'msgproc', 'secmod',
|
||||
'mibbuild', 'mibinstrum', 'acl', 'proxy', 'app',
|
||||
printer=lambda *v, **kw: v))
|
||||
debug.setLogger(0)
|
||||
|
||||
def testUnknownFlags(self):
|
||||
try:
|
||||
debug.setLogger(debug.Debug('all', 'unknown', loggerName='xxx'))
|
||||
|
||||
except error.PySnmpError:
|
||||
debug.setLogger(0)
|
||||
return
|
||||
|
||||
else:
|
||||
debug.setLogger(0)
|
||||
assert 0, 'unknown debug flag tolerated'
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
Loading…
Reference in New Issue