fix uninitialized ASN.1 objects use

The underlying pyasn1 library has a notion of `schema` and
`value` object. The `schema` object can't be used with
regular Python operators as values because `schema` does
not carry any value, it's rather a type.

This fix turns a couple of `NoSuchInstance` schema
objects into proper `value` objects to retain compatibility
with the latest pysnmp which removed the default initializer
of the `NoSuchInstance` object.

Change-Id: Id044a0e437724bf1f3581e9187e2a1e6c336b1bc
This commit is contained in:
Ilya Etingof 2018-02-16 11:57:59 +01:00
parent a1c8f82b20
commit 8bc40fff79
3 changed files with 4 additions and 4 deletions

View File

@ -32,7 +32,7 @@ class TestPDU(PDUTestCase):
self.snmp_get, enterprises + (42,)) self.snmp_get, enterprises + (42,))
def test_set_unknown_oid(self): def test_set_unknown_oid(self):
self.assertEqual(NoSuchInstance(), self.assertEqual(NoSuchInstance(''),
self.snmp_set(enterprises + (42,), univ.Integer(7))) self.snmp_set(enterprises + (42,), univ.Integer(7)))
def test_get_valid_oid_wrong_community(self): def test_get_valid_oid_wrong_community(self):

View File

@ -108,7 +108,7 @@ class SnmpServiceMessageReceivedTest(unittest.TestCase):
varbindlist = message[PDUs][ResponsePDU][VarBindList] varbindlist = message[PDUs][ResponsePDU][VarBindList]
self.assertEqual(varbindlist[0][ObjectName].value, (1, 1)) self.assertEqual(varbindlist[0][ObjectName].value, (1, 1))
self.assertEqual(varbindlist[0][NoSuchInstance].value, self.assertEqual(varbindlist[0][NoSuchInstance].value,
NoSuchInstance()) NoSuchInstance(''))
def test_get(self): def test_get(self):
self.pdu_mock.oid_mapping[(1, 1)] = Mock() self.pdu_mock.oid_mapping[(1, 1)] = Mock()

View File

@ -121,10 +121,10 @@ class TestSnmpClient(base.TestCase):
def test_set_no_such_instance(self): def test_set_no_such_instance(self):
oid = (1, 3, 6) oid = (1, 3, 6)
self.command_generator_mock.setCmd.return_value = \ self.command_generator_mock.setCmd.return_value = \
(None, 0, 0, [(oid, NoSuchInstance())]) (None, 0, 0, [(oid, NoSuchInstance(''))])
value = self.snmp_client.set(oid, '43 thousands') value = self.snmp_client.set(oid, '43 thousands')
self.assertEqual(NoSuchInstance(), value) self.assertEqual(NoSuchInstance(''), value)
self.oneliner_cmdgen.UdpTransportTarget \ self.oneliner_cmdgen.UdpTransportTarget \
.assert_called_with((sentinel.hostname, sentinel.port), .assert_called_with((sentinel.hostname, sentinel.port),