Ejemplo n.º 1
0
    def test_bulktable(self, mck_transport):
        responses = readbytes_multiple('bulktable_response.hex')
        mck_transport().send.side_effect = responses

        request_ids = [1, 2, 3, 4, 5]
        mck_transport().get_request_id.side_effect = request_ids

        result = list(bulktable('127.0.0.1', 'private', '1.3.6.1.2.1.2.2'))

        expected = [{
            '0': '1',
            '1': Integer(1),
            '2': OctetString(b'lo'),
            '3': Integer(24),
            '4': Integer(65536),
            '5': Gauge(10000000),
            '6': OctetString(b''),
            '7': Integer(1),
            '8': Integer(1),
            '9': TimeTicks(0),
            '10': Counter(172),
            '11': Counter(2),
            '12': Counter(0),
            '13': Counter(0),
            '14': Counter(0),
            '15': Counter(0),
            '16': Counter(172),
            '17': Counter(2),
            '18': Counter(0),
            '19': Counter(0),
            '20': Counter(0),
            '21': Gauge(0),
            '22': ObjectIdentifier(0, 0),
        }, {
            '0': '4',
            '1': Integer(4),
            '2': OctetString(b'eth0'),
            '3': Integer(6),
            '4': Integer(1500),
            '5': Gauge(4294967295),
            '6': OctetString(b'\x02B\xac\x11\x00\x02'),
            '7': Integer(1),
            '8': Integer(1),
            '9': TimeTicks(0),
            '10': Counter(548760),
            '11': Counter(3888),
            '12': Counter(0),
            '13': Counter(0),
            '14': Counter(0),
            '15': Counter(0),
            '16': Counter(186660),
            '17': Counter(1875),
            '18': Counter(0),
            '19': Counter(0),
            '20': Counter(0),
            '21': Gauge(0),
            '22': ObjectIdentifier(0, 0),
        }]
        self.assertEqual(sorted(result, key=lambda x: x['0']), expected)
Ejemplo n.º 2
0
    def test_walk(self):
        response_1 = readbytes('walk_response_1.hex')
        response_2 = readbytes('walk_response_2.hex')
        response_3 = readbytes('walk_response_3.hex')

        expected = [
            VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.5.1'),
                    Gauge(10000000)),
            VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.5.13'),
                    Gauge(4294967295))
        ]

        with patch('puresnmp.api.raw.send') as mck:
            mck.side_effect = [response_1, response_2, response_3]
            result = list(walk('::1', 'public', '1.3.6.1.2.1.2.2.1.5'))
        self.assertEqual(result, expected)
Ejemplo n.º 3
0
    async def test_walk(self):
        response_1 = readbytes('walk_response_1.hex')
        response_2 = readbytes('walk_response_2.hex')
        response_3 = readbytes('walk_response_3.hex')

        expected = [
            VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.5.1'),
                    Gauge(10000000)),
            VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.5.13'),
                    Gauge(4294967295))
        ]

        with patch('puresnmp.aio.api.raw.send', new_callable=AsyncMock) as mck:
            mck.side_effect = [response_1, response_2, response_3]
            result = []
            async for x in walk('::1', 'public', '1.3.6.1.2.1.2.2.1.5'):
                result.append(x)
        assert result == expected
Ejemplo n.º 4
0
    async def test_walk(self):
        response_1 = readbytes('walk_response_1.hex')
        response_2 = readbytes('walk_response_2.hex')
        response_3 = readbytes('walk_response_3.hex')

        expected = [
            VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.5.1'),
                    Gauge(10000000)),
            VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.5.13'),
                    Gauge(4294967295))
        ]

        with patch('puresnmp.aio.api.raw.Transport') as mck:
            mck().send = AsyncMock()
            mck().send.side_effect = [response_1, response_2, response_3]
            mck().get_request_id.return_value = 0
            result = []
            async for x in walk('::1', 'public', '1.3.6.1.2.1.2.2.1.5'):
                result.append(x)
        assert result == expected
