]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
prune: Process log dirs in order of ctime 713/head
authorZack Cerza <zack@redhat.com>
Wed, 18 Nov 2015 19:05:51 +0000 (12:05 -0700)
committerZack Cerza <zack@redhat.com>
Wed, 18 Nov 2015 19:26:20 +0000 (12:26 -0700)
Most recent first, of course.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/prune.py

index d0560beb61356172c24968a833fdcd2b81c287d5..2b5114ce87e584e4e4de5b06580fd6a41025d88f 100644 (file)
@@ -34,16 +34,21 @@ def prune_archive(archive_dir, pass_days, remotes_days, dry_run=False):
     directories that might be old enough
     """
     max_days = max(pass_days, remotes_days)
-    run_dirs = list()
     log.debug("Archive {archive} has {count} children".format(
         archive=archive_dir, count=len(os.listdir(archive_dir))))
-    for child in listdir(archive_dir):
-        item = os.path.join(archive_dir, child)
+    # Use full paths
+    children = map(
+        lambda p: os.path.join(archive_dir, p),
+        listdir(archive_dir)
+    )
+    run_dirs = list()
+    for child in children:
         # Ensure that the path is not a symlink, is a directory, and is old
         # enough to process
-        if (not os.path.islink(item) and os.path.isdir(item) and
-                is_old_enough(item, max_days)):
-            run_dirs.append(item)
+        if (not os.path.islink(child) and os.path.isdir(child) and
+                is_old_enough(child, max_days)):
+            run_dirs.append(child)
+    run_dirs.sort(key=lambda p: os.path.getctime(p), reverse=True)
     for run_dir in run_dirs:
         log.debug("Processing %s ..." % run_dir)
         maybe_remove_passes(run_dir, pass_days, dry_run)