Add Remote.arch

Returns the result of 'uname -p'

Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
This commit is contained in:
Zack Cerza 2014-09-05 09:32:33 -06:00
parent 9593534155
commit d0630f7651
2 changed files with 43 additions and 0 deletions

View File

@ -245,6 +245,14 @@ class Remote(object):
self._distro = Distribution(lsb_info.stdout.getvalue().strip())
return self._distro
@property
def arch(self):
if not hasattr(self, '_arch'):
proc = self.run(args=['uname', '-p'], stdout=StringIO())
proc.wait()
self._arch = proc.stdout.getvalue().strip()
return self._arch
class Distribution(object):
"""

View File

@ -1,6 +1,7 @@
import fudge
import fudge.inspector
from cStringIO import StringIO, OutputType
from textwrap import dedent
from .. import remote
@ -57,6 +58,40 @@ class TestRemote(object):
assert got is ret
assert got.remote is r
@fudge.with_fakes
def test_arch(self):
fudge.clear_expectations()
ssh = fudge.Fake('SSHConnection')
ssh.expects('get_transport').returns_fake().expects('getpeername')\
.returns(('name', 22))
run = fudge.Fake('run')
args = [
'uname',
'-p',
]
stdout = StringIO('test_arch')
stdout.seek(0)
ret = RemoteProcess(
client=ssh,
args='fakey',
)
# status = self._stdout_buf.channel.recv_exit_status()
ret._stdout_buf = fudge.Fake()
ret._stdout_buf.channel = fudge.Fake()
ret._stdout_buf.channel.expects('recv_exit_status').returns(0)
ret.stdout = stdout
r = remote.Remote(name='jdoe@xyzzy.example.com', ssh=ssh)
run.expects_call().with_args(
client=ssh,
args=args,
stdout=fudge.inspector.arg.passes_test(
lambda v: isinstance(v, OutputType)),
name=r.shortname,
).returns(ret)
# monkey patch ook ook
r._runner = run
assert r.arch == 'test_arch'
class TestDistribution(object):
lsb_centos = dedent("""