]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
lock/ops: remove circular import of keys operations
authorKyr Shatskyy <kyrylo.shatskyy@suse.com>
Mon, 18 Nov 2019 18:30:45 +0000 (19:30 +0100)
committerKyr Shatskyy <kyrylo.shatskyy@gmail.com>
Mon, 18 Nov 2019 22:06:51 +0000 (23:06 +0100)
Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@suse.com>
teuthology/lock/cli.py
teuthology/lock/keys.py
teuthology/lock/ops.py
teuthology/task/internal/lock_machines.py

index 16e2806798c539050ca0eabcaf96fd6fc82be6b6..b6f6ed00057cdf1dfd2bcef75318c418b130cf31 100644 (file)
@@ -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]
index 3ed2f987ca78ddc93723704aa27cf778bf18e6b0..a03bb5d12b83d48181079239e518b074242798b5 100644 (file)
@@ -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
index fc4aed9d6b17889c1e10825adacc99e5adaafea0..376aa4af24c023311d065d0954e77c3ba6bf2c74 100644 (file)
@@ -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
index 1dc2e0a3b26ca8c1429e53e82419b5736cae6340..bfab80f79ef7fa6a5310505f76dcbfe233f78d57 100644 (file)
@@ -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():