File: test_v3-inform.py

package info (click to toggle)
python-pysnmp4 7.1.21-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,564 kB
  • sloc: python: 33,654; makefile: 166; javascript: 4
file content (38 lines) | stat: -rw-r--r-- 1,544 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pytest
from pysnmp.hlapi.v3arch.asyncio import *
from pysnmp.smi import builder, compiler, view
from tests.manager_context import MANAGER_PORT, ManagerContextManager


@pytest.mark.asyncio
async def test_send_v3_inform():
    async with ManagerContextManager():
        with SnmpEngine() as snmpEngine:
            (
                errorIndication,
                errorStatus,
                errorIndex,
                varBinds,
            ) = await send_notification(
                snmpEngine,
                UsmUserData("usr-md5-des", "authkey1", "privkey1"),
                await UdpTransportTarget.create(("localhost", MANAGER_PORT)),
                ContextData(),
                "inform",
                NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2"))
                .load_mibs("SNMPv2-MIB")
                .add_varbinds(("1.3.6.1.2.1.1.1.0", OctetString("my system"))),
            )

            assert errorIndication is None
            assert errorStatus == 0
            assert errorIndex == 0
            assert len(varBinds) == 3
            assert (
                varBinds[0][0].prettyPrint() == "SNMPv2-MIB::sysUpTime.0"
            )  # IMPORTANT: MIB is needed to resolve this name
            assert varBinds[1][0].prettyPrint() == "SNMPv2-MIB::snmpTrapOID.0"
            assert varBinds[2][0].prettyPrint() == "SNMPv2-MIB::sysDescr.0"
            isinstance(varBinds[0][1], TimeTicks)
            isinstance(varBinds[1][1], ObjectIdentifier)
            isinstance(varBinds[2][1], OctetString)