From c031be4ed0cf731afd27e7c407dc39db2d146f20 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 2 Feb 2024 11:40:52 -0700 Subject: [PATCH] Add teuthology-node-cleanup command This replaces teuthology-nuke --stale Signed-off-by: Zack Cerza --- scripts/node_cleanup.py | 48 +++++++++++++++++++++++++++++++++++++++++ setup.cfg | 1 + 2 files changed, 49 insertions(+) create mode 100755 scripts/node_cleanup.py diff --git a/scripts/node_cleanup.py b/scripts/node_cleanup.py new file mode 100755 index 000000000..f1f5b0be2 --- /dev/null +++ b/scripts/node_cleanup.py @@ -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() diff --git a/setup.cfg b/setup.cfg index a2e14b1d2..75c8a02f1 100644 --- 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 =