]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Add teuthology-node-cleanup command
authorZack Cerza <zack@redhat.com>
Fri, 2 Feb 2024 18:40:52 +0000 (11:40 -0700)
committerZack Cerza <zack@redhat.com>
Fri, 2 Feb 2024 18:51:33 +0000 (11:51 -0700)
This replaces teuthology-nuke --stale

Signed-off-by: Zack Cerza <zack@redhat.com>
scripts/node_cleanup.py [new file with mode: 0755]
setup.cfg

diff --git a/scripts/node_cleanup.py b/scripts/node_cleanup.py
new file mode 100755 (executable)
index 0000000..f1f5b0b
--- /dev/null
@@ -0,0 +1,48 @@
+import argparse
+import logging
+import sys
+
+import teuthology
+from teuthology.lock import query, ops
+
+def main():
+    args = parse_args(sys.argv[1:])
+    if args.verbose:
+        teuthology.log.setLevel(logging.DEBUG)
+    log = logging.getLogger(__name__)
+    stale = query.find_stale_locks(args.owner)
+    if not stale:
+        return
+    if args.dry_run:
+        log.info("Would attempt to unlock:")
+        for node in stale:
+            log.info(f"{node['name']}\t{node['description']}")
+    else:
+        names = [node["name"] for node in stale]
+        ops.unlock_safe(names, args.owner)
+
+def parse_args(argv):
+    parser = argparse.ArgumentParser(
+        description="Find and unlock nodes that are still locked by jobs that are no "
+            "longer active",
+    )
+    parser.add_argument(
+        '-v', '--verbose',
+        action='store_true',
+        default=False,
+        help='Be more verbose',
+    )
+    parser.add_argument(
+        '--dry-run',
+        action='store_true',
+        default=False,
+        help="List nodes that would be unlocked if the flag were omitted",
+    )
+    parser.add_argument(
+        '--owner',
+        help='Optionally, find nodes locked by a specific user',
+    )
+    return parser.parse_args(argv)
+
+if __name__ == "__main__":
+    main()
index a2e14b1d244a61af1a0a4f0a6ee083e9a1e72c15..75c8a02f1a78d288d54d2d34102c5740a4f6f05e 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -84,6 +84,7 @@ console_scripts =
     teuthology-dispatcher = scripts.dispatcher:main
     teuthology-wait = scripts.wait:main
     teuthology-exporter = scripts.exporter:main
+    teuthology-node-cleanup = scripts.node_cleanup:main
 
 [options.extras_require]
 manhole =