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:
@@ -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):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user