Ack,
Mathi.

----- [email protected] wrote:

> python/pyosaf/utils/immom/ccb.py |  56
> ++++++++++++---------------------------
>  1 files changed, 17 insertions(+), 39 deletions(-)
> 
> 
> Fix marshalling and wrong module prefixes in modify_value_add,
> modify_value_replace and modify_value_delete in ccb.py.
> 
> Use the following steps to verify the fix:
> 
> 
> 1. Create a test class
> 
> $ cat > testclass.xml
> <?xml version="1.0"?>
> <imm:IMM-contents
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xsi:noNamespaceSchemaLocation="SAI-AIS-IMM-XSD-A.02.13.xsd"
> xmlns:xs="http://www.w3.org/2001/XMLSchema";
> xmlns:imm="http://www.saforum.org/IMMSchema";>
> <class name="SampleClass">
> <category>SA_CONFIG</category>
> <rdn>
> <name>sampleClassId</name>
> <type>SA_STRING_T</type>
> <category>SA_CONFIG</category>
> <flag>SA_INITIALIZED</flag>
> <flag>SA_NOTIFY</flag>
> </rdn>
> <attr>
> <name>attribute1</name>
> <type>SA_STRING_T</type>
> <category>SA_CONFIG</category>
> <flag>SA_WRITABLE</flag>
> <flag>SA_NOTIFY</flag>
> <flag>SA_MULTI_VALUE</flag>
> </attr>
> </class>
> </imm:IMM-contents>
> 
> $ immcfg -f testclass.xml
> 
> 
> 2. Create an instance
> $ immcfg -c SampleClass sampleClassId=1
> 
> 
> 3. Test the methods in the Python shell
> $ 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.
> >>>
> >>> from pyosaf.utils.immom.ccb import Ccb
> >>> from pyosaf.utils import immom
> >>> test_object = immom.get('sampleClassId=1')
> >>> print test_object.attribute1
> []
> >>>
> >>> # Verify that modify_value_add works
> ...
> >>> ccb = Ccb()
> >>> ccb.modify_value_add("sampleClassId=1", "attribute1", ["a", "b"])
> >>> ccb.apply()
> >>>
> >>> test_object = immom.get('sampleClassId=1')
> >>> print test_object.attribute1
> ['a', 'b']
> >>>
> >>>
> >>> # Verify that modify_value_replace works
> ...
> >>> ccb = Ccb()
> >>> ccb.modify_value_replace("sampleClassId=1", "attribute1", ["c",
> "d"])
> >>> ccb.apply()
> >>> test_object = immom.get('sampleClassId=1')
> >>>
> >>> print test_object.attribute1
> ['c', 'd']
> >>>
> >>>
> >>> # Verify that modify_value_delete works
> ...
> >>> ccb = Ccb()
> >>> ccb.modify_value_delete("sampleClassId=1", "attribute1", ["c"])
> >>> ccb.apply()
> >>> test_object = immom.get('sampleClassId=1')
> >>> print test_object.attribute1
> ['d']
> >>>
> 
> diff --git a/python/pyosaf/utils/immom/ccb.py
> b/python/pyosaf/utils/immom/ccb.py
> --- a/python/pyosaf/utils/immom/ccb.py
> +++ b/python/pyosaf/utils/immom/ccb.py
> @@ -22,9 +22,11 @@ import time
>  from ctypes import c_void_p, pointer, cast
>  
>  from pyosaf.saAis import eSaAisErrorT, SaNameT, SaStringT, \
> -    SaDoubleT, SaTimeT, SaUint64T, SaInt64T, SaUint32T, SaInt32T,
> SaFloatT
> +    SaDoubleT, SaTimeT, SaUint64T, SaInt64T, SaUint32T, SaInt32T,
> SaFloatT, \
> +    marshalNullArray
>  
> -from pyosaf.saImm import eSaImmScopeT, eSaImmValueTypeT,
> SaImmAttrValuesT_2
> +from pyosaf.saImm import eSaImmScopeT, eSaImmValueTypeT,
> SaImmAttrValuesT_2, \
> +    SaImmValueTypeMap
>  
>  from pyosaf import saImm
>  from pyosaf import saImmOm
> @@ -35,7 +37,6 @@ from pyosaf.utils.immom.common import Sa
>  
>  TRYAGAIN_CNT = 60
>  
> -
>  def _value_to_ctype_ptr(value_type, value):
>      ''' convert a value to a ctypes value ptr '''
>      if value_type is eSaImmValueTypeT.SA_IMM_ATTR_SAINT32T:
> @@ -175,7 +176,7 @@ class Ccb(object):
>              raise SafException(err, "saImmOmCcbObjectDelete: %s - %s"
> % \
>                  (_object_name, eSaAisErrorT.whatis(err)))
>  
> -    def modify_value_add(self, object_name, attr_name, value):
> +    def modify_value_add(self, object_name, attr_name, values):
>          ''' add to the CCB an ADD modification of an existing object
> '''
>  
>          assert object_name
> @@ -208,23 +209,16 @@ class Ccb(object):
>                  (object_name, eSaAisErrorT.whatis(err)))
>  
>          attr_mods = []
> +
>          attr_mod = saImmOm.SaImmAttrModificationT_2()
>          attr_mod.modType = \
> -           
> saImmOm.eSaImmAttrModificationTypeT.SA_IMM_ATTR_VALUES_ADD
> +            saImm.eSaImmAttrModificationTypeT.SA_IMM_ATTR_VALUES_ADD
>          attr_mod.modAttr = SaImmAttrValuesT_2()
>          attr_mod.modAttr.attrName = attr_name
>          attr_mod.modAttr.attrValueType = value_type
> -        attr_mod.modAttr.attrValuesNumber = 1
> +        attr_mod.modAttr.attrValuesNumber = len(values)
> +        attr_mod.modAttr.attrValues = marshal_c_array(value_type,
> values)
>  
> -        values = []
> -        values.append(value)
> -        try:
> -            ptr2ctype = _value_to_ctype_ptr(value_type, value)
> -        except ValueError:
> -            raise
> SafException(eSaAisErrorT.SA_AIS_ERR_INVALID_PARAM,
> -                "value '%s' has wrong type" % value)
> -
> -        attr_mod.modAttr.attrValues = pointer(ptr2ctype)
>          attr_mods.append(attr_mod)
>  
>          err = saImmOm.saImmOmCcbObjectModify_2(self.ccb_handle,
> @@ -233,7 +227,7 @@ class Ccb(object):
>              print "saImmOmCcbObjectModify_2: %s, %s" %
> (eSaAisErrorT.whatis(err), object_name)
>              raise SafException(err)
>  
> -    def modify_value_replace(self, object_name, attr_name, value):
> +    def modify_value_replace(self, object_name, attr_name, values):
>          ''' add to the CCB an REPLACE modification of an existing
> object '''
>  
>          assert object_name
> @@ -268,21 +262,13 @@ class Ccb(object):
>          attr_mods = []
>          attr_mod = saImmOm.SaImmAttrModificationT_2()
>          attr_mod.modType = \
> -           
> saImmOm.eSaImmAttrModificationTypeT.SA_IMM_ATTR_VALUES_REPLACE
> +           
> saImm.eSaImmAttrModificationTypeT.SA_IMM_ATTR_VALUES_REPLACE
>          attr_mod.modAttr = SaImmAttrValuesT_2()
>          attr_mod.modAttr.attrName = attr_name
>          attr_mod.modAttr.attrValueType = value_type
> -        attr_mod.modAttr.attrValuesNumber = 1
> +        attr_mod.modAttr.attrValuesNumber = len(values)
> +        attr_mod.modAttr.attrValues = marshal_c_array(value_type,
> values)
>  
> -        values = []
> -        values.append(value)
> -        try:
> -            ptr2ctype = _value_to_ctype_ptr(value_type, value)
> -        except ValueError:
> -            raise
> SafException(eSaAisErrorT.SA_AIS_ERR_INVALID_PARAM,
> -                "value '%s' has wrong type" % value)
> -
> -        attr_mod.modAttr.attrValues = pointer(ptr2ctype)
>          attr_mods.append(attr_mod)
>  
>          err = saImmOm.saImmOmCcbObjectModify_2(self.ccb_handle,
> @@ -291,7 +277,7 @@ class Ccb(object):
>              print "saImmOmCcbObjectModify_2: %s, %s" %
> (eSaAisErrorT.whatis(err), object_name)
>              raise SafException(err)
>  
> -    def modify_value_delete(self, object_name, attr_name, value):
> +    def modify_value_delete(self, object_name, attr_name, values):
>          ''' add to the CCB an DELETE modification of an existing
> object '''
>  
>          assert object_name
> @@ -326,21 +312,13 @@ class Ccb(object):
>          attr_mods = []
>          attr_mod = saImmOm.SaImmAttrModificationT_2()
>          attr_mod.modType = \
> -           
> saImmOm.eSaImmAttrModificationTypeT.SA_IMM_ATTR_VALUES_DELETE
> +           
> saImm.eSaImmAttrModificationTypeT.SA_IMM_ATTR_VALUES_DELETE
>          attr_mod.modAttr = SaImmAttrValuesT_2()
>          attr_mod.modAttr.attrName = attr_name
>          attr_mod.modAttr.attrValueType = value_type
> -        attr_mod.modAttr.attrValuesNumber = 1
> +        attr_mod.modAttr.attrValuesNumber = len(values)
> +        attr_mod.modAttr.attrValues = marshal_c_array(value_type,
> values)
>  
> -        values = []
> -        values.append(value)
> -        try:
> -            ptr2ctype = _value_to_ctype_ptr(value_type, value)
> -        except ValueError:
> -            raise
> SafException(eSaAisErrorT.SA_AIS_ERR_INVALID_PARAM,
> -                "value '%s' has wrong type" % value)
> -
> -        attr_mod.modAttr.attrValues = pointer(ptr2ctype)
>          attr_mods.append(attr_mod)
>  
>          err = saImmOm.saImmOmCcbObjectModify_2(self.ccb_handle,

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to