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

added support for spectrum SNMP attributes

parent a54db2a7
No related branches found
No related tags found
1 merge request!288Resolve L2SS-446 "Extend snmp client to support mib files"
...@@ -149,12 +149,34 @@ class snmp_attribute: ...@@ -149,12 +149,34 @@ class snmp_attribute:
self.name = name self.name = name
self.idx = idx self.idx = idx
self.dtype = dtype self.dtype = dtype
self.dim_x = dim_x
self.dim_y = dim_y self.is_scalar = (dim_x + dim_y) == 1
self.is_scalar = (self.dim_x + self.dim_y) == 1 self.len = self.get_len(dim_x, dim_y)
self.objID = self.create_objID() self.objID = self.create_objID()
def get_len(self, dim_x, dim_y):
"""""Small helper function to not clutter the __init__"""
if dim_x == 0:
dim_x = 1
if dim_y == 0:
dim_y = 1
return dim_x * dim_y
def create_objID(self):
# only scalars can be used at the present time.
if not self.is_scalar:
objID = tuple(hlapi.ObjectIdentity(self.mib, self.name, self.idx + i) for i in range(self.len))
else:
objID = hlapi.ObjectIdentity(self.mib, self.name, self.idx)
return objID
def next_wrap(self, cmd): def next_wrap(self, cmd):
""" """
This function exists to allow the next(cmd) call to be mocked for unit testing. As the This function exists to allow the next(cmd) call to be mocked for unit testing. As the
...@@ -165,8 +187,6 @@ class snmp_attribute: ...@@ -165,8 +187,6 @@ class snmp_attribute:
""" """
Read function we give to the attribute wrapper Read function we give to the attribute wrapper
""" """
# must be recreated for each read it seems
self.objs = tuple(hlapi.ObjectType(i) for i in self.objID) self.objs = tuple(hlapi.ObjectType(i) for i in self.objID)
# get the thingy to get the values # get the thingy to get the values
...@@ -193,6 +213,7 @@ class snmp_attribute: ...@@ -193,6 +213,7 @@ class snmp_attribute:
write_obj = tuple(hlapi.ObjectType(self.objID[i], value[i]) for i in range(len(self.objID))) write_obj = tuple(hlapi.ObjectType(self.objID[i], value[i]) for i in range(len(self.objID)))
set_cmd = hlapi.setCmd(self.client.engine, self.client.community, self.client.trasport, self.client.ctx_data, *write_obj) set_cmd = hlapi.setCmd(self.client.engine, self.client.community, self.client.trasport, self.client.ctx_data, *write_obj)
errorIndication, errorStatus, errorIndex, *varBinds = self.next_wrap(set_cmd) errorIndication, errorStatus, errorIndex, *varBinds = self.next_wrap(set_cmd)
def convert(self, varBinds): def convert(self, varBinds):
...@@ -221,16 +242,4 @@ class snmp_attribute: ...@@ -221,16 +242,4 @@ class snmp_attribute:
return vals return vals
def create_objID(self):
# only scalars can be used at the present time.
if not self.is_scalar:
# tuple(hlapi.ObjectIdentity(mib, name, idx) for i in range(len(oids)))
raise ValueError(f"MIB + name type attributes can only be scalars, got dimensions of: ({x}, {y})")
else:
objID = hlapi.ObjectIdentity(self.mib, self.name, self.idx)
return objID
...@@ -22,8 +22,7 @@ class server_imitator: ...@@ -22,8 +22,7 @@ class server_imitator:
# shortcut for testing dimensionality # shortcut for testing dimensionality
dim_list = { dim_list = {
"scalar": (1, 0), "scalar": (1, 0),
#NOTE: spectrum not supported currently "spectrum": (4, 0),
#"spectrum": (4, 0),
} }
def get_return_val(self, snmp_type : type, dims : tuple): def get_return_val(self, snmp_type : type, dims : tuple):
...@@ -132,9 +131,10 @@ class TestSNMP(base.TestCase): ...@@ -132,9 +131,10 @@ class TestSNMP(base.TestCase):
self.assertEqual(checkval, val, f"Expected: {checkval}, got: {val}") self.assertEqual(checkval, val, f"Expected: {checkval}, got: {val}")
@mock.patch('pysnmp.hlapi.ObjectIdentity') @mock.patch('pysnmp.hlapi.ObjectIdentity')
@mock.patch('pysnmp.hlapi.ObjectType')
@mock.patch('pysnmp.hlapi.setCmd') @mock.patch('pysnmp.hlapi.setCmd')
@mock.patch('tangostationcontrol.clients.snmp_client.snmp_attribute.next_wrap') @mock.patch('tangostationcontrol.clients.snmp_client.snmp_attribute.next_wrap')
def test_snmp_obj_set(self, m_next, m_nextCmd, m_obj_i): def test_snmp_obj_set(self, m_next, m_nextCmd, m_obj_T, m_obj_ID):
""" """
Attempts to write a value to an SNMP server, but instead intercepts it and compared whether the values is as expected. Attempts to write a value to an SNMP server, but instead intercepts it and compared whether the values is as expected.
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment