diff options
author | Manoj Gupta <manojgupta@google.com> | 2020-04-13 16:59:27 -0700 |
---|---|---|
committer | Manoj Gupta <manojgupta@chromium.org> | 2020-04-29 01:51:50 +0000 |
commit | d94e440824c45b48fbee6396b389279a6967e3d0 (patch) | |
tree | 53dc041226cf993e6d2c422e0cabd25c6ed2ed62 /auto_delete_nightly_test_data.py | |
parent | b830979d628d7cdbd3a93dc898173362af228cd7 (diff) | |
download | toolchain-utils-d94e440824c45b48fbee6396b389279a6967e3d0.tar.gz |
toolchain-utils: Auto abandon old CLs
Abandon CLs without any update that are older than 2 weeks.
Ignoring days to preserve intentionally since sometimes
CLs can be older than several days.
BUG=chromium:1067029
TEST=unit tests
Change-Id: Ie0f377a32ccf40331221c579401b5aaa2e84cf6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2147820
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Tiancong Wang <tcwang@google.com>
Diffstat (limited to 'auto_delete_nightly_test_data.py')
-rwxr-xr-x | auto_delete_nightly_test_data.py | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/auto_delete_nightly_test_data.py b/auto_delete_nightly_test_data.py index 429d0b4a..8f156549 100755 --- a/auto_delete_nightly_test_data.py +++ b/auto_delete_nightly_test_data.py @@ -179,6 +179,29 @@ def CleanChromeOsTmpAndImages(days_to_preserve=1, dry_run=False): return rv +def CleanOldCLs(days_to_preserve='1', dry_run=False): + """Abandon old CLs created by automation tooling.""" + ce = command_executer.GetCommandExecuter() + chromeos_root = os.path.join(constants.CROSTC_WORKSPACE, 'chromeos') + # Find Old CLs. + old_cls_cmd = ( + 'gerrit --raw search "owner:me status:open age:%sd"' % days_to_preserve) + _, cls, _ = ce.ChrootRunCommandWOutput( + chromeos_root, old_cls_cmd, print_to_console=False) + # Convert any whitespaces to spaces. + cls = ' '.join(cls.split()) + if not cls: + return 0 + + abandon_cls_cmd = ('gerrit abandon %s' % cls) + if dry_run: + print('Going to execute: %s' % abandon_cls_cmd) + return 0 + + return ce.ChrootRunCommand( + chromeos_chroot, abandon_cls_cmd, print_to_console=False) + + def Main(argv): """Delete nightly test data directories, tmps and test images.""" options = ProcessArguments(argv) @@ -201,12 +224,15 @@ def Main(argv): os.path.join(NIGHTLY_TESTS_WORKSPACE, dated_dir), options.dry_run) else 1 - -## Finally clean temporaries, images under crostc/chromeos + ## Clean temporaries, images under crostc/chromeos rv2 = CleanChromeOsTmpAndImages( int(options.days_to_preserve), options.dry_run) - return rv + rv2 + # Clean CLs that are not updated in last 2 weeks. + rv3 = CleanOldCLs('14', options.dry_run) + + return rv + rv2 + rv3 + if __name__ == '__main__': retval = Main(sys.argv[1:]) |