Skip to content
Snippets Groups Projects
Commit d76ff879 authored by Taya Snijder's avatar Taya Snijder
Browse files

L2SS-874 merged test_mib_loading.py tests in to test_snmp_client

parent 31077660
No related branches found
No related tags found
1 merge request!427Resolve L2SS-874 "Mib loading test"
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)
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment