| |
@@ -0,0 +1,79 @@
|
| |
+ #!/usr/bin/python
|
| |
+
|
| |
+ import argparse
|
| |
+ import logging
|
| |
+ import subprocess
|
| |
+ import sys
|
| |
+
|
| |
+ import toml
|
| |
+
|
| |
+
|
| |
+ _log = logging.getLogger(__name__)
|
| |
+
|
| |
+
|
| |
+ def get_cli_args(args):
|
| |
+
|
| |
+ parser = argparse.ArgumentParser(
|
| |
+ prog="clean up side-tags", formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
| |
+ )
|
| |
+
|
| |
+ parser.add_argument(
|
| |
+ "conf",
|
| |
+ help="Configuration file used by the runner",
|
| |
+ )
|
| |
+
|
| |
+ return parser.parse_args(args)
|
| |
+
|
| |
+
|
| |
+ def run_command(command) -> bytes:
|
| |
+ """ Run the specified command in a specific working directory if one
|
| |
+ is specified.
|
| |
+ """
|
| |
+ output = None
|
| |
+ try:
|
| |
+ output = subprocess.check_output(command, stderr=subprocess.PIPE)
|
| |
+ except subprocess.CalledProcessError as e:
|
| |
+ _log.error("Command `{}` return code: `{}`".format(" ".join(command), e.returncode))
|
| |
+ _log.error("stdout:\n-------\n{}".format(e.stdout))
|
| |
+ _log.error("stderr:\n-------\n{}".format(e.stderr))
|
| |
+ pass
|
| |
+
|
| |
+ return output
|
| |
+
|
| |
+
|
| |
+ def main(args):
|
| |
+
|
| |
+ conf = toml.load(args.conf)
|
| |
+ if conf.get("kb_principal") and conf.get("kb_keytab_file"):
|
| |
+ print(f"Logging as {conf['kb_principal']} into kerberos using: {conf['kb_keytab_file']}")
|
| |
+ cmd = ["kinit", conf["kb_principal"], "-kt", conf["kb_keytab_file"]]
|
| |
+ run_command(cmd)
|
| |
+
|
| |
+ # list side-tags:
|
| |
+ cmd = [
|
| |
+ conf["fedpkg"], "list-side-tags", "--user", conf["kb_principal"].rsplit('@', 1)[0]
|
| |
+ ]
|
| |
+ output = run_command(cmd)
|
| |
+
|
| |
+ if not output:
|
| |
+ print("No side-tags to clean found.")
|
| |
+ return
|
| |
+
|
| |
+ output = output.decode("UTF-8").strip().split("\n")
|
| |
+ # Remove all the side-tags but the last one (which is the latest one), which
|
| |
+ # we keep in case there is a run ongoing
|
| |
+ for line in output[:-1]:
|
| |
+ side_tag = line.split('\t')[0]
|
| |
+ print("Removing side-tag: %s" % side_tag)
|
| |
+ cmd = [
|
| |
+ conf["fedpkg"], "remove-side-tag", side_tag
|
| |
+ ]
|
| |
+ output = run_command(cmd)
|
| |
+
|
| |
+
|
| |
+
|
| |
+ if __name__ == "__main__":
|
| |
+ """ Main method. """
|
| |
+
|
| |
+ args = get_cli_args(sys.argv[1:])
|
| |
+ main(args)
|
| |
If a run of monitor-gating fails, there can be some side-tags left
over. While we need to fix monitor-gating to avoid them, this script
can also become handy to just clean up when needed.
Relates to #18
Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr