From f397984b3de0dc30aed20d7ba1d3372815e12c62 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Sun, 14 Jun 2015 15:45:32 +0200 Subject: [PATCH] move ssh_keyscan from lock.py to misc.py Because it may be used by provision.py Signed-off-by: Loic Dachary --- teuthology/lock.py | 29 +---------------------------- teuthology/misc.py | 28 ++++++++++++++++++++++++++++ teuthology/task/internal.py | 2 +- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/teuthology/lock.py b/teuthology/lock.py index 9b5796669a..b7430c68d2 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -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) diff --git a/teuthology/misc.py b/teuthology/misc.py index b27041e701..6f3d70e3c5 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -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. diff --git a/teuthology/task/internal.py b/teuthology/task/internal.py index 8c7de33c03..171c4e2a78 100644 --- a/teuthology/task/internal.py +++ b/teuthology/task/internal.py @@ -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 -- 2.39.5