Hi,

automember-rebuild uses asynchronous 389 task, and returned success
even if the task didn't run. This patch fixes this issue adding a
--nowait parameter to 'ipa automember-rebuild', defaulting to False,
thus when the script runs without it, it waits for the 'nstaskexitcode'
attribute, which means the task has finished, according to
http://directory.fedoraproject.org/wiki/Task_Invocation_Via_LDAP#Implementation.
Old usage can be enabled using --nowait.

https://fedorahosted.org/freeipa/ticket/4239

Request for comments:
- Should I add a parameter to specify the polling time? (now 1ms)
- Should I add a parameter to specify the maximum polling number? Now
  if something fails about creating the task, it polls forever.
- Obviously, if these parameters should be added, there should be a
  reasonable default for them (~ Required=False, Default=X).

Thanks,
Adam
>From 62215a10a826d9e529ac861b40c1f1bf68823472 Mon Sep 17 00:00:00 2001
From: Adam Misnyovszki <amisn...@redhat.com>
Date: Fri, 14 Mar 2014 17:22:09 +0100
Subject: [PATCH] automember rebuild nowait feature added

automember-rebuild uses asynchronous 389 task, and returned success even if the task didn't run. this patch fixes this issue adding a --nowait parameter to 'ipa automember-rebuild', defaulting to False, thus when the script runs without it, it waits for the 'nstaskexitcode' attribute, which means the task has finished. Old usage can be enabled using --nowait.

https://fedorahosted.org/freeipa/ticket/4239
---
 ipalib/plugins/automember.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/ipalib/plugins/automember.py b/ipalib/plugins/automember.py
index a12bfb52522e38bc083d0750dc66c894a4aeba53..1f36b36b63bf94345f48e18867dbdd3316d6ecb0 100644
--- a/ipalib/plugins/automember.py
+++ b/ipalib/plugins/automember.py
@@ -17,6 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 import uuid
+import time
 import ldap as _ldap
 from ipalib import api, errors, Str, StrEnum, _, ngettext
 from ipalib.plugins.baseldap import *
@@ -623,6 +624,13 @@ class automember_rebuild(Command):
             label=_('Hosts'),
             doc=_('Rebuild membership for specified hosts'),
         ),
+        Flag(
+            'nowait',
+            required=False,
+            default=False,
+            label=_('No wait'),
+            doc=_('Don\'t wait for rebuilding membership'),
+        ),
     )
     has_output = output.standard_value
     msg_summary = _('Automember rebuild membership task completed')
@@ -707,6 +715,23 @@ class automember_rebuild(Command):
             scope=['sub']
         )
         ldap.add_entry(entry)
+
+        while options.get('nowait'):
+            tasks = ldap.get_entries(
+                DN(
+                    ('cn', cn),
+                    ('cn', 'automember rebuild membership'),
+                    ('cn', 'tasks'),
+                    ('cn', 'config'),
+                ),
+            )
+
+            if len(tasks) > 0:
+                task = tasks[0]
+                if 'nstaskexitcode' in task.single_value:
+                    return dict(result=task.single_value['nstaskexitcode'] == '0', value=unicode(task.single_value['nstaskexitcode']))
+            time.sleep(0.001)
+
         return dict(result=True, value=u'')
 
 api.register(automember_rebuild)
-- 
1.8.5.3

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to