def test__run_command_exit_add_to_badhosts(mock_ctx): """It updates the list of badhosts """ badhosts = {'foo', 'bar'} SubProcPool._run_command_exit(mock_ctx(cmd=['ssh']), bad_hosts=badhosts, callback=print, callback_args=['Welcome to Magrathea']) assert badhosts == {'foo', 'bar', 'mouse'}
def test__run_command_exit_no_255_args(caplog, mock_ctx): """It runs the 255 callback with the args of the callback if no callback 255 args provided. """ SubProcPool._run_command_exit(mock_ctx(cmd=['ssh', 'Zaphod']), callback=_test_callback, callback_args=['Zaphod'], callback_255=_test_callback_255) assert '255' in caplog.records[1].msg
def test__run_command_exit(caplog, mock_ctx, expect, ret_code, cmd_key): """It runs a callback """ ctx = mock_ctx(ret_code=ret_code, cmd_key=cmd_key, cmd=['ssh']) SubProcPool._run_command_exit(ctx, callback=_test_callback, callback_255=_test_callback_255) assert expect in caplog.records[0].msg if ret_code == 255: assert f'255 callback called.' in caplog.records[1].msg
def test__run_command_exit_rsync_fails(mock_ctx): """It updates the list of badhosts """ badhosts = {'foo', 'bar'} ctx = mock_ctx(cmd=['rsync'], ret_code=42, cmd_key='file-install') SubProcPool._run_command_exit( ctx=ctx, bad_hosts=badhosts, callback=print, callback_args=['Welcome to Magrathea', {'ssh command': 'ssh'}] ) assert badhosts == {'foo', 'bar', 'mouse'}
def test__run_command_exit_no_255_callback(caplog, mock_ctx): """It runs the vanilla callback if no 255 callback provided""" SubProcPool._run_command_exit(mock_ctx(), callback=_test_callback) assert 'callback called' in caplog.records[0].msg