Add 2 callbacks to processutils.execute()

Add optional on_execute and on_completion callbacks to allow callers of
procesutils.execute() to track process completion asynchronously.

This could be used to cache the pid of long running tasks associated
with an instance and then clear the cache when the process completes.
While the tasks are running should it be required the pid retrieved and
the process can be signaled.

Co-Authored-By: abhishekkekane <abhishek.kekane@nttdata.com>
Change-Id: Ifc23325eddb523f6449ba06a2deb0885a8a7009d
This commit is contained in:
Tony Breeds
2015-06-17 10:33:54 +10:00
parent 4ac9247be5
commit d8307005bf
2 changed files with 32 additions and 0 deletions

View File

@@ -66,6 +66,18 @@ class UtilsTest(test_base.BaseTestCase):
mock_cpu_count):
self.assertEqual(1, processutils.get_worker_count())
def test_execute_with_callback(self):
on_execute_callback = mock.Mock()
on_completion_callback = mock.Mock()
processutils.execute("/bin/true")
self.assertEqual(0, on_execute_callback.call_count)
self.assertEqual(0, on_completion_callback.call_count)
processutils.execute("/bin/true", on_execute=on_execute_callback,
on_completion=on_completion_callback)
self.assertEqual(1, on_execute_callback.call_count)
self.assertEqual(1, on_completion_callback.call_count)
class ProcessExecutionErrorTest(test_base.BaseTestCase):