Exemplo n.º 1
0
    def setUp(self):
        with mock.patch.object(oid_db, 'loadConfig', autospec=True):
            with mock.patch.object(oid_db, 'set_logging', autospec=True):
                self.oidDb = oid_db.OidDb(mock.MagicMock(config={}))

                for ident, value in reversed(self.MIB_OBJECTS):
                    self.oidDb.add(*ident, value=value)

        super(OidDbTestCase, self).setUp()
Exemplo n.º 2
0
    def test_add_expire(self, mock_set_logging, mock_loadConfig, mock_time):
        mock_time.return_value = 0

        oidDb = oid_db.OidDb(mock.MagicMock(config={}))

        # add sysDescr.0 and expect it to be in the OID DB

        oidDb.add('SNMPv2-MIB', 'sysDescr', 0, value='my system')

        expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.1.0')

        oidItem = oidDb.getObjectByOid(expected)

        self.assertEqual(expected, oidItem.oid)

        mock_time.return_value = 61

        # add sysORDescr.1 and expect sysDescr.0 & sysORDescr.1
        # to be in the OID DB

        oidDb.add('SNMPv2-MIB', 'sysORDescr', 1, value='descr')

        expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.1.0')

        oidItem = oidDb.getObjectByOid(expected)

        self.assertEqual(expected, oidItem.oid)

        expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.9.1.3.1')

        oidItem = oidDb.getObjectByOid(expected)

        self.assertEqual(expected, oidItem.oid)

        mock_time.return_value = 122

        # add sysORDescr.2 and expect sysORDescr.1 to expire

        oidDb.add('SNMPv2-MIB', 'sysORDescr', 2, value='descr')

        expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.1.0')

        oidItem = oidDb.getObjectByOid(expected)

        self.assertEqual(expected, oidItem.oid)

        not_expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.9.1.3.1')

        oidItem = oidDb.getObjectByOid(not_expected)

        self.assertIsNone(oidItem)

        expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.9.1.3.2')

        oidItem = oidDb.getObjectByOid(expected)

        self.assertEqual(expected, oidItem.oid)
Exemplo n.º 3
0
    def setUp(self):
        with mock.patch.object(oid_db, 'loadConfig', autospec=True):
            with mock.patch.object(oid_db, 'set_logging', autospec=True):
                self.oidDb = oid_db.OidDb(mock.MagicMock(config={}))

        self.container = mmod.ConfdGlobalInterfaceContainer()

        self.my_loop = asyncio.new_event_loop()
        self.addCleanup(self.my_loop.close)

        super(ConfdGlobalInterfaceContainerTestCase, self).setUp()
Exemplo n.º 4
0
    def setUp(self):
        with mock.patch.object(oid_db, 'loadConfig',
                               autospec=True) as config_mock:
            with mock.patch.object(oid_db, 'set_logging', autospec=True):
                config_mock.return_value = self.CONFIG
                self.oidDb = oid_db.OidDb(mock.MagicMock(config={}))

        self.container = mmod.StaticAndPredefinedOids()

        self.my_loop = asyncio.new_event_loop()
        self.addCleanup(self.my_loop.close)

        super(StaticAndPredefinedOidsTestCase, self).setUp()
Exemplo n.º 5
0
    def test_add_permanent(self, mock_set_logging, mock_loadConfig, mock_time):
        mock_time.return_value = 0

        oidDb = oid_db.OidDb(mock.MagicMock(config={}))

        # add sysDescr and expect it to be in the OID DB

        oidDb.add('SNMPv2-MIB', 'sysDescr', 0, value='my system')

        expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.1.0')

        oidItem = oidDb.getObjectByOid(expected)

        self.assertEqual(expected, oidItem.oid)

        mock_time.return_value = 61

        # add snmpOutNoSuchNames and expect sysDescr & snmpOutNoSuchNames
        # to be in the OID DB

        oidDb.add('SNMPv2-MIB', 'snmpOutNoSuchNames', 0, value=123)

        expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.1.0')

        oidItem = oidDb.getObjectByOid(expected)

        self.assertEqual(expected, oidItem.oid)

        expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.11.21.0')

        oidItem = oidDb.getObjectByOid(expected)

        self.assertEqual(expected, oidItem.oid)

        mock_time.return_value = 122

        # update snmpOutNoSuchNames, but expect sysDescr to still be there

        oidDb.add('SNMPv2-MIB', 'snmpOutNoSuchNames', 0, value=123)

        expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.1.0')

        oidItem = oidDb.getObjectByOid(expected)

        self.assertEqual(expected, oidItem.oid)

        expected = rfc1902.ObjectIdentifier('1.3.6.1.2.1.11.21.0')

        oidItem = oidDb.getObjectByOid(expected)

        self.assertEqual(expected, oidItem.oid)
    def setUp(self):
        with mock.patch.object(oid_db, 'loadConfig',
                               autospec=True) as config_mock:
            config_mock.return_value = self.CONFIG

            with mock.patch.object(oid_db, 'set_logging', autospec=True):
                self.oidDb = oid_db.OidDb(mock.MagicMock(config=self.CONFIG))

        self.container = mmod.ConfdGlobalStartupStatusConfd()

        self.my_loop = asyncio.new_event_loop()
        self.addCleanup(self.my_loop.close)

        super(ConfdGlobalStartupStatusConfdTestCase, self).setUp()
Exemplo n.º 7
0
    def test_add_value(self, mock_set_logging, mock_loadConfig):
        oidDb = oid_db.OidDb(mock.MagicMock(config={}))

        oidDb.add('SNMPv2-MIB', 'sysDescr', 0, value='my system')

        expectedOid = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.1.0')

        oidItem = oidDb.getObjectByOid(expectedOid)

        self.assertEqual(expectedOid, oidItem.oid)

        expectedValue = rfc1902.OctetString('my system')
        self.assertEqual(expectedValue, oidItem.value)

        self.assertIsNone(oidItem.code)
Exemplo n.º 8
0
    def test_add_code(self, mock_set_logging, mock_loadConfig):
        oidDb = oid_db.OidDb(mock.MagicMock(config={}))

        code = """
# no op
pass
"""
        oidDb.add('SNMPv2-MIB', 'sysDescr', 0, value='', code=code)

        expectedOid = rfc1902.ObjectIdentifier('1.3.6.1.2.1.1.1.0')

        oidItem = oidDb.getObjectByOid(expectedOid)

        self.assertEqual(expectedOid, oidItem.oid)
        self.assertEqual('', str(oidItem.value))
        self.assertIsInstance(oidItem.code, types.CodeType)