Esempio n. 1
0
    async def test_get_call_args_issue_22(self):
        data = readbytes('dummy.hex')  # any dump would do
        packet = Sequence(Integer(Version.V2C), OctetString('public'),
                          BulkGetRequest(0, 0, 2, ObjectIdentifier(1, 2, 3)))
        with patch('puresnmp.aio.api.raw.Transport') as mck:
            mck().send = AsyncMock()
            mck().send.return_value = data
            mck().get_request_id.return_value = 0

            with pytest.raises(TypeError, match=r'OIDS.*list'):
                # we need to wrap this in a list to consume the generator.
                async for x in bulkwalk('::1', 'public', '1.2.3', bulk_size=2):
                    pass
Esempio n. 2
0
    async def test_get_call_args(self):
        data = readbytes('dummy.hex')  # any dump would do
        packet = Sequence(Integer(Version.V2C), OctetString('public'),
                          BulkGetRequest(0, 0, 2, ObjectIdentifier(1, 2, 3)))
        with patch('puresnmp.aio.api.raw.send', new_callable=AsyncMock) as mck, \
                patch('puresnmp.aio.api.raw.get_request_id') as mck2:
            mck2.return_value = 0
            mck.return_value = data

            # we need to wrap this in a list to consume the generator.
            async for x in bulkwalk('::1', 'public', ['1.2.3'], bulk_size=2):
                pass
            mck.assert_called_with('::1', 161, to_bytes(packet), timeout=6)
Esempio n. 3
0
    async def test_bulkwalk(self):
        req1 = readbytes('bulkwalk_request_1.hex')
        req2 = readbytes('bulkwalk_request_2.hex')
        req3 = readbytes('bulkwalk_request_3.hex')

        responses = [
            readbytes('bulkwalk_response_1.hex'),
            readbytes('bulkwalk_response_2.hex'),
            readbytes('bulkwalk_response_3.hex'),
        ]
        with patch('puresnmp.aio.api.raw.Transport') as mck:
            mck().send = AsyncMock()
            mck().send.side_effect = responses

            request_ids = [1001613222, 1001613223, 1001613224]
            mck().get_request_id.side_effect = request_ids

            result = []
            async for x in bulkwalk('127.0.0.1', 'private', ['1.3.6.1.2.1.2.2'],
                                   bulk_size=20):
                result.append(x)

            mck.assert_called_with(timeout=6)
            assert mck().send.mock_calls == [
                call('127.0.0.1', 161, req1),
                call('127.0.0.1', 161, req2),
                call('127.0.0.1', 161, req3),
            ]

            expected = [
                VarBind('1.3.6.1.2.1.2.2.1.1.1', Integer(1)),
                VarBind('1.3.6.1.2.1.2.2.1.1.10', Integer(10)),
                VarBind('1.3.6.1.2.1.2.2.1.2.1', OctetString(b"lo")),
                VarBind('1.3.6.1.2.1.2.2.1.2.10', OctetString(b"eth0")),
                VarBind('1.3.6.1.2.1.2.2.1.3.1', Integer(24)),
                VarBind('1.3.6.1.2.1.2.2.1.3.10', Integer(6)),
                VarBind('1.3.6.1.2.1.2.2.1.4.1', Integer(65536)),
                VarBind('1.3.6.1.2.1.2.2.1.4.10', Integer(1500)),
                VarBind('1.3.6.1.2.1.2.2.1.5.1',  Gauge(10000000)),
                VarBind('1.3.6.1.2.1.2.2.1.5.10',  Gauge(4294967295)),
                VarBind('1.3.6.1.2.1.2.2.1.6.1', OctetString(b"")),
                VarBind('1.3.6.1.2.1.2.2.1.6.10',
                    OctetString(b"\x02\x42\xAC\x11\x00\x02")),
                VarBind('1.3.6.1.2.1.2.2.1.7.1', Integer(1)),
                VarBind('1.3.6.1.2.1.2.2.1.7.10', Integer(1)),
                VarBind('1.3.6.1.2.1.2.2.1.8.1', Integer(1)),
                VarBind('1.3.6.1.2.1.2.2.1.8.10', Integer(1)),
                VarBind('1.3.6.1.2.1.2.2.1.9.1', TimeTicks(0)),
                VarBind('1.3.6.1.2.1.2.2.1.9.10', TimeTicks(0)),
                VarBind('1.3.6.1.2.1.2.2.1.10.1', Counter(172)),
                VarBind('1.3.6.1.2.1.2.2.1.10.10', Counter(60558)),
                VarBind('1.3.6.1.2.1.2.2.1.11.1', Counter(2)),
                VarBind('1.3.6.1.2.1.2.2.1.11.10', Counter(564)),
                VarBind('1.3.6.1.2.1.2.2.1.12.1', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.12.10', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.13.1', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.13.10', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.14.1', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.14.10', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.15.1', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.15.10', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.16.1', Counter(172)),
                VarBind('1.3.6.1.2.1.2.2.1.16.10', Counter(44295)),
                VarBind('1.3.6.1.2.1.2.2.1.17.1', Counter(2)),
                VarBind('1.3.6.1.2.1.2.2.1.17.10', Counter(442)),
                VarBind('1.3.6.1.2.1.2.2.1.18.1', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.18.10', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.19.1', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.19.10', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.20.1', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.20.10', Counter(0)),
                VarBind('1.3.6.1.2.1.2.2.1.21.1',  Gauge(0)),
                VarBind('1.3.6.1.2.1.2.2.1.21.10',  Gauge(0)),
                VarBind('1.3.6.1.2.1.2.2.1.22.1', ObjectIdentifier(0, 0)),
                VarBind('1.3.6.1.2.1.2.2.1.22.10', ObjectIdentifier(0, 0))
            ]
        assert result == expected