Please ignore this. I missed the final part of the commit message that actually verifies the fix. I will correct this and re-send.
/ Johan -----Original Message----- From: Johan Mårtensson [mailto:[email protected]] Sent: den 14 juli 2015 11:08 To: Hans Nordebäck; Anders Björnerstedt; [email protected]; Hung Nguyen D Cc: [email protected] Subject: [devel] [PATCH 1 of 1] pyosaf: Add method to pyosaf.utils.immom.ccb.Ccb class to clear admin owner flag for objects affected by CCB [#1418] python/pyosaf/utils/immom/__init__.py | 44 +++++++++++++++++++++++++++++++++++ python/pyosaf/utils/immom/ccb.py | 22 +++++++++++++++++ 2 files changed, 66 insertions(+), 0 deletions(-) Adds a method to the pyosaf.utils.immom.ccb.Ccb class to clear the admin owner flag for any objects it has set the flag for during the CCB. Also creates support functions in the __init__.py file for the pyosaf.utils.immom module. Verify like this (assuming SampleClass1 and sampleClassId=1 exist): from pyosaf.utils.immom.ccb import Ccb from pyosaf.utils.immom.object import ImmObject ccb = Ccb() obj = ImmObject(class_name='SampleClass1', dn='sampleClassId=2,sampleClassId=1') obj.sampleClassId='sampleClassId=2' ccb.create(obj, 'sampleClassId=1') ccb.apply() diff --git a/python/pyosaf/utils/immom/__init__.py b/python/pyosaf/utils/immom/__init__.py --- a/python/pyosaf/utils/immom/__init__.py +++ b/python/pyosaf/utils/immom/__init__.py @@ -194,3 +194,47 @@ def admin_op_invoke(dn, op_id, params=No if error != eSaAisErrorT.SA_AIS_OK: print "saImmOmAdminOwnerFinalize: %s" % eSaAisErrorT.whatis(error) raise SafException(error) + + +def raise_saf_exception(function, error): + ''' Raises an exception for a given SAF function, based on + the given error code + ''' + + error_string = "%s: %s" % (function.__name__, + eSaAisErrorT.whatis(error)) + + raise SafException(error, error_string) + + +def call_saf_function(function, *args): + ''' Calls a function, with the applied arguments, + with retries and sleep between each retry + ''' + + one_sec_sleeps = 0 + + error = function(*args) + + while error == eSaAisErrorT.SA_AIS_ERR_TRY_AGAIN: + if one_sec_sleeps == TRYAGAIN_CNT: + break; + time.sleep(1) + one_sec_sleeps += 1 + + error = function(*args) + + if error != eSaAisErrorT.SA_AIS_OK: + raise_saf_exception(function, error) + + return error + + +def clear_admin_owner(dns, owner_handle): + ''' Clears admin owner for the given DNs ''' + + # Marshall the parameters + object_names = [SaNameT(dn) for dn in dns] + + c_object_names = saAis.marshalNullArray(object_names) + + call_saf_function(saImmOm.saImmOmAdminOwnerClear, owner_handle, + c_object_names) 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 @@ -76,6 +76,8 @@ class Ccb(object): def __init__(self, require_registered_oi=True): self.owner_handle = saImmOm.SaImmAdminOwnerHandleT() + self.objects_to_clear = [] + owner_name = saImmOm.SaImmAdminOwnerNameT("DummyName") one_sec_sleeps = 0 err = saImmOm.saImmOmAdminOwnerInitialize(pyosaf.utils.immom.HANDLE, owner_name, @@ -140,6 +142,9 @@ class Ccb(object): msg = "saImmOmAdminOwnerSet: %s - obj:%s" % \ (_parent_name, eSaAisErrorT.whatis(err)) raise SafException(err, msg) + + self.objects_to_clear.append(parent_name) + else: parent_name = None @@ -175,6 +180,8 @@ class Ccb(object): raise SafException(err, "saImmOmAdminOwnerSet: %s - %s" % \ (_object_name, eSaAisErrorT.whatis(err))) + self.objects_to_clear.append(object_name) + err = saImmOm.saImmOmCcbObjectDelete(self.ccb_handle, object_name) if err != eSaAisErrorT.SA_AIS_OK: raise SafException(err, "saImmOmCcbObjectDelete: %s - %s" % \ @@ -212,6 +219,8 @@ class Ccb(object): raise SafException(err, "saImmOmAdminOwnerSet: %s - %s" % \ (object_name, eSaAisErrorT.whatis(err))) + self.objects_to_clear.append(object_name) + attr_mods = [] attr_mod = saImmOm.SaImmAttrModificationT_2() @@ -263,6 +272,8 @@ class Ccb(object): raise SafException(err, "saImmOmAdminOwnerSet: %s - %s" % \ (object_name, eSaAisErrorT.whatis(err))) + self.objects_to_clear.append(object_name) + attr_mods = [] attr_mod = saImmOm.SaImmAttrModificationT_2() attr_mod.modType = \ @@ -313,6 +324,8 @@ class Ccb(object): raise SafException(err, "saImmOmAdminOwnerSet: %s - %s" % \ (object_name, eSaAisErrorT.whatis(err))) + self.objects_to_clear.append(object_name) + attr_mods = [] attr_mod = saImmOm.SaImmAttrModificationT_2() attr_mod.modType = \ @@ -346,6 +359,15 @@ class Ccb(object): if err != eSaAisErrorT.SA_AIS_OK: raise SafException(err) + def clear_admin_owner(self): + ''' Removes the admin owner role for the objects + it has been set for during the CCB + ''' + + pyosaf.utils.immom.clear_admin_owner(self.objects_to_clear) + + self.objects_to_clear = [] + def test(): ccb = Ccb() ccb.modify("safAmfCluster=myAmfCluster", "saAmfClusterStartupTimeout", ------------------------------------------------------------------------------ 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 ------------------------------------------------------------------------------ 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
