]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
node-cleanup: Optionally filter by machine type
authorZack Cerza <zack@cerza.org>
Thu, 21 May 2026 19:44:17 +0000 (13:44 -0600)
committerZack Cerza <zack@cerza.org>
Thu, 21 May 2026 19:50:10 +0000 (13:50 -0600)
scripts/node_cleanup.py
teuthology/lock/ops.py
teuthology/lock/query.py

index d6db35dae43c01893d804ce886dc80d73fdcb622..a2cb82602e09c75f9f48d2c8558a0d2acad825b7 100755 (executable)
@@ -21,7 +21,10 @@ def main():
             logging.Formatter('%(message)s')
         )
     try:
-        stale = query.find_stale_locks(args.owner)
+        stale = query.find_stale_locks(
+            args.owner,
+            machine_type=args.machine_type
+        )
     except Exception:
         log.exception(f"Error while check for stale locks held by {args.owner}")
         return
@@ -70,6 +73,10 @@ def parse_args(argv):
         '--owner',
         help='Optionally, find nodes locked by a specific user',
     )
+    parser.add_argument(
+        '-m', '--machine-type',
+        help='Optionally, find nodes in a comma-separated list of machine types',
+    )
     return parser.parse_args(argv)
 
 if __name__ == "__main__":
index 0acc6b62eb64912b0975fa0cf5329b35dcbb839f..9cccd758c9abb8d0749f67ccf8745dad82418291 100644 (file)
@@ -503,7 +503,7 @@ def block_and_lock_machines(ctx, total_requested, machine_type, reimage=True, tr
 
 def stop_node(name: str, status: Union[dict, None]):
     status = status or query.get_status(name)
-    remote_ = remote.Remote(name)
+    remote_ = remote.Remote(misc.canonicalize_hostname(name))
     if status['machine_type'] in provision.fog.get_types():
         remote_.console.power_off()
         return
index ac4cede070e5b5b4eea20b66471525973aacae22..b42d7b956e077eaf90229dedddc0da2dd9832720 100644 (file)
@@ -64,8 +64,8 @@ def list_locks(keyed_by_name=False, tries=10, **kwargs):
         if kwargs[key] is True:
             kwargs[key] = '1'
     if kwargs:
-        if 'machine_type' in kwargs:
-            kwargs['machine_type'] = kwargs['machine_type'].replace(',','|')
+        if machine_type := kwargs.get("machine_type"):
+            kwargs['machine_type'] = machine_type.replace(',','|')
         uri += '?' + urlencode(kwargs)
     with safe_while(
             sleep=1,
@@ -89,14 +89,15 @@ def list_locks(keyed_by_name=False, tries=10, **kwargs):
     return dict()
 
 
-def find_stale_locks(owner=None) -> List[Dict]:
+def find_stale_locks(owner: str | None = None, machine_type: str | None = None) -> List[Dict]:
     """
     Return a list of node dicts corresponding to nodes that were locked to run
     a job, but the job is no longer running. The purpose of this is to enable
     us to find nodes that were left locked due to e.g. infrastructure failures
     and return them to the pool.
 
-    :param owner: If non-None, return nodes locked by owner. Default is None.
+    :param owner: Optionally filter nodes by owner
+    :param machine_type: Optionally filter nodes by comma-separated machine type(s)
     """
     def might_be_stale(node_dict):
         """
@@ -117,7 +118,7 @@ def find_stale_locks(owner=None) -> List[Dict]:
         return False
 
     # Which nodes are locked for jobs?
-    nodes = list_locks(locked=True)
+    nodes = list_locks(locked=True, machine_type=machine_type)
     if owner is not None:
         nodes = [node for node in nodes if node['locked_by'] == owner]
     nodes = filter(might_be_stale, nodes)