Ejemplo n.º 5
0
    def test_walk(self):
        expected = [
            VarBind('1.3.6.1.2.1.2.2.1.5.1', 10000000),
            VarBind('1.3.6.1.2.1.2.2.1.5.13', 4294967295)
        ]

        with patch('puresnmp.api.pythonic.raw') as mck:
            mck.walk.return_value = [
                VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.5.1'),
                        Gauge(10000000)),
                VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.5.13'),
                        Integer(4294967295))
            ]
            result = list(walk('::1', 'public', '1.3.6.1.2.1.2.2.1.5'))
        self.assertEqual(result, expected)
Ejemplo n.º 6
0
    async def test_walk(self):
        expected = [
            VarBind('1.3.6.1.2.1.2.2.1.5.1', 10000000),
            VarBind('1.3.6.1.2.1.2.2.1.5.13', 4294967295)
        ]

        with patch('puresnmp.aio.api.pythonic.raw',
                   new_callable=AsyncGenMock) as mck:
            mck.walk.return_value = [
                VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.5.1'),
                        Gauge(10000000)),
                VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.5.13'),
                        Integer(4294967295))
            ]
            result = []
            async for x in walk('::1', 'public', '1.3.6.1.2.1.2.2.1.5'):
                result.append(x)
        assert result == expected
Ejemplo n.º 7
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
Ejemplo n.º 8
0
    def test_bulkwalk(self, mck_rid, mck_send):
        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'),
        ]
        mck_send.side_effect = responses

        request_ids = [1001613222, 1001613223, 1001613224]
        mck_rid.side_effect = request_ids

        result = list(
            bulkwalk('127.0.0.1', 'private', ['1.3.6.1.2.1.2.2'],
                     bulk_size=20))

        self.assertEqual(mck_send.mock_calls, [
            call('127.0.0.1', 161, req1, timeout=2),
            call('127.0.0.1', 161, req2, timeout=2),
            call('127.0.0.1', 161, req3, timeout=2),
        ])

        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))
        ]
        self.assertEqual(result, expected)
Ejemplo n.º 9
0
    async def test_bulktable(self):
        responses = readbytes_multiple('bulktable_response.hex')

        expected = [{
            '0': '1',
            '1': Integer(1),
            '2': OctetString(b'lo'),
            '3': Integer(24),
            '4': Integer(65536),
            '5': Gauge(10000000),
            '6': OctetString(b''),
            '7': Integer(1),
            '8': Integer(1),
            '9': TimeTicks(0),
            '10': Counter(172),
            '11': Counter(2),
            '12': Counter(0),
            '13': Counter(0),
            '14': Counter(0),
            '15': Counter(0),
            '16': Counter(172),
            '17': Counter(2),
            '18': Counter(0),
            '19': Counter(0),
            '20': Counter(0),
            '21': Gauge(0),
            '22': ObjectIdentifier(0, 0),
        }, {
            '0': '4',
            '1': Integer(4),
            '2': OctetString(b'eth0'),
            '3': Integer(6),
            '4': Integer(1500),
            '5': Gauge(4294967295),
            '6': OctetString(b'\x02B\xac\x11\x00\x02'),
            '7': Integer(1),
            '8': Integer(1),
            '9': TimeTicks(0),
            '10': Counter(548760),
            '11': Counter(3888),
            '12': Counter(0),
            '13': Counter(0),
            '14': Counter(0),
            '15': Counter(0),
            '16': Counter(186660),
            '17': Counter(1875),
            '18': Counter(0),
            '19': Counter(0),
            '20': Counter(0),
            '21': Gauge(0),
            '22': ObjectIdentifier(0, 0),
        }]

        with patch('puresnmp.aio.api.raw.Transport') as mck:
            mck().send = AsyncMock()
            mck().send.side_effect = responses
            mck().get_request_id.return_value = 0
            result = []
            table = await bulktable('127.0.0.1', 'private', '1.3.6.1.2.1.2.2')
            for row in table:
                result.append(row)
        assert sorted(result, key=lambda x: x['0']) == expected