The saImmOmSearchInitialize_2 method in saImmOm.py only works as long as it's called without specifying the list of attributes to retrieve. The marshalling of the list is broken. The steps to reproduce this are:
$ python Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> # Verify that KeyboardInterrupt >>> >>> # Handle imports ... >>> from pyosaf.saImm import SaImmSearchParametersT_2, eSaImmValueTypeT, eSaImmScopeT >>> from ctypes import cast, pointer, c_void_p, c_char_p >>> from pyosaf import saImm, saImmOm >>> from pyosaf.utils import immom >>> >>> >>> # Set parameters ... >>> name = c_char_p("SampleClass") >>> search_param = SaImmSearchParametersT_2() >>> search_param.searchOneAttr.attrName = "SaImmAttrClassName" >>> search_param.searchOneAttr.attrValueType = eSaImmValueTypeT.SA_IMM_ATTR_SASTRINGT >>> search_param.searchOneAttr.attrValue = cast(pointer(name), c_void_p) >>> scope = eSaImmScopeT.SA_IMM_SUBTREE >>> search_options = saImm.saImm.SA_IMM_SEARCH_ONE_ATTR >>> attribute_names = None >>> search_handle = saImmOm.SaImmSearchHandleT() >>> attribute_names = ["attribute1"] >>> >>> >>> # Provoke the fault ... >>> saImmOm.saImmOmSearchInitialize_2(immom.HANDLE, None, scope, search_options, search_param, attribute_names, search_handle) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/pyosaf/saImmOm.py", line 281, in saImmOmSearchInitialize_2 BYREF(attributeNames), File "/usr/local/lib/python2.7/dist-packages/pyosaf/saAis.py", line 196, in BYREF return None if data == None else byref(data) TypeError: byref() argument must be a ctypes instance, not 'list' >>>
Correction, each attribute name in the list must be marshalled by the caller:
attribute_names = [SaImmAttrNameT("attribute1")]
And search_options is wrong as well. With these fixes, the (copy-paste friendly) code to trigger the fault is:
from pyosaf.saImm import SaImmSearchParametersT_2, eSaImmValueTypeT, eSaImmScopeT, SaImmAttrNameT
from ctypes import cast, pointer, c_void_p, c_char_p
from pyosaf import saImm, saImmOm
from pyosaf.utils import immom
Set parameters
name = c_char_p("SampleClass")
search_param = SaImmSearchParametersT_2()
search_param.searchOneAttr.attrName = "SaImmAttrClassName"
search_param.searchOneAttr.attrValueType = eSaImmValueTypeT.SA_IMM_ATTR_SASTRINGT
search_param.searchOneAttr.attrValue = cast(pointer(name), c_void_p)
scope = eSaImmScopeT.SA_IMM_SUBTREE
search_options = saImm.saImm.SA_IMM_SEARCH_ONE_ATTR | saImm.saImm.SA_IMM_SEARCH_GET_SOME_ATTR
attribute_names = None
search_handle = saImmOm.SaImmSearchHandleT()
attribute_names = [SaImmAttrNameT("attribute1")]
Provoke the fault
saImmOm.saImmOmSearchInitialize_2(immom.HANDLE, None, scope, search_options, search_param, attribute_names, search_handle)
changeset: 6657:076a983d0d33
tag: tip
parent: 6654:bb54e27d86fb
user: Johan Mårtensson johan.o.martensson@ericsson.com
date: Thu Jul 09 16:47:16 2015 +0200
summary: pyosaf: Fix broken marshalling of the attribute list in saImmOmSearchInitialize_2 in saImmOm.py [#1408]
changeset: 6656:13de5120210a
branch: opensaf-4.6.x
parent: 6653:879bc51d5131
user: Johan Mårtensson johan.o.martensson@ericsson.com
date: Thu Jul 09 16:47:16 2015 +0200
summary: pyosaf: Fix broken marshalling of the attribute list in saImmOmSearchInitialize_2 in saImmOm.py [#1408]
changeset: 6655:d3f811aa0a32
branch: opensaf-4.5.x
parent: 6652:7be459a08ca1
user: Johan Mårtensson johan.o.martensson@ericsson.com
date: Thu Jul 09 16:47:16 2015 +0200
summary: pyosaf: Fix broken marshalling of the attribute list in saImmOmSearchInitialize_2 in saImmOm.py [#1408]
Related
Tickets:
#1408