aboutsummaryrefslogtreecommitdiff
path: root/auto_delete_nightly_test_data.py
diff options
context:
space:
mode:
authorDenis Nikitin <denik@google.com>2020-05-14 16:02:38 -0700
committerDenis Nikitin <denik@chromium.org>2020-05-15 06:42:47 +0000
commite68d197f0665315607f99f193c67009ba66a2e8d (patch)
tree5ea58976e7333c9d9f19a42c0e640b20f51e1fd6 /auto_delete_nightly_test_data.py
parent2147769daea8a3cad93d6c62017e42e1b7461e62 (diff)
downloadtoolchain-utils-e68d197f0665315607f99f193c67009ba66a2e8d.tar.gz
Update tmp cleanup on chrotomation3
Remove "*-llvm-next-nightly" images from chroot /tmp. Updated CleanChromeOsImageFiles which now deletes directories with rmtree. This should fix the problem with cron job auto delete. BUG=None TEST=Tested with --dry_run on chrotomation3. Change-Id: If8458540e009c50dec829f14c47581fdd7be305e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2202728 Tested-by: Denis Nikitin <denik@chromium.org> Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Diffstat (limited to 'auto_delete_nightly_test_data.py')
-rwxr-xr-xauto_delete_nightly_test_data.py54
1 files changed, 31 insertions, 23 deletions
diff --git a/auto_delete_nightly_test_data.py b/auto_delete_nightly_test_data.py
index 4ec5b0fd..e40b95c2 100755
--- a/auto_delete_nightly_test_data.py
+++ b/auto_delete_nightly_test_data.py
@@ -15,7 +15,9 @@ import argparse
import datetime
import os
import re
+import shutil
import sys
+import time
from cros_utils import command_executer
from cros_utils import constants
@@ -134,30 +136,33 @@ def CleanChromeOsTmpFiles(chroot_tmp, days_to_preserve, dry_run):
def CleanChromeOsImageFiles(chroot_tmp, subdir_suffix, days_to_preserve,
dry_run):
- rv = 0
- rv2 = 0
- ce = command_executer.GetCommandExecuter()
- minutes = 1440 * days_to_preserve
# Clean files that were last accessed more than the specified time.
- rv2 = 0
- cmd = (r'find {0}/*{1}/* -maxdepth 1 -type d '
- r'-amin +{2} '
- r'-exec bash -c "echo rm -fr {{}}" \; '
- r'-exec bash -c "rm -fr {{}}" \;').format(chroot_tmp, subdir_suffix,
- minutes)
- if dry_run:
- print('Going to execute:\n%s' % cmd)
- else:
- rv2 = ce.RunCommand(cmd, print_to_console=False)
- if rv2 == 0:
- print('Successfully cleaned chromeos image autotest directories from '
- '"{0}/*{1}".'.format(chroot_tmp, subdir_suffix))
- else:
- print('Some image autotest directories were not removed from '
- '"{0}/*{1}".'.format(chroot_tmp, subdir_suffix))
-
- rv += rv2
- return rv
+ seconds_delta = days_to_preserve * 24 * 3600
+ now = time.time()
+ errors = 0
+
+ for tmp_dir in os.listdir(chroot_tmp):
+ # Directory under /tmp
+ tmp_dir = os.path.join(chroot_tmp, tmp_dir)
+ if tmp_dir.endswith(subdir_suffix):
+ # Tmp directory which ends with subdir_suffix.
+ for subdir in os.listdir(tmp_dir):
+ # Subdirectories targeted for deletion.
+ subdir_path = os.path.join(tmp_dir, subdir)
+ if now - os.path.getatime(subdir_path) > seconds_delta:
+ if dry_run:
+ print('Will run:\nshutil.rmtree({})'.format(subdir_path))
+ else:
+ try:
+ shutil.rmtree(subdir_path)
+ print('Successfully cleaned chromeos image autotest directories '
+ 'from "{}".'.format(subdir_path))
+ except OSError:
+ print('Some image autotest directories were not removed from '
+ '"{}".'.format(subdir_path))
+ errors += 1
+
+ return errors
def CleanChromeOsTmpAndImages(days_to_preserve=1, dry_run=False):
@@ -175,6 +180,9 @@ def CleanChromeOsTmpAndImages(days_to_preserve=1, dry_run=False):
# Clean image files in *-pfq directories
rv += CleanChromeOsImageFiles(chromeos_chroot_tmp, '-pfq', days_to_preserve,
dry_run)
+ # Clean image files in *-llvm-next-nightly directories
+ rv += CleanChromeOsImageFiles(chromeos_chroot_tmp, '-llvm-next-nightly',
+ days_to_preserve, dry_run)
return rv