|
@@ -42,20 +42,20 @@ class TestPythonExecutor(TestCase):
|
|
executor = PythonExecutor("/tmp", AmbariConfig().getConfig())
|
|
executor = PythonExecutor("/tmp", AmbariConfig().getConfig())
|
|
_, tmpoutfile = tempfile.mkstemp()
|
|
_, tmpoutfile = tempfile.mkstemp()
|
|
_, tmperrfile = tempfile.mkstemp()
|
|
_, tmperrfile = tempfile.mkstemp()
|
|
- executor.PYTHON_TIMEOUT_SECONDS = 0.1
|
|
|
|
|
|
+ PYTHON_TIMEOUT_SECONDS = 0.1
|
|
kill_process_with_children_mock.side_effect = lambda pid : subproc_mock.terminate()
|
|
kill_process_with_children_mock.side_effect = lambda pid : subproc_mock.terminate()
|
|
|
|
|
|
- def lauch_python_subprocess_method(command, tmpout, tmperr):
|
|
|
|
|
|
+ def launch_python_subprocess_method(command, tmpout, tmperr):
|
|
subproc_mock.tmpout = tmpout
|
|
subproc_mock.tmpout = tmpout
|
|
subproc_mock.tmperr = tmperr
|
|
subproc_mock.tmperr = tmperr
|
|
return subproc_mock
|
|
return subproc_mock
|
|
- executor.lauch_python_subprocess = lauch_python_subprocess_method
|
|
|
|
|
|
+ executor.launch_python_subprocess = launch_python_subprocess_method
|
|
runShellKillPgrp_method = MagicMock()
|
|
runShellKillPgrp_method = MagicMock()
|
|
runShellKillPgrp_method.side_effect = lambda python : python.terminate()
|
|
runShellKillPgrp_method.side_effect = lambda python : python.terminate()
|
|
executor.runShellKillPgrp = runShellKillPgrp_method
|
|
executor.runShellKillPgrp = runShellKillPgrp_method
|
|
subproc_mock.returncode = None
|
|
subproc_mock.returncode = None
|
|
- thread = Thread(target = executor.run_file, args = ("fake_command",
|
|
|
|
- "fake_puppetFile", tmpoutfile, tmperrfile))
|
|
|
|
|
|
+ thread = Thread(target = executor.run_file, args = ("fake_puppetFile", ["arg1", "arg2"],
|
|
|
|
+ tmpoutfile, tmperrfile, PYTHON_TIMEOUT_SECONDS))
|
|
thread.start()
|
|
thread.start()
|
|
time.sleep(0.1)
|
|
time.sleep(0.1)
|
|
subproc_mock.finished_event.wait()
|
|
subproc_mock.finished_event.wait()
|
|
@@ -70,19 +70,19 @@ class TestPythonExecutor(TestCase):
|
|
executor = PythonExecutor("/tmp", AmbariConfig().getConfig())
|
|
executor = PythonExecutor("/tmp", AmbariConfig().getConfig())
|
|
_, tmpoutfile = tempfile.mkstemp()
|
|
_, tmpoutfile = tempfile.mkstemp()
|
|
_, tmperrfile = tempfile.mkstemp()
|
|
_, tmperrfile = tempfile.mkstemp()
|
|
- executor.PYTHON_TIMEOUT_SECONDS = 5
|
|
|
|
|
|
+ PYTHON_TIMEOUT_SECONDS = 5
|
|
|
|
|
|
- def lauch_python_subprocess_method(command, tmpout, tmperr):
|
|
|
|
|
|
+ def launch_python_subprocess_method(command, tmpout, tmperr):
|
|
subproc_mock.tmpout = tmpout
|
|
subproc_mock.tmpout = tmpout
|
|
subproc_mock.tmperr = tmperr
|
|
subproc_mock.tmperr = tmperr
|
|
return subproc_mock
|
|
return subproc_mock
|
|
- executor.lauch_python_subprocess = lauch_python_subprocess_method
|
|
|
|
|
|
+ executor.launch_python_subprocess = launch_python_subprocess_method
|
|
runShellKillPgrp_method = MagicMock()
|
|
runShellKillPgrp_method = MagicMock()
|
|
runShellKillPgrp_method.side_effect = lambda python : python.terminate()
|
|
runShellKillPgrp_method.side_effect = lambda python : python.terminate()
|
|
executor.runShellKillPgrp = runShellKillPgrp_method
|
|
executor.runShellKillPgrp = runShellKillPgrp_method
|
|
subproc_mock.returncode = 0
|
|
subproc_mock.returncode = 0
|
|
- thread = Thread(target = executor.run_file, args = ("fake_command",
|
|
|
|
- "fake_puppetFile", tmpoutfile, tmperrfile))
|
|
|
|
|
|
+ thread = Thread(target = executor.run_file, args = ("fake_puppetFile", ["arg1", "arg2"],
|
|
|
|
+ tmpoutfile, tmperrfile, PYTHON_TIMEOUT_SECONDS))
|
|
thread.start()
|
|
thread.start()
|
|
time.sleep(0.1)
|
|
time.sleep(0.1)
|
|
subproc_mock.should_finish_event.set()
|
|
subproc_mock.should_finish_event.set()
|
|
@@ -96,19 +96,19 @@ class TestPythonExecutor(TestCase):
|
|
executor = PythonExecutor("/tmp", AmbariConfig().getConfig())
|
|
executor = PythonExecutor("/tmp", AmbariConfig().getConfig())
|
|
_, tmpoutfile = tempfile.mkstemp()
|
|
_, tmpoutfile = tempfile.mkstemp()
|
|
_, tmperrfile = tempfile.mkstemp()
|
|
_, tmperrfile = tempfile.mkstemp()
|
|
- executor.PYTHON_TIMEOUT_SECONDS = 5
|
|
|
|
|
|
+ PYTHON_TIMEOUT_SECONDS = 5
|
|
|
|
|
|
- def lauch_python_subprocess_method(command, tmpout, tmperr):
|
|
|
|
|
|
+ def launch_python_subprocess_method(command, tmpout, tmperr):
|
|
subproc_mock.tmpout = tmpout
|
|
subproc_mock.tmpout = tmpout
|
|
subproc_mock.tmperr = tmperr
|
|
subproc_mock.tmperr = tmperr
|
|
return subproc_mock
|
|
return subproc_mock
|
|
- executor.lauch_python_subprocess = lauch_python_subprocess_method
|
|
|
|
|
|
+ executor.launch_python_subprocess = launch_python_subprocess_method
|
|
runShellKillPgrp_method = MagicMock()
|
|
runShellKillPgrp_method = MagicMock()
|
|
runShellKillPgrp_method.side_effect = lambda python : python.terminate()
|
|
runShellKillPgrp_method.side_effect = lambda python : python.terminate()
|
|
executor.runShellKillPgrp = runShellKillPgrp_method
|
|
executor.runShellKillPgrp = runShellKillPgrp_method
|
|
subproc_mock.returncode = 0
|
|
subproc_mock.returncode = 0
|
|
subproc_mock.should_finish_event.set()
|
|
subproc_mock.should_finish_event.set()
|
|
- result = executor.run_file("command", "file", tmpoutfile, tmperrfile)
|
|
|
|
|
|
+ result = executor.run_file("file", ["arg1", "arg2"], tmpoutfile, tmperrfile, PYTHON_TIMEOUT_SECONDS)
|
|
self.assertEquals(result, {'exitcode': 0, 'stderr': 'Dummy err', 'stdout': 'Dummy output'})
|
|
self.assertEquals(result, {'exitcode': 0, 'stderr': 'Dummy err', 'stdout': 'Dummy output'})
|
|
|
|
|
|
|
|
|