diff --git a/tangostationcontrol/tangostationcontrol/test/clients/test_mib_loading.py b/tangostationcontrol/tangostationcontrol/test/clients/test_mib_loading.py deleted file mode 100644 index 0ea33e2a529a57b0dbaa5d92565ad9268f45a497..0000000000000000000000000000000000000000 --- a/tangostationcontrol/tangostationcontrol/test/clients/test_mib_loading.py +++ /dev/null @@ -1,57 +0,0 @@ -from pysnmp.smi import view -import pysnmp.hlapi as pysnmp -from pysnmp.smi.rfc1902 import ObjectIdentity - -from tangostationcontrol.test import base - -from tangostationcontrol.clients.snmp_client import mib_loader - - -from os import path - - -class TestMibLoading(base.TestCase): - - #name and directory of the pymib file - MIB = "TEST-MIB" - - # mib file is in a folder that is in the same folder as this test - REL_DIR = "snmp_mib_loading" - - def test_retrieve_mib_content(self): - - """ - This file contains a 1 variable named: testNamedValue with oid "1.3.99.1.99" with named values: ("test_name", 1), ("other_name", 2) - 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 + "/" - 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.mib - testNamedValue_oid = "1.3.99.1.99" - testNamedValue = "testNamedValue" - testNamedValue_named = "test_name" - 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) diff --git a/tangostationcontrol/tangostationcontrol/test/clients/test_snmp_client.py b/tangostationcontrol/tangostationcontrol/test/clients/test_snmp_client.py index ee04a1b3dfffab25d012ba81c0a80d3e61c1de50..90eb1463614e2141d025b42a25b8fb2eaa67fb45 100644 --- a/tangostationcontrol/tangostationcontrol/test/clients/test_snmp_client.py +++ b/tangostationcontrol/tangostationcontrol/test/clients/test_snmp_client.py @@ -1,11 +1,13 @@ from pysnmp import hlapi +from pysnmp.smi import view +from pysnmp.smi.rfc1902 import ObjectIdentity +from os import path import numpy from unittest import mock - from tangostationcontrol.test import base -from tangostationcontrol.clients.snmp_client import SNMP_client, snmp_attribute, SNMP_comm +from tangostationcontrol.clients.snmp_client import SNMP_client, snmp_attribute, SNMP_comm, mib_loader class server_imitator: @@ -211,3 +213,50 @@ class TestSNMP(base.TestCase): # check to make sure the value is indeed 2 self.assertEqual(ret_val, 2, f"Expected: to get {2}, got: {ret_val} of type {type(ret_val)}") + + +class TestMibLoading(base.TestCase): + + #name and directory of the pymib file + MIB = "TEST-MIB" + + # mib file is in a folder that is in the same folder as this test + REL_DIR = "snmp_mib_loading" + + def test_retrieve_mib_content(self): + + """ + This file contains a 1 variable named: testNamedValue with oid "1.3.99.1.99" with named values: ("test_name", 1), ("other_name", 2) + 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 + "/" + 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.mib + testNamedValue_oid = "1.3.99.1.99" + testNamedValue = "testNamedValue" + testNamedValue_named = "test_name" + testNamedValue_value = 1 + + # get testValue and set a value of 1 + obj_T = hlapi.ObjectType(ObjectIdentity(self.MIB, testNamedValue), hlapi.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)