]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
move ssh_keyscan from lock.py to misc.py 531/head
authorLoic Dachary <ldachary@redhat.com>
Sun, 14 Jun 2015 13:45:32 +0000 (15:45 +0200)
committerLoic Dachary <ldachary@redhat.com>
Fri, 19 Jun 2015 11:00:31 +0000 (13:00 +0200)
Because it may be used by provision.py

Signed-off-by: Loic Dachary <loic@dachary.org>
teuthology/lock.py
teuthology/misc.py
teuthology/task/internal.py

index 9b5796669afcd5b4f9521e86b4aa68d97b6a6966..b7430c68d2613f0635186f23b9de8a91a07f1573 100644 (file)
@@ -638,33 +638,6 @@ def update_inventory(node_dict):
     return response.ok
 
 
-def ssh_keyscan(hostnames):
-    """
-    Fetch the SSH public key of one or more hosts
-    """
-    if isinstance(hostnames, basestring):
-        raise TypeError("'hostnames' must be a list")
-    hostnames = [misc.canonicalize_hostname(name, user=None) for name in
-                 hostnames]
-    args = ['ssh-keyscan', '-T', '1', '-t', 'rsa'] + hostnames
-    p = subprocess.Popen(
-        args=args,
-        stdout=subprocess.PIPE,
-        stderr=subprocess.PIPE,
-    )
-    p.wait()
-
-    keys_dict = dict()
-    for line in p.stderr.readlines():
-        line = line.strip()
-        if line and not line.startswith('#'):
-            log.error(line)
-    for line in p.stdout.readlines():
-        host, key = line.strip().split(' ', 1)
-        keys_dict[host] = key
-    return keys_dict
-
-
 def updatekeys(args):
     loglevel = logging.DEBUG if args['--verbose'] else logging.INFO
     logging.basicConfig(
@@ -690,7 +663,7 @@ def do_update_keys(machines, all_=False):
     reference = list_locks(keyed_by_name=True)
     if all_:
         machines = reference.keys()
-    keys_dict = ssh_keyscan(machines)
+    keys_dict = misc.ssh_keyscan(machines)
     return push_new_keys(keys_dict, reference)
 
 
index b27041e70137b53256bbc1eb9a7d951849cc618c..6f3d70e3c5e9f92cbf2a189e38be2697316644bd 100644 (file)
@@ -10,6 +10,7 @@ import logging
 import configobj
 import getpass
 import socket
+import subprocess
 import sys
 import tarfile
 import time
@@ -1119,6 +1120,33 @@ def get_valgrind_args(testdir, name, preamble, v):
     return args
 
 
+def ssh_keyscan(hostnames):
+    """
+    Fetch the SSH public key of one or more hosts
+    """
+    if isinstance(hostnames, basestring):
+        raise TypeError("'hostnames' must be a list")
+    hostnames = [canonicalize_hostname(name, user=None) for name in
+                 hostnames]
+    args = ['ssh-keyscan', '-T', '1', '-t', 'rsa'] + hostnames
+    p = subprocess.Popen(
+        args=args,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE,
+    )
+    p.wait()
+
+    keys_dict = dict()
+    for line in p.stderr.readlines():
+        line = line.strip()
+        if line and not line.startswith('#'):
+            log.error(line)
+    for line in p.stdout.readlines():
+        host, key = line.strip().split(' ', 1)
+        keys_dict[host] = key
+    return keys_dict
+
+
 def stop_daemons_of_type(ctx, type_):
     """
     :param type_: type of daemons to be stopped.
index 8c7de33c0386a9cab04d775f69b218c616b4f80f..171c4e2a78b5ee490193eca9ddd86280a1f22190 100644 (file)
@@ -130,7 +130,7 @@ def lock_machines(ctx, config):
                 while len(keys_dict) != len(vmlist):
                     loopcount += 1
                     time.sleep(10)
-                    keys_dict = lock.ssh_keyscan(vmlist)
+                    keys_dict = misc.ssh_keyscan(vmlist)
                     log.info('virtual machine is still unavailable')
                     if loopcount == 40:
                         loopcount = 0