script mode testing and fixes

This commit is contained in:
Edwin Eefting
2022-01-28 23:59:50 +01:00
parent 2ffd3baf77
commit e1fb7a37be
3 changed files with 45 additions and 23 deletions

View File

@ -156,17 +156,28 @@ class TestExecuteNode(unittest2.TestCase):
self.assertEqual(nodeb.run(cmd=["pwd", ExecuteNode.PIPE, "cat"], cwd="/tmp/space test"), ["/tmp/space test"])
self.assertEqual(nodeb.run(cmd=["cat", ExecuteNode.PIPE, "pwd"], cwd="/tmp/space test"), ["/tmp/space test"])
# #
# def test_script(self):
#
# def stdout_handler(line):
# print("handle: " + line)
#
# nodea=ExecuteNode(debug_output=True, ssh_to="localhost")
#
# cmd_pipe=nodea.script(lines=["echo line1", "echo line 2"], stdout_handler=stdout_handler)
# cmd_pipe.execute()
def test_script_handlers(self):
results=[]
nodea=ExecuteNode(debug_output=True)
cmd_pipe=nodea.script(lines=["echo line1", "echo line2 1>&2", "exit 123"],
stdout_handler=lambda line: results.append(line),
stderr_handler=lambda line: results.append(line),
exit_handler=lambda exit_code: results.append(exit_code),
valid_exitcodes=[123]
)
cmd_pipe.execute()
self.assertEqual(results, ["line1", "line2", 123 ])
def test_script_defaults(self):
def handler(line):
pass
nodea=ExecuteNode(debug_output=True, ssh_to="localhost")
cmd_pipe=nodea.script(lines=["echo test"], stdout_handler=handler)
cmd_pipe.execute()