]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Add Remote.host_key
authorZack Cerza <zack.cerza@inktank.com>
Mon, 8 Sep 2014 15:55:22 +0000 (09:55 -0600)
committerZack Cerza <zack.cerza@inktank.com>
Thu, 11 Sep 2014 21:12:52 +0000 (15:12 -0600)
Turns out we can easily grab the ssh key from paramiko once a connection
is established.

Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/orchestra/remote.py
teuthology/orchestra/test/test_remote.py

index a8363e031dd85c12a0d5c6bcd4daadb2fa6f8bc9..7d4c145085fde785f4137029b643d4cfc8f158f8 100644 (file)
@@ -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):
     """
index d0dcf27c661feebad70f83dd7426c3526c09d1be..79e0221489d7d6aa2fb05a62b3b91688a06fe732 100644 (file)
@@ -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("""