From: Kyr Shatskyy Date: Mon, 18 Nov 2019 18:30:45 +0000 (+0100) Subject: lock/ops: remove circular import of keys operations X-Git-Tag: 1.1.0~188^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cd28833b958aa64664a38d2edf13251cd40c9e5c;p=teuthology.git lock/ops: remove circular import of keys operations Signed-off-by: Kyr Shatskyy --- diff --git a/teuthology/lock/cli.py b/teuthology/lock/cli.py index 16e28067..b6f6ed00 100644 --- a/teuthology/lock/cli.py +++ b/teuthology/lock/cli.py @@ -13,7 +13,6 @@ from teuthology import misc from teuthology.config import set_config_attr from teuthology.lock import ( - keys, ops, util, query, @@ -88,7 +87,7 @@ def main(ctx): vmachines.append(machine['name']) if vmachines: log.info("updating host keys for %s", ' '.join(sorted(vmachines))) - keys.do_update_keys(vmachines, _raise=False) + ops.do_update_keys(vmachines, _raise=False) # get statuses again to refresh any updated keys statuses = query.get_statuses(machines) if statuses: @@ -179,7 +178,7 @@ def main(ctx): for machine in reimage_machines: p.spawn(teuthology.provision.reimage, ctx, machine) for machine in updatekeys_machines: - keys.do_update_keys([machine]) + ops.do_update_keys([machine]) ops.update_nodes(reimage_machines + machines_to_update) elif ctx.unlock: @@ -286,4 +285,4 @@ def updatekeys(args): for doc in docs: machines = [n for n in doc.get('targets', dict()).keys()] - return keys.do_update_keys(machines, all_)[0] + return ops.do_update_keys(machines, all_)[0] diff --git a/teuthology/lock/keys.py b/teuthology/lock/keys.py index 3ed2f987..a03bb5d1 100644 --- a/teuthology/lock/keys.py +++ b/teuthology/lock/keys.py @@ -2,26 +2,6 @@ import logging from teuthology import misc -from teuthology.lock import ops, query - log = logging.getLogger(__name__) -def do_update_keys(machines, all_=False, _raise=True): - reference = query.list_locks(keyed_by_name=True) - if all_: - machines = reference.keys() - keys_dict = misc.ssh_keyscan(machines, _raise=_raise) - return push_new_keys(keys_dict, reference), keys_dict - - -def push_new_keys(keys_dict, reference): - ret = 0 - for hostname, pubkey in keys_dict.items(): - log.info('Checking %s', hostname) - if reference[hostname]['ssh_pub_key'] != pubkey: - log.info('New key found. Updating...') - if not ops.update_lock(hostname, ssh_pub_key=pubkey): - log.error('failed to update %s!', hostname) - ret = 1 - return ret diff --git a/teuthology/lock/ops.py b/teuthology/lock/ops.py index fc4aed9d..376aa4af 100644 --- a/teuthology/lock/ops.py +++ b/teuthology/lock/ops.py @@ -13,8 +13,7 @@ from teuthology.contextutil import safe_while from teuthology.task import console_log from teuthology.misc import canonicalize_hostname -from teuthology.lock import util -from teuthology.lock import keys +from teuthology.lock import util, query log = logging.getLogger(__name__) @@ -126,7 +125,7 @@ def lock_many(ctx, num, machine_type, user=None, description=None, log.error('Unable to create virtual machine: %s', machine) unlock_one(ctx, machine, user) - ok_machs = keys.do_update_keys(ok_machs.keys())[1] + ok_machs = do_update_keys(ok_machs.keys())[1] update_nodes(ok_machs) return ok_machs elif machine_type in reimage_types: @@ -143,7 +142,7 @@ def lock_many(ctx, num, machine_type, user=None, description=None, for machine in machines: p.spawn(teuthology.provision.reimage, ctx, machine) reimaged[machine] = machines[machine] - reimaged = keys.do_update_keys(reimaged.keys())[1] + reimaged = do_update_keys(reimaged.keys())[1] update_nodes(reimaged) return reimaged return machines @@ -277,3 +276,23 @@ def update_inventory(node_dict): log.error("Node update/creation failed for %s: %s", name, response.text) return response.ok + + +def do_update_keys(machines, all_=False, _raise=True): + reference = query.list_locks(keyed_by_name=True) + if all_: + machines = reference.keys() + keys_dict = misc.ssh_keyscan(machines, _raise=_raise) + return push_new_keys(keys_dict, reference), keys_dict + + +def push_new_keys(keys_dict, reference): + ret = 0 + for hostname, pubkey in keys_dict.items(): + log.info('Checking %s', hostname) + if reference[hostname]['ssh_pub_key'] != pubkey: + log.info('New key found. Updating...') + if not update_lock(hostname, ssh_pub_key=pubkey): + log.error('failed to update %s!', hostname) + ret = 1 + return ret diff --git a/teuthology/task/internal/lock_machines.py b/teuthology/task/internal/lock_machines.py index 1dc2e0a3..bfab80f7 100644 --- a/teuthology/task/internal/lock_machines.py +++ b/teuthology/task/internal/lock_machines.py @@ -3,7 +3,6 @@ import logging import time import yaml -import teuthology.lock.keys import teuthology.lock.ops import teuthology.lock.query import teuthology.lock.util @@ -115,7 +114,7 @@ def lock_machines(ctx, config): full_name = misc.canonicalize_hostname(guest) provision.destroy_if_vm(ctx, full_name) provision.create_if_vm(ctx, full_name) - if teuthology.lock.keys.do_update_keys(keys_dict)[0]: + if teuthology.lock.ops.do_update_keys(keys_dict)[0]: log.info("Error in virtual machine keys") newscandict = {} for dkey in all_locked.keys():