From f3f45a804a0db3c844f7f3f40f6eb264105cb445 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Nov 23 2023 00:52:55 +0000 Subject: [PATCH 1/2] fedora_bz: add a --start-bug option for aborted runs Now we're not feeding the script CSVs, it's harder to recover if a long run happens to die in the middle somehow (before, if that happened, you could just lop off the already-touched bugs from the CSV manually or something). This adds a --start-bug option you can use in this case to start the process wherever the failed run left off. This is mainly useful for eolwarn because for the other commands, the query should exclude bugs that were already handled. We use the value in both paginate_query and update_bugs. This is so it works for alert_deadline (which doesn't use paginate_query) but we also get the efficiency bonus of not bothering to search for bugs lower than the specified ID at all in paginate_query. Note we use greaterthan queries, so the bug ID specified will not be included. This is because I assume the main use case will be if a run dies somehow, we want to feed in the ID of the last bug it successfully edited before dying, so we don't want to edit that bug again. Signed-off-by: Adam Williamson --- diff --git a/closebugs/fedora_bz.py b/closebugs/fedora_bz.py index 6f38294..ed827a7 100755 --- a/closebugs/fedora_bz.py +++ b/closebugs/fedora_bz.py @@ -96,7 +96,7 @@ def paginate_query(query, bz): query[f"f{field}"] = "bug_id" query[f"o{field}"] = "greaterthan" - query[f"v{field}"] = 0 + query[f"v{field}"] = options.start_bug or 0 while True: result = bz.query(query) @@ -222,6 +222,8 @@ def handle_eol(): def update_bugs(bugs, update): '''Actually perform the Bugzilla update now!''' + if options.start_bug: + bugs = [bug for bug in bugs if int(bug) > options.start_bug] total_bugs = len(bugs) failed_bugs = {} @@ -291,6 +293,9 @@ parser.add_argument('--sleep-every', dest='sleep_every', type=int, default=10, help='Sleep after every X bugs') parser.add_argument('--sleep-seconds', dest='sleep_seconds', type=int, default=2, help='Sleep period (in seconds)') +parser.add_argument('--start-bug', dest='start_bug', type=int, + help='Bug ID to start from - useful if a long run dies part-way through. ' + 'Note this is exclusive, --start-bug 8 will include bug #9 and higher.') subparsers = parser.add_subparsers(dest="subcommand") subparsers.required = True From 71bb6f6add3af8927e15bfe2508faa988e56fbb6 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Nov 23 2023 00:52:58 +0000 Subject: [PATCH 2/2] Add safety check for eolwarn eolwarn is the one command where running multiple times will cause the script to actually touch the bugs again and again, because all it does is post a comment, so the bug will still be found by the same query on a subsequent run. In the other cases, the script changes the bugs such that they should not be found again on subsequent runs. This adds a safety valve - on each run of eolwarn, we look at the first bug in the list, and see if it already contains the comment. If it does, we abort with a note to use --start-bug. Figuring out where to start from is left as an exercise for the script user (I could write a fancy bisect-type thing to figure it out, but ehhh, let's just hope you have the output of the run that died so you know where to start from). We also add a --force arg to override the check. Signed-off-by: Adam Williamson --- diff --git a/closebugs/fedora_bz.py b/closebugs/fedora_bz.py index ed827a7..55e1052 100755 --- a/closebugs/fedora_bz.py +++ b/closebugs/fedora_bz.py @@ -217,6 +217,12 @@ def handle_eol(): DATE=date ) update = bz.build_update(comment=comment, minor_update=options.mail) + if bugs and not options.close and not options.force: + # safety check: if the first bug already has the comment, abort + firstbug = bz.getbug(bugs[0]) + for comment in firstbug.comments: + if f"Fedora Linux {options.release} is nearing its end of life" in comment["text"]: + error_out(f"First bug {firstbug.id} has already been touched! Use --start-bug", ERROR_CODES['DATA']) update_bugs(bugs, update) @@ -329,6 +335,8 @@ parser_eolw = subparsers.add_parser( "eolwarn", description="Comment on bugs that will soon be closed for a release that is going EOL" ) +parser_eolw.add_argument('--force', action='store_true', + help='Override the check for whether this already ran') parser_eolw.set_defaults(func=handle_eol, close=False) parser_eolc = subparsers.add_parser(