예제 #1
0
    def test_multiwalk_non_containment(self):
        '''
        Running a multiwalk should raise an exception if the agent returns OIDs
        which are not properly increasing.
        '''
        from puresnmp.pdu import GetResponse
        OID = ObjectIdentifier.from_string

        # First case: Returned OIDs are the same
        response = Sequence(
            Integer(1), OctetString(b'public'),
            GetResponse(123, [
                VarBind(oid=OID('1.2.3'), value=Integer(30)),
                VarBind(oid=OID('2.3.4'), value=Integer(40)),
            ]))
        with patch('puresnmp.api.raw.Transport') as mck:
            mck().send.side_effect = [to_bytes(response)]
            mck().get_request_id.return_value = 0
            with self.assertRaises(FaultySNMPImplementation):
                list(multiwalk('::1', 'public', [
                    '1.2.3',
                    '2.3.4',
                ]))

        # Second case: Returned OIDs are smaller
        response = Sequence(
            Integer(1), OctetString(b'public'),
            GetResponse(123, [
                VarBind(oid=OID('1.2.2'), value=Integer(30)),
                VarBind(oid=OID('2.3.3'), value=Integer(40)),
            ]))
        with patch('puresnmp.api.raw.Transport') as mck:
            mck().send.side_effect = [to_bytes(response)]
            mck().get_request_id.return_value = 0
            with self.assertRaises(FaultySNMPImplementation):
                list(multiwalk('::1', 'public', [
                    '1.2.3',
                    '2.3.4',
                ]))
예제 #2
0
    def test_multi_walk(self):
        response_1 = readbytes('multiwalk_response_1.hex')
        response_2 = readbytes('multiwalk_response_2.hex')
        response_3 = readbytes('multiwalk_response_3.hex')

        expected = [
            VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.1.1'),
                    Integer(1)),
            VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.2.1'),
                    OctetString(b'lo')),
            VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.1.78'),
                    Integer(78)),
            VarBind(ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.2.78'),
                    OctetString(b'eth0'))
        ]

        with patch('puresnmp.api.raw.send') as mck:
            mck.side_effect = [response_1, response_2, response_3]
            result = list(
                multiwalk('::1', 'public',
                          ['1.3.6.1.2.1.2.2.1.1', '1.3.6.1.2.1.2.2.1.2']))
        self.assertEqual(result, expected)
예제 #3
0
    def test_eom(self):
        '''
        A test for a walk operation which runs into the endOfMibView marker
        '''

        data_generator = readbytes_multiple('x690/multiwalk_endofmibview.hex')

        with patch('puresnmp.api.raw.Transport') as mck:
            mck().send.side_effect = data_generator
            mck().get_request_id.return_value = 0
            result = multiwalk(u'::1', u'public', [
                u'1.3.6.1.6.3.16.1.5.2.1.6.6.95.110.111.110.101.95.1',
            ])
            result = list(result)

        OID = ObjectIdentifier.from_string
        root = '1.3.6.1.6.3.16.1.5.2.1.6.6.95.110.111.110.101.95.1.'
        expected = [
            VarBind(OID(root + '0'), Integer(1)),
            VarBind(OID(root + '1'), Integer(1)),
            VarBind(OID(root + '2'), Integer(1)),
        ]

        self.assertEqual(result, expected)