From d0630f76519efc209c4139bf54b64ea0c1e59319 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 5 Sep 2014 09:32:33 -0600 Subject: [PATCH] Add Remote.arch Returns the result of 'uname -p' Signed-off-by: Zack Cerza --- teuthology/orchestra/remote.py | 8 ++++++ teuthology/orchestra/test/test_remote.py | 35 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/teuthology/orchestra/remote.py b/teuthology/orchestra/remote.py index 6d68365729..e7f7a61ac3 100644 --- a/teuthology/orchestra/remote.py +++ b/teuthology/orchestra/remote.py @@ -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): """ diff --git a/teuthology/orchestra/test/test_remote.py b/teuthology/orchestra/test/test_remote.py index a2a32676d7..8dd00191d6 100644 --- a/teuthology/orchestra/test/test_remote.py +++ b/teuthology/orchestra/test/test_remote.py @@ -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(""" -- 2.39.5