Hi Johan,

Ack from me.
Reviewed and tested the patch.
Only a minor comment about mixed tab/space indentation.


I found a problem when testing and we might need another ticket for this defect.
immadm worked fine with SASTRINGT param and SANAMET param but I got this error 
when trying immadm with SAUINT32T param.

root@SC1:~# ./immadm -p param_name:SA_IMM_ATTR_SAUINT32T:100 10 test=1
     Traceback (most recent call last):
       File "/srv/shared/immadm", line 89, in <module>
         result = immadm(options, args)
   File "/srv/shared/immadm", line 73, in immadm
      val))
   File "/usr/local/lib/python2.7/dist-packages/pyosaf/saImm.py", line 172, in 
__init__
     pval = cast(pointer(SaImmValueTypeMap[ptype](val)), SaVoidPtr)
TypeError: an integer is required

The problem is in saImm module.
'val' must be converted from str to long or float before the pointer cast.
pval = cast(pointer(SaImmValueTypeMap[ptype](*val*)), SaVoidPtr)


Best Regards,

Hung Nguyen - DEK Technologies


--------------------------------------------------------------------------------
From: Johan Mårtensson [email protected]
Sent: Friday, October 02, 2015 10:53PM
To: Hans Nordeback, Mathivanan Naickan, Hung Nguyen, Srikanth Revanuru
     [email protected], [email protected], 
[email protected], [email protected]
Cc: Opensaf-devel
     [email protected]
Subject: [PATCH 1 of 1] pyosaf: Update the Python IMM sample applications to 
use the immom utils [#1451]


  python/samples/immadm  |  78 +++++++++++++++++++------------------------------
  python/samples/immlist |  51 ++++++++++++-------------------
  2 files changed, 50 insertions(+), 79 deletions(-)


Update the Python IMM sample applications to use the immom utils bindings 
instead of the direct C mappings.

diff --git a/python/samples/immadm b/python/samples/immadm
--- a/python/samples/immadm
+++ b/python/samples/immadm
@@ -18,19 +18,19 @@
  
  from optparse import OptionParser
  from pyosaf import saImm
-from pyosaf.saImmOm import *
+from pyosaf.utils import immom, SafException
  from socket import gethostname
  from os import getpid
-from immbase import *
+from pyosaf.saAis import eSaAisErrorT, SaAisErrorT
  import json
  import sys
  
  from pyosaf.utils.log.logger import SafLogger
  
-def getExecName():
+def get_exec_name():
        return ':'.join((gethostname(), sys.argv[0], str(getpid())))
  
-def parseArgs(cmd=sys.argv[1:]):
+def parse_args(cmd=sys.argv[1:]):
        usage = 'usage: %prog [options] OP_ID object_dn'
        epilog = '\nOP_ID: an integer, dependent on the class of object.\n'\
                        '\nTYPE: one of:\n%s\n' % 
'\n'.join(saImm.eSaImmValueTypeT.lookup.keys())
@@ -38,7 +38,7 @@ def parseArgs(cmd=sys.argv[1:]):
        parser = OptionParser(usage=usage, epilog=epilog)
        parser.add_option('-a', '--admin-owner', dest='adminOwner',
                        help='Name denoting owner of the operation.',
-                       metavar='OWNERNAME', default=getExecName())
+                       metavar='OWNERNAME', default=get_exec_name())
        parser.add_option('-p', '--param', dest='params',
                        help='parameters to admin operation.',
                        metavar='NAME:TYPE:VAL', action='append', default=[])
@@ -46,66 +46,48 @@ def parseArgs(cmd=sys.argv[1:]):
                        help='turn off pretty printing.',
                        action='store_true', default=False)
        (options, args) = parser.parse_args(cmd)
+
        if len(args) < 2:
                parser.print_help()
                sys.exit()
+
        return options, args
  
  def immadm(options, args):
+
        if len(args) < 2:
                raise SafException(eSaAisErrorT.SA_AIS_ERR_INIT)
-       opId = SaImmAdminOperationIdT(int(args[0]))
-       dn = SaNameT(args[1])
-       retVal = SaAisErrorT(eSaAisErrorT.SA_AIS_ERR_NOT_EXIST)
+
+        op_id = int(args[0])
+        dn = args[1]
+        ret_val = SaAisErrorT(eSaAisErrorT.SA_AIS_OK)
  
        try:
-               immHandle = SaImmHandleT()
-               rc = saImmOmInitialize(immHandle, None, IMM_VERSION)
-               if rc != eSaAisErrorT.SA_AIS_OK:
-                       raise SafException(rc)
+               params = []
+               for param in options.params:
+                       (name, type, val) = param.split(':', 2)
+                       ptype = saImm.eSaImmValueTypeT.lookup[type]
+                       params.append(
+                               saImm.SaImmAdminOperationParamsT_2(name,
+                                                                   ptype,
+                                                                   val))
  
-               ownerName = SaImmAdminOwnerNameT(options.adminOwner)
-               ownerHandle = SaImmAdminOwnerHandleT()
-               rc = saImmOmAdminOwnerInitialize(immHandle,
-                               ownerName, eSaBoolT.SA_TRUE, ownerHandle)
-               if rc != eSaAisErrorT.SA_AIS_OK:
-                       raise SafException(rc)
+                immom.admin_op_invoke(dn, op_id, params=params)
  
-               rc = saImmOmAdminOwnerSet(ownerHandle,
-                               [dn], saImm.eSaImmScopeT.SA_IMM_ONE)
-               if rc != eSaAisErrorT.SA_AIS_OK:
-                       raise SafException(rc)
+       except SafException as err:
+               if err.value != eSaAisErrorT.SA_AIS_ERR_NOT_EXIST:
+                       raise err
  
-               params = []
-               for p in options.params:
-                       (name, type, val) = p.split(':', 2)
-                       ptype = eSaImmValueTypeT.lookup[type]
-                       params.append(
-                               SaImmAdminOperationParamsT_2(name, ptype, val))
-               contId = SaImmContinuationIdT()
-               rc = saImmOmAdminOperationInvoke_2(ownerHandle,
-                               dn, contId, opId, params, retVal,
-                               saAis.SA_TIME_ONE_SECOND*5)
-               if rc != eSaAisErrorT.SA_AIS_OK:
-                       raise SafException(rc)
-       except SafException, e:
-               if e.value != eSaAisErrorT.SA_AIS_ERR_NOT_EXIST:
-                       raise e
-       finally:
-               saImmOmAdminOwnerRelease(ownerHandle,
-                               [dn], saImm.eSaImmScopeT.SA_IMM_ONE)
-               saImmOmAdminOwnerFinalize(ownerHandle)
-               saImmOmFinalize(immHandle)
-
-       return {'opId': opId.value,
-               'dname': args[1],
-               'owner': options.adminOwner,
+       return {'opId':   op_id,
+               'dname':  args[1],
+               'owner':  options.adminOwner,
                'params': options.params,
-               'rc': eSaAisErrorT.whatis(retVal.value)}
+               'rc':     eSaAisErrorT.whatis(ret_val.value)}
  
  if __name__ == '__main__':
-       (options, args) = parseArgs()
+       (options, args) = parse_args()
        result = immadm(options, args)
        logger = SafLogger(result['owner'])
        logger.log('ADMIN_CMD: OP_ID %(opId)s %(dname)s: %(rc)s' % result)
+
        print json.dumps(result, indent=None if options.ugly else 4)
diff --git a/python/samples/immlist b/python/samples/immlist
--- a/python/samples/immlist
+++ b/python/samples/immlist
@@ -16,12 +16,13 @@
  #
  ############################################################################
  
+from pyosaf import saImm
+from pyosaf.utils import immom
  from optparse import OptionParser
-from immbase import *
  import json
  import sys
  
-def parseArgs(cmd=sys.argv[1:]):
+def parse_args(cmd=sys.argv[1:]):
        usage = 'usage: %prog [options] object_dn [object_dn ..]'
        parser = OptionParser(usage)
        parser.add_option('-a', '--attr', dest='attr',
@@ -42,36 +43,24 @@ class ListOptions(object):
                self.ugly = False
  
  def immlist(options, args):
-       try:
-               immHandle = SaImmHandleT()
-               rc = saImmOmInitialize(immHandle, None, IMM_VERSION)
-               if rc != eSaAisErrorT.SA_AIS_OK:
-                       raise SafException(rc)
+        objects = {}
  
-               accessorHandle = SaImmAccessorHandleT()
-               rc = saImmOmAccessorInitialize(immHandle, accessorHandle)
-               if rc != eSaAisErrorT.SA_AIS_OK:
-                       raise SafException(rc)
+        for dn in args:
+                obj = immom.get(dn, attr_name_list=options.attr)
  
-               objects = {}
-               attribNames = [SaImmAttrNameT(a) for a in options.attr]\
-                               if options.attr else None
-               attribs = pointer(pointer(SaImmAttrValuesT_2()))
-               for dn in args:
-                       rc = saImmOmAccessorGet_2(accessorHandle,
-                                       SaNameT(dn), attribNames, attribs)
-                       if rc == eSaAisErrorT.SA_AIS_ERR_NOT_EXIST:
-                               continue;
-                       if rc != eSaAisErrorT.SA_AIS_OK:
-                               raise SafException(rc)
-                       objects[dn] = SafObject(dn, attribs, options.numeric)
-       finally:
-               saImmOmAccessorFinalize(accessorHandle)
-               saImmOmFinalize(immHandle)
-       return objects
+                if obj:
+                        attributes = {}
+                        for name, value_pair in obj.attrs.iteritems():
+                                type_str = 
saImm.eSaImmValueTypeT.whatis(value_pair[0])
+                                value = value_pair[1]
+
+                                attributes[name] = [type_str, value]
+
+                        objects[dn] = attributes
+
+        return objects
  
  if __name__ == '__main__':
-       (options, args) = parseArgs()
-       print json.dumps(immlist(options, args),
-                       default=SafObject.serialize,
-                       indent=None if options.ugly else 4)
+       (options, args) = parse_args()
+        print json.dumps(immlist(options, args),
+                         indent=None if options.ugly else 4)


------------------------------------------------------------------------------
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to