Пример #1
0
 def test_get_call_args(self):
     data = readbytes('dummy.hex')  # any dump would do
     packet = Sequence(
         Integer(Version.V2C), OctetString('public'),
         BulkGetRequest(0, 1, 2, ObjectIdentifier(1, 2, 3),
                        ObjectIdentifier(1, 2, 4)))
     with patch('puresnmp.api.raw.send') as mck, \
             patch('puresnmp.api.raw.get_request_id') as mck2:
         mck2.return_value = 0
         mck.return_value = data
         bulkget('::1', 'public', ['1.2.3'], ['1.2.4'], max_list_size=2)
         mck.assert_called_with('::1', 161, to_bytes(packet), timeout=2)
Пример #2
0
    def test_bulkget(self):
        data = readbytes('bulk_get_response.hex')
        expected = BulkResult(
            {
                '1.3.6.1.2.1.1.1.0':
                OctetString(
                    b'Linux 7e68e60fe303 4.4.0-28-generic '
                    b'#47-Ubuntu SMP Fri Jun 24 10:09:13 UTC 2016 x86_64')
            }, {
                '1.3.6.1.2.1.3.1.1.1.10.1.172.17.0.1':
                Integer(10),
                '1.3.6.1.2.1.3.1.1.2.10.1.172.17.0.1':
                OctetString(b'\x02B\xe2\xc5\x8d\t'),
                '1.3.6.1.2.1.3.1.1.3.10.1.172.17.0.1':
                IpAddress(b'\xac\x11\x00\x01'),
                '1.3.6.1.2.1.4.1.0':
                Integer(1),
                '1.3.6.1.2.1.4.3.0':
                Counter(57)
            })

        with patch('puresnmp.api.raw.send') as mck:
            mck.return_value = data
            result = bulkget('::1',
                             'public', ['1.3.6.1.2.1.1.1'],
                             ['1.3.6.1.2.1.3.1'],
                             max_list_size=5)
        self.assertEqual(result, expected)
Пример #3
0
def test_54_endofmibview():
    data = readbytes('gh-issues/54-endofmibview.hex')
    with patch('puresnmp.api.raw.Transport') as ptch:
        ptch().send.return_value = data
        ptch().get_request_id.return_value = 123
        result = bulkget('192.0.2.1',
                         'private', [], ['1.2.3'],
                         max_list_size=10)
    assert result.scalars == {}

    expected_lists = {
        '1.3.6.1.4.1.12325.1.303.1.9.1.3.1.0': OctetString(b'\x00' * 404),
        '1.3.6.1.4.1.12325.1.303.1.9.1.3.2.0': OctetString(b'\x00' * 404),
        '1.3.6.1.6.3.1.1.6.1.0': Integer(1103779487),
        '1.3.6.1.6.3.10.2.1.1.0':
        OctetString(b'\x80\x00\x08\xbe\x803740773355'),
        '1.3.6.1.6.3.10.2.1.2.0': Integer(1),
        '1.3.6.1.6.3.10.2.1.3.0': Integer(632),
        '1.3.6.1.6.3.10.2.1.4.0': Integer(1500),
    }
    assert result.listing == expected_lists
Пример #4
0
    def test_eom(self):
        '''
        Test a bulg-get operation which runs into the "endOfMibView" marker.
        '''

        data = readbytes('x690/bulk_get_eom_response.hex')
        with patch('puresnmp.api.raw.Transport') as mck:
            mck().send.return_value = data
            mck().get_request_id.return_value = 0
            result = bulkget('::1', 'public', [], ['1.2.4'], max_list_size=10)

        expected_scalars = {}
        self.assertEqual(result.scalars, expected_scalars)

        root = '1.3.6.1.6.3.16.1.5.2.1.6.6.95.110.111.110.101.95.1.'
        expected_listing = {
            root + '0': Integer(1),
            root + '1': Integer(1),
            root + '2': Integer(1),
        }

        self.assertEqual(result.listing, expected_listing)