From 2cda272a04954e32a7a1e6bc49a7314ea24bc2a3 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Mon, 23 Sep 2019 10:43:43 -0700 Subject: [PATCH] add test case for when the server returns tooBig.. make sure we subdivide the query into smaller chunks.. perfect example of how the pysnmp hlapi isn't that high level... --- vlanmang.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/vlanmang.py b/vlanmang.py index 23a5626..9d37474 100644 --- a/vlanmang.py +++ b/vlanmang.py @@ -555,6 +555,32 @@ class _TestSNMPSwitch(unittest.TestCase): # and call _getmany w/ the correct arg gm.assert_called_with(arg) + @mock.patch('pysnmp.hlapi.ContextData') + @mock.patch('vlanmang.getCmd') + def test_getmany(self, gc, cd): + # that a switch + switch = SNMPSwitch(None, None) + + # when getCmd returns tooBig when too many oids are asked for + def custgetcmd(eng, cd, targ, contextdata, *oids): + # induce a too big error + if len(oids) > 3: + res = ( None, 'tooBig', None, None ) + else: + #import pdb; pdb.set_trace() + [ oid.resolveWithMib(_mvc) for oid in oids ] + res = ( None, None, None, oids ) + + return iter([res]) + + gc.side_effect = custgetcmd + + #import pdb; pdb.set_trace() + res = switch.getegress(*xrange(1, 10)) + + # will still return the complete set of results + self.assertEqual(res, { x: '' for x in xrange(1, 10) }) + _skipSwitchTests = True class _TestSwitch(unittest.TestCase):