From: Zack Cerza Date: Mon, 8 Sep 2014 15:55:22 +0000 (-0600) Subject: Add Remote.host_key X-Git-Tag: 1.1.0~1174 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=58cbb236e46212a2c1d6920198b3219ccd0cd78e;p=teuthology.git Add Remote.host_key Turns out we can easily grab the ssh key from paramiko once a connection is established. Signed-off-by: Zack Cerza --- diff --git a/teuthology/orchestra/remote.py b/teuthology/orchestra/remote.py index a8363e031..7d4c14508 100644 --- a/teuthology/orchestra/remote.py +++ b/teuthology/orchestra/remote.py @@ -44,14 +44,14 @@ class Remote(object): self.user = pwd.getpwuid(os.getuid()).pw_name hostname = name self._shortname = shortname or hostname.split('.')[0] - self.host_key = host_key + self._host_key = host_key self.keep_alive = keep_alive self.console = console self.ssh = ssh or self.connect() def connect(self): self.ssh = connection.connect(user_at_host=self.name, - host_key=self.host_key, + host_key=self._host_key, keep_alive=self.keep_alive) return self.ssh @@ -260,6 +260,14 @@ class Remote(object): self._arch = proc.stdout.getvalue().strip() return self._arch + @property + def host_key(self): + if not self._host_key: + trans = self.ssh.get_transport() + key = trans.get_remote_server_key() + self._host_key = ' '.join((key.get_name(), key.get_base64())) + return self._host_key + class Distribution(object): """ diff --git a/teuthology/orchestra/test/test_remote.py b/teuthology/orchestra/test/test_remote.py index d0dcf27c6..79e022148 100644 --- a/teuthology/orchestra/test/test_remote.py +++ b/teuthology/orchestra/test/test_remote.py @@ -70,9 +70,7 @@ class TestRemote(object): '--fqdn', ] stdout = StringIO('test_hostname') - print repr(stdout) stdout.seek(0) - print repr(stdout) ret = RemoteProcess( client=ssh, args='fakey', @@ -128,6 +126,17 @@ class TestRemote(object): r._runner = run assert r.arch == 'test_arch' + @fudge.with_fakes + def test_host_key(self): + fudge.clear_expectations() + ssh = fudge.Fake('SSHConnection') + key = ssh.expects('get_transport').returns_fake().expects( + 'get_remote_server_key').returns_fake() + key.expects('get_name').returns('key_type') + key.expects('get_base64').returns('test ssh key') + r = remote.Remote(name='jdoe@xyzzy.example.com', ssh=ssh) + assert r.host_key == 'key_type test ssh key' + class TestDistribution(object): lsb_centos = dedent("""