diff --git a/lib/utils.py b/lib/utils.py index 131f4c1a7645bbe99f855befeaf252caed62c2e1..53f5eb234ed6c28934981fb104c0d16c04237e4b 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -2156,15 +2156,15 @@ def GetFilesystemStats(path): return (tsize, fsize) -def RunInSeparateProcess(fn): +def RunInSeparateProcess(fn, *args): """Runs a function in a separate process. Note: Only boolean return values are supported. @type fn: callable @param fn: Function to be called - @rtype: tuple of (int/None, int/None) - @return: Exit code and signal number + @rtype: bool + @return: Function's result """ pid = os.fork() @@ -2175,7 +2175,7 @@ def RunInSeparateProcess(fn): ResetTempfileModule() # Call function - result = int(bool(fn())) + result = int(bool(fn(*args))) assert result in (0, 1) except: # pylint: disable-msg=W0702 logging.exception("Error while calling function in separate process") diff --git a/test/ganeti.utils_unittest.py b/test/ganeti.utils_unittest.py index 8392ad056cc90b009509dd0ec518178a4aacbb29..14954684a71621dda8e0f0b00a684d067bc3c73a 100755 --- a/test/ganeti.utils_unittest.py +++ b/test/ganeti.utils_unittest.py @@ -1200,6 +1200,13 @@ class RunInSeparateProcess(unittest.TestCase): self.assertEqual(exp, utils.RunInSeparateProcess(_child)) + def testArgs(self): + for arg in [0, 1, 999, "Hello World", (1, 2, 3)]: + def _child(carg1, carg2): + return carg1 == "Foo" and carg2 == arg + + self.assert_(utils.RunInSeparateProcess(_child, "Foo", arg)) + def testPid(self): parent_pid = os.getpid()