diff --git a/tangostationcontrol/tangostationcontrol/clients/snmp_client.py b/tangostationcontrol/tangostationcontrol/clients/snmp_client.py index d7ca16b907fa78b6c767eb7d81d2654afaf37a00..71d50713a0434b8505bc32f26400ba4e49cf16fe 100644 --- a/tangostationcontrol/tangostationcontrol/clients/snmp_client.py +++ b/tangostationcontrol/tangostationcontrol/clients/snmp_client.py @@ -238,7 +238,7 @@ class snmp_attribute: elif needs_conversion_from_integer_to_str(value): result = convert_integer_to_str(value) elif needs_conversion_from_number_to_int64(value): - result = numpy.int64(value) * self.scaling_factor + result = numpy.int64(value) * self.scaling_factor elif needs_conversion_from_string_to_str(value): result = str(value) else: diff --git a/tangostationcontrol/tangostationcontrol/test/clients/test_mib_loading.py b/tangostationcontrol/tangostationcontrol/test/clients/test_mib_loading.py index 9e1513e62d301e4f9fdc04e8a1653c63b1b2ea11..6939aa7874947df3c0627a5efb9db4806ce7b738 100644 --- a/tangostationcontrol/tangostationcontrol/test/clients/test_mib_loading.py +++ b/tangostationcontrol/tangostationcontrol/test/clients/test_mib_loading.py @@ -1,11 +1,11 @@ from tangostationcontrol.test import base -# from tangostationcontrol.clients.snmp_client import mib_loader -# from pysnmp.smi import view -# import pysnmp.hlapi as pysnmp -# from pysnmp.smi.rfc1902 import ObjectIdentity -# -# from os import path +from tangostationcontrol.clients.snmp_client import mib_loader +from pysnmp.smi import view +import pysnmp.hlapi as pysnmp +from pysnmp.smi.rfc1902 import ObjectIdentity + +from os import path class TestMibLoading(base.TestCase): @@ -17,40 +17,54 @@ class TestMibLoading(base.TestCase): REL_DIR = "SNMP_mib_loading" def test_content(self): - return - - # """ - # This file contains a 1 variable named: testNamedValue with oid "9.8.7.6.5.4.3.2.1" with named values: ("A", 1), ("B", 2), ("C", 3), ("D", 4) - # In order to confirm that the mib is indeed loaded correctly this test has to get the oids, the values and the named values - # - # """ - # - # # abs_dir = path.dirname(__file__) + "/" + self.REL_DIR - # abs_dir = "test/clients/SNMP_mib_loading/TEST-MIB.mib" - # loader = mib_loader(abs_dir) - # loader.load_pymib(self.MIB) - # - # # used to view mibs client side - # mibView = view.MibViewController(loader.mibBuilder) - # - # # The expected testNamedValue parameters as written in TEST-MIB.py - # testNamedValue = "testNamedValue" - # testNamedValue_oid = "9.8.7.6.5.4.3.2.1" - # testNamedValue_named = "A" - # testNamedValue_value = 1 - # - # # get testValue and set a value of 1 - # obj_T = pysnmp.ObjectType(ObjectIdentity(self.MIB, testNamedValue), pysnmp.Integer32(1)) - # obj_T.resolveWithMib(mibView) - # - # # get the oid - # self.assertEqual(str(obj_T[0]), testNamedValue_oid) - # - # # get the name format: mib::name - # self.assertEqual(obj_T[0].prettyPrint(), f"{self.MIB}::{testNamedValue}") - # - # # get the namedValue - # self.assertEqual(str(obj_T[1]), testNamedValue_named) - # - # # get the numerical value - # self.assertEqual(int(obj_T[1]), testNamedValue_value) + + """ + This file contains a 1 variable named: testNamedValue with oid "9.8.7.6.5.4.3.2.1" with named values: ("A", 1), ("B", 2), ("C", 3), ("D", 4) + In order to confirm that the mib is indeed loaded correctly this test has to get the oids, the values and the named values + + """ + + abs_dir = path.dirname(__file__) + "/" + self.REL_DIR + abs_dir = "test/clients/SNMP_mib_loading/TEST-MIB.mib" + loader = mib_loader(abs_dir) + + iterator = pysnmp.getCmd( + pysnmp.SnmpEngine(), + pysnmp.CommunityData('public', mpModel=1), + pysnmp.UdpTransportTarget(('127.0.0.1', 161)), + pysnmp.ContextData(), + pysnmp.ObjectType(ObjectIdentity('TEST-MIB', 'testNamedValue', 1)) + ) + + try: + next(iterator) + except: + pass + + loader.load_pymib(self.MIB) + + + # used to view mibs client side + mibView = view.MibViewController(loader.mibBuilder) + + # The expected testNamedValue parameters as written in TEST-MIB.py + testNamedValue = "testNamedValue" + testNamedValue_oid = "9.8.7.6.5.4.3.2.1" + testNamedValue_named = "A" + testNamedValue_value = 1 + + # get testValue and set a value of 1 + obj_T = pysnmp.ObjectType(ObjectIdentity(self.MIB, testNamedValue), pysnmp.Integer32(1)) + obj_T.resolveWithMib(mibView) + + # get the oid + self.assertEqual(str(obj_T[0]), testNamedValue_oid) + + # get the name format: mib::name + self.assertEqual(obj_T[0].prettyPrint(), f"{self.MIB}::{testNamedValue}") + + # get the namedValue + self.assertEqual(str(obj_T[1]), testNamedValue_named) + + # get the numerical value + self.assertEqual(int(obj_T[1]), testNamedValue_value)