forked from etingof/pysnmp
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed etingof#270. Added more test cases.
- Loading branch information
Showing
4 changed files
with
139 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
tests/hlapi/asyncio/manager/cmdgen/test_v2c_bulkwalk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import pytest | ||
|
||
from pysnmp.hlapi.asyncio import * | ||
from tests.agent_context import AGENT_PORT, AgentContextManager | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_v2c_get_table_bulk(): | ||
async with AgentContextManager(): | ||
snmpEngine = SnmpEngine() | ||
objects = bulkWalkCmd( | ||
snmpEngine, | ||
CommunityData("public"), | ||
UdpTransportTarget(("localhost", AGENT_PORT)), | ||
ContextData(), | ||
0, | ||
4, | ||
ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), | ||
) | ||
|
||
objects_list = [obj async for obj in objects] | ||
|
||
errorIndication, errorStatus, errorIndex, varBinds = objects_list[0] | ||
|
||
assert errorIndication is None | ||
assert errorStatus == 0 | ||
assert len(varBinds) == 1 | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::sysObjectID.0" | ||
assert varBinds[0][1].prettyPrint() == "PYSNMP-MIB::pysnmp" | ||
# assert isinstance(varBinds[0][1], ObjectIdentifier) | ||
|
||
errorIndication, errorStatus, errorIndex, varBinds = objects_list[1] | ||
|
||
assert errorIndication is None | ||
assert errorStatus == 0 | ||
assert len(varBinds) == 1 | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::sysUpTime.0" | ||
# assert isinstance(varBinds[0][1], TimeTicks) | ||
|
||
assert len(objects_list), 50 | ||
|
||
snmpEngine.closeDispatcher() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_v2c_get_table_bulk_0_4(): | ||
async with AgentContextManager(): | ||
snmpEngine = SnmpEngine() | ||
index = 0 | ||
async for errorIndication, errorStatus, errorIndex, varBinds in bulkWalkCmd( | ||
snmpEngine, | ||
CommunityData("public"), | ||
UdpTransportTarget(("localhost", AGENT_PORT)), | ||
ContextData(), | ||
0, | ||
4, | ||
ObjectType(ObjectIdentity("SNMPv2-MIB", "snmp")), | ||
lexicographicMode=False, | ||
): | ||
assert errorIndication is None | ||
assert errorStatus == 0 | ||
assert len(varBinds) == 1 | ||
if index == 0: | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::snmpInPkts.0" | ||
|
||
if index == 1: | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::snmpOutPkts.0" | ||
|
||
if index == 26: | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::snmpSilentDrops.0" | ||
|
||
if index == 27: | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::snmpProxyDrops.0" | ||
|
||
index += 1 | ||
|
||
assert index == 28 | ||
|
||
snmpEngine.closeDispatcher() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_v2c_get_table_bulk_0_1(): | ||
async with AgentContextManager(): | ||
snmpEngine = SnmpEngine() | ||
index = 0 | ||
async for errorIndication, errorStatus, errorIndex, varBinds in bulkWalkCmd( | ||
snmpEngine, | ||
CommunityData("public"), | ||
UdpTransportTarget(("localhost", AGENT_PORT)), | ||
ContextData(), | ||
0, | ||
1, | ||
ObjectType(ObjectIdentity("SNMPv2-MIB", "snmp")), | ||
lexicographicMode=False, | ||
): | ||
assert errorIndication is None | ||
assert errorStatus == 0 | ||
assert len(varBinds) == 1 | ||
if index == 0: | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::snmpInPkts.0" | ||
|
||
if index == 1: | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::snmpOutPkts.0" | ||
|
||
if index == 26: | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::snmpSilentDrops.0" | ||
|
||
if index == 27: | ||
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::snmpProxyDrops.0" | ||
|
||
index += 1 | ||
|
||
assert index == 28 | ||
|
||
snmpEngine.closeDispatcher() |