mirror of
https://github.com/ceph/ceph
synced 2025-01-14 23:12:52 +00:00
b386f5e5df
RemoteProcess behaves more like subprocess.Popen, with some important differences. A summary of the API changes: * RemoteProcess.exitstatus is either an int or None; it is never a callable nor a gevent.AsyncResult. * New method: RemoteProcess.execute() * New method: RemoteProcess.poll() * New method: RemoteProcess.wait() * New attribute: RemoteProcess.returncode - alias to exitstatus * New property: RemoteProcess.finished - added because returncode can be None if the connection was interrupted * run.execute() is removed. Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
import fudge
|
|
import fudge.inspector
|
|
|
|
from .. import remote
|
|
from ..run import RemoteProcess
|
|
|
|
|
|
class TestRemote(object):
|
|
def test_shortname(self):
|
|
r = remote.Remote(
|
|
name='jdoe@xyzzy.example.com',
|
|
shortname='xyz',
|
|
ssh=fudge.Fake('SSHConnection'),
|
|
)
|
|
assert r.shortname == 'xyz'
|
|
assert str(r) == 'jdoe@xyzzy.example.com'
|
|
|
|
def test_shortname_default(self):
|
|
r = remote.Remote(
|
|
name='jdoe@xyzzy.example.com',
|
|
ssh=fudge.Fake('SSHConnection'),
|
|
)
|
|
assert r.shortname == 'xyzzy'
|
|
assert str(r) == 'jdoe@xyzzy.example.com'
|
|
|
|
@fudge.with_fakes
|
|
def test_run(self):
|
|
fudge.clear_expectations()
|
|
ssh = fudge.Fake('SSHConnection')
|
|
ssh.expects('get_transport').returns_fake().expects('getpeername')\
|
|
.returns(('name', 22))
|
|
run = fudge.Fake('run')
|
|
args = [
|
|
'something',
|
|
'more',
|
|
]
|
|
foo = object()
|
|
ret = RemoteProcess(
|
|
client=ssh,
|
|
args='fakey',
|
|
)
|
|
r = remote.Remote(name='jdoe@xyzzy.example.com', ssh=ssh)
|
|
run.expects_call().with_args(
|
|
client=fudge.inspector.arg.passes_test(lambda v: v is ssh),
|
|
args=fudge.inspector.arg.passes_test(lambda v: v is args),
|
|
foo=fudge.inspector.arg.passes_test(lambda v: v is foo),
|
|
name=r.shortname,
|
|
).returns(ret)
|
|
# monkey patch ook ook
|
|
r._runner = run
|
|
got = r.run(
|
|
args=args,
|
|
foo=foo,
|
|
)
|
|
assert got is ret
|
|
assert got.remote is r
|