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

changes

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