@fudge.with_fakes
def test_run_log_simple():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
cmd = ssh.expects('exec_command')
cmd.with_args("foo 'bar baz'")
in_ = fudge.Fake('ChannelFile(stdin)')
logger = fudge.Fake('logger')
log_err = fudge.Fake('log_err')
logger.expects('getChild').with_args('err').returns(log_err)
- log_err.expects('log').with_args(logging.INFO, 'bad')
+ log_err.expects('log').with_args(logging.INFO, '[HOST]: bad')
log_out = fudge.Fake('log_out')
logger.expects('getChild').with_args('out').returns(log_out)
- log_out.expects('log').with_args(logging.INFO, 'foo')
- log_out.expects('log').with_args(logging.INFO, 'bar')
+ log_out.expects('log').with_args(logging.INFO, '[HOST]: foo')
+ log_out.expects('log').with_args(logging.INFO, '[HOST]: bar')
channel = fudge.Fake('channel')
out.has_attr(channel=channel)
channel.expects('recv_exit_status').with_args().returns(0)
@fudge.with_fakes
def test_run_capture_stdout():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
cmd = ssh.expects('exec_command')
cmd.with_args("foo 'bar baz'")
in_ = fudge.Fake('ChannelFile(stdin)')
logger = fudge.Fake('logger')
log_err = fudge.Fake('log_err')
logger.expects('getChild').with_args('err').returns(log_err)
- log_err.expects('log').with_args(logging.INFO, 'bad')
+ log_err.expects('log').with_args(logging.INFO, '[HOST]: bad')
channel = fudge.Fake('channel')
out.has_attr(channel=channel)
channel.expects('recv_exit_status').with_args().returns(0)
@fudge.with_fakes
def test_run_status_bad():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
cmd = ssh.expects('exec_command')
cmd.with_args("foo")
in_ = fudge.Fake('ChannelFile').is_a_stub()
)
eq(e.command, 'foo')
eq(e.exitstatus, 42)
- eq(str(e), "Command failed with status 42: 'foo'")
+ eq(str(e), "Command failed on HOST with status 42: 'foo'")
@nose.with_setup(fudge.clear_expectations)
@fudge.with_fakes
def test_run_status_bad_nocheck():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
cmd = ssh.expects('exec_command')
cmd.with_args("foo")
in_ = fudge.Fake('ChannelFile').is_a_stub()
@fudge.with_fakes
def test_run_status_crash():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
+ transport.expects('is_active').with_args().returns(True)
cmd = ssh.expects('exec_command')
cmd.with_args("foo")
in_ = fudge.Fake('ChannelFile').is_a_stub()
channel = fudge.Fake('channel')
out.has_attr(channel=channel)
channel.expects('recv_exit_status').with_args().returns(-1)
- transport = ssh.expects('get_transport').with_args().returns_fake()
- transport.expects('is_active').with_args().returns(True)
e = assert_raises(
run.CommandCrashedError,
run.run,
@fudge.with_fakes
def test_run_status_crash_nocheck():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
cmd = ssh.expects('exec_command')
cmd.with_args("foo")
in_ = fudge.Fake('ChannelFile').is_a_stub()
out.has_attr(channel=channel)
channel.expects('recv_exit_status').with_args().returns(-1)
transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
transport.expects('is_active').with_args().returns(False)
e = assert_raises(
run.ConnectionLostError,
@fudge.with_fakes
def test_run_status_lost_nocheck():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
cmd = ssh.expects('exec_command')
cmd.with_args("foo")
in_ = fudge.Fake('ChannelFile').is_a_stub()
@fudge.with_fakes
def test_run_nowait():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
cmd = ssh.expects('exec_command')
cmd.with_args("foo")
in_ = fudge.Fake('ChannelFile').is_a_stub()
r.exitstatus.get,
)
eq(e.exitstatus, 42)
- eq(str(e), "Command failed with status 42: 'foo'")
+ eq(str(e), "Command failed on HOST with status 42: 'foo'")
@nose.with_setup(fudge.clear_expectations)
@fudge.with_fakes
def test_run_stdin_pipe():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
cmd = ssh.expects('exec_command')
cmd.with_args("foo")
in_ = fudge.Fake('ChannelFile').is_a_stub()
@fudge.with_fakes
def test_run_stdout_pipe():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
cmd = ssh.expects('exec_command')
cmd.with_args("foo")
in_ = fudge.Fake('ChannelFile').is_a_stub()
@fudge.with_fakes
def test_run_stderr_pipe():
ssh = fudge.Fake('SSHConnection')
+ transport = ssh.expects('get_transport').with_args().returns_fake()
+ transport.expects('getpeername').with_args().returns(('HOST', 22))
cmd = ssh.expects('exec_command')
cmd.with_args("foo")
in_ = fudge.Fake('ChannelFile').is_a_stub()