From 6f631f1e913b6f6df852fc2c7af6d5419421f69d Mon Sep 17 00:00:00 2001 From: Patrik Polakovič Date: Dec 16 2021 13:54:23 +0000 Subject: Run black Signed-off-by: Patrik Polakovič --- diff --git a/entrypoint.sh b/entrypoint.sh index 21986ed..0c9c11d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,16 +6,14 @@ if ! whoami &> /dev/null; then fi fi - ln -s /opt/ssh/id_rsa /.ssh/id_rsa || true + if [ -z ${PRODUCTION+x} ]; then -# Staging info -echo "Running in staging" -ssh-keyscan pkgs.stg.fedoraproject.org >> /.ssh/known_hosts + echo "Running in staging" + ssh-keyscan pkgs.stg.fedoraproject.org >> /.ssh/known_hosts else -# Prod info -echo "Running in production" -ssh-keyscan pkgs.fedoraproject.org >> /.ssh/known_hosts + echo "Running in production" + ssh-keyscan pkgs.fedoraproject.org >> /.ssh/known_hosts fi klist -t -k /etc/keytabs/monitor-gating-keytab diff --git a/monitor_gating/clean_up_side_tags.py b/monitor_gating/clean_up_side_tags.py index 9c3e994..de42c9e 100644 --- a/monitor_gating/clean_up_side_tags.py +++ b/monitor_gating/clean_up_side_tags.py @@ -19,23 +19,22 @@ def get_cli_args(args): ) parser.add_argument( - "conf", help="Configuration file used by the runner", + "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 + """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("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 @@ -44,14 +43,12 @@ def run_command(command) -> bytes: def main(): - """ Main method. """ + """Main method.""" args = get_cli_args(sys.argv[1:]) 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']}" - ) + 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) diff --git a/monitor_gating/multi_builds.py b/monitor_gating/multi_builds.py index c83b4b1..7e397db 100644 --- a/monitor_gating/multi_builds.py +++ b/monitor_gating/multi_builds.py @@ -36,8 +36,7 @@ _log = logging.getLogger(__name__) def get_arguments(args): - """ Parse and return the CLI arguments. - """ + """Parse and return the CLI arguments.""" parser = argparse.ArgumentParser(description="Test the CI workflow in Fedora.") parser.add_argument( "--staging", @@ -67,7 +66,7 @@ def get_arguments(args): def main(args, utils=None): - """ Main method used by this script. """ + """Main method used by this script.""" start = datetime.datetime.utcnow() args = get_arguments(args) @@ -87,9 +86,7 @@ def main(args, utils=None): # Store the side_tag_name so we can use it in the runner utils.side_tag_name = side_tag_name - nevrs, _ = utils.clone_and_bump( - folder, nevrs, conf, conf["name_multi_2"], version=0, target=side_tag_name - ) + nevrs, _ = utils.clone_and_bump(folder, nevrs, conf, conf["name_multi_2"], version=0, target=side_tag_name) version, synced = utils.nevrs_synced(nevrs, conf) @@ -101,9 +98,7 @@ def main(args, utils=None): folder, nevrs, conf, conf["name_multi_1"], version=version, new_side_tag=True ) - nevrs, _ = utils.bump( - folder, nevrs, conf, conf["name_multi_2"], version=version, target=side_tag_name - ) + nevrs, _ = utils.bump(folder, nevrs, conf, conf["name_multi_2"], version=version, target=side_tag_name) start_dg = datetime.datetime.utcnow() # Chain-build the packages @@ -126,7 +121,10 @@ def main(args, utils=None): password=conf.get("bodhi-password"), from_tag=True, ) - updateid = utils.get_update_id(nevrs[list(nevrs.keys())[0]], conf["bodhi"],) + updateid = utils.get_update_id( + nevrs[list(nevrs.keys())[0]], + conf["bodhi"], + ) utils.print_user(f"Update {updateid} created : {conf['bodhi']}/updates/{updateid}", success=True) # Check the tag of the build @@ -144,8 +142,7 @@ def main(args, utils=None): utils.lookup_results_datagrepper( base_url=conf["datagrepper"], name="bodhi to CI", - topic=f"org.fedoraproject.{conf['_env']}.bodhi.update.status." - "testing.koji-build-group.build.complete", + topic=f"org.fedoraproject.{conf['_env']}.bodhi.update.status." "testing.koji-build-group.build.complete", bodhi_id=updateid, duration=180, start=start_dg, @@ -178,7 +175,9 @@ def main(args, utils=None): # Check the tag of the build utils.get_build_tags( - conf.get("koji_hub"), nevr, expected_ends=["testing-pending"], + conf.get("koji_hub"), + nevr, + expected_ends=["testing-pending"], ) # Check that the CI results made it to resultsdb @@ -210,7 +209,9 @@ def main(args, utils=None): # Check the tag of the build -- build is blocked but should be signed utils.get_build_tags( - conf.get("koji_hub"), nevr, expected_ends=["testing-pending"], + conf.get("koji_hub"), + nevr, + expected_ends=["testing-pending"], ) if not args.no_waive: @@ -245,7 +246,9 @@ def main(args, utils=None): # Check the tag of the build -- build was waived, let is through utils.get_build_tags( - conf.get("koji_hub"), nevr, expected_ends=conf["koji_end_tag"], + conf.get("koji_hub"), + nevr, + expected_ends=conf["koji_end_tag"], ) utils.finalize(start) diff --git a/monitor_gating/runner.py b/monitor_gating/runner.py index 43c2f76..74082ea 100644 --- a/monitor_gating/runner.py +++ b/monitor_gating/runner.py @@ -22,6 +22,7 @@ from .utils import MonitoringUtils, blocking_issues, run_command, report_failure import code import signal + signal.signal(signal.SIGUSR2, lambda sig, frame: code.interact()) scheduler = sched.scheduler(time.time, time.sleep) @@ -29,10 +30,11 @@ conf = toml.load def get_arguments(args): - """ Load and parse the CLI arguments.""" + """Load and parse the CLI arguments.""" parser = argparse.ArgumentParser(description="Runner for the CI canary tests.") parser.add_argument( - "conf", help="Configuration file for the different tests", + "conf", + help="Configuration file for the different tests", ) return parser.parse_args(args) @@ -40,9 +42,7 @@ def get_arguments(args): def notify(topic, message): try: - msg = fedora_messaging.api.Message( - topic="monitor-gating.{}".format(topic), body=message - ) + msg = fedora_messaging.api.Message(topic="monitor-gating.{}".format(topic), body=message) fedora_messaging.api.publish(msg) except fedora_messaging.exceptions.PublishReturned as err: print(f"Fedora Messaging broker rejected message {msg.id}: {err}") @@ -66,7 +66,7 @@ def _clean_up_side_tags(utils): def schedule(conf): - """ Run the test and schedules the next one. """ + """Run the test and schedules the next one.""" if conf.get("kb_principal") and conf.get("kb_keytab_file"): print(f"Logging into kerberos using: {conf['kb_keytab_file']}") @@ -86,7 +86,7 @@ def schedule(conf): # Single Build Gating single_args = conf["workflow_single_gating_args"].split() notify( - topic=f"single-build.start", + topic="single-build.start", message={"arguments": single_args, "runid": runid}, ) monit_utils = single_build.main(single_args) @@ -119,7 +119,7 @@ def schedule(conf): multi_args = conf["workflow_multi_gating_args"].split() monit_utils = MonitoringUtils() notify( - topic=f"multi-build.start", + topic="multi-build.start", message={"arguments": multi_args, "runid": runid}, ) try: @@ -159,12 +159,14 @@ def schedule(conf): print(sys.exc_info()) print("=" * 60) import traceback + traceback.print_exc(file=sys.stdout) print("-" * 60) traceback.print_stack() notify( - topic=f"multi-build.end.error", message={"runid": runid, "exception": str(err)}, + topic="multi-build.end.error", + message={"runid": runid, "exception": str(err)}, ) if monit_utils: report_failure( @@ -183,8 +185,7 @@ def schedule(conf): now = datetime.datetime.utcnow().strftime("%H:%M:%S") if blocking_issues_list: print( - f"{now} Next run in: {delay_when_failing} seconds because of " - f"{len(blocking_issues_list)} open issues", + f"{now} Next run in: {delay_when_failing} seconds because of " f"{len(blocking_issues_list)} open issues", flush=True, ) if single_run: @@ -198,7 +199,7 @@ def schedule(conf): def main(): - """ Main method. """ + """Main method.""" try: args = get_arguments(sys.argv[1:]) print(args) diff --git a/monitor_gating/single_build.py b/monitor_gating/single_build.py index 912b6b4..c870937 100644 --- a/monitor_gating/single_build.py +++ b/monitor_gating/single_build.py @@ -36,11 +36,11 @@ _log = logging.getLogger(__name__) def get_arguments(args): - """ Parse and return the CLI arguments. - """ + """Parse and return the CLI arguments.""" parser = argparse.ArgumentParser(description="Test the CI workflow in Fedora.") parser.add_argument( - "--nevr", help="NEVR of the build, allows by-passing: commit, push, build", + "--nevr", + help="NEVR of the build, allows by-passing: commit, push, build", ) parser.add_argument( "--update", @@ -62,8 +62,7 @@ def get_arguments(args): "--auto-update", action="store_true", default=False, - help="Wait for the update to be created automatically instead of " - "doing it manually", + help="Wait for the update to be created automatically instead of " "doing it manually", ) parser.add_argument( "--no-waive", @@ -81,7 +80,7 @@ def get_arguments(args): def main(args): - """ Main method used by this script. """ + """Main method used by this script.""" start = datetime.datetime.utcnow() args = get_arguments(args) @@ -99,7 +98,11 @@ def main(args): if not args.nevr: fedpkg_username = conf.get("fedpkg_username", conf["fas_username"]) utils.clone_repo( - conf["fedpkg"], fedpkg_username, namespace, name, folder=folder, + conf["fedpkg"], + fedpkg_username, + namespace, + name, + folder=folder, ) gitfolder = os.path.join(folder, name) utils.switch_branch(conf["fedpkg"], branch, folder=gitfolder) @@ -116,8 +119,7 @@ def main(args): # wait for CI to flag the PR, twice, merge the PR utils.add_remote( f"{fas_username}", - f"ssh://{fas_username}@{conf['distgit_host']}/" - f"forks/{fas_username}/{namespace}/{name}.git", + f"ssh://{fas_username}@{conf['distgit_host']}/" f"forks/{fas_username}/{namespace}/{name}.git", folder=gitfolder, ) utils.push_changes(gitfolder, fas_username, branch, force=True) @@ -226,8 +228,7 @@ def main(args): utils.lookup_results_datagrepper( base_url=conf["datagrepper"], name="bodhi to CI", - topic=f"org.fedoraproject.{conf['_env']}.bodhi.update.status." - "testing.koji-build-group.build.complete", + topic=f"org.fedoraproject.{conf['_env']}.bodhi.update.status." "testing.koji-build-group.build.complete", bodhi_id=updateid, ) @@ -255,7 +256,9 @@ def main(args): # Check the tag of the build utils.get_build_tags( - conf.get("koji_hub"), nevr, expected_ends=["testing-pending"], + conf.get("koji_hub"), + nevr, + expected_ends=["testing-pending"], ) # Check that the CI results made it to resultsdb @@ -287,7 +290,9 @@ def main(args): # Check the tag of the build -- build is blocked but should be signed utils.get_build_tags( - conf.get("koji_hub"), nevr, expected_ends=["testing-pending"], + conf.get("koji_hub"), + nevr, + expected_ends=["testing-pending"], ) if not args.no_waive: @@ -321,7 +326,9 @@ def main(args): # Check the tag of the build -- build was waived, let is through utils.get_build_tags( - conf.get("koji_hub"), nevr, expected_ends=conf["koji_end_tag"], + conf.get("koji_hub"), + nevr, + expected_ends=conf["koji_end_tag"], ) utils.finalize(start) diff --git a/monitor_gating/utils.py b/monitor_gating/utils.py index f144b0f..8bafcce 100644 --- a/monitor_gating/utils.py +++ b/monitor_gating/utils.py @@ -19,7 +19,7 @@ _log = logging.getLogger(__name__) def report_failure(project, token, env, workflow, monit_utils): - """ Open a pagure ticket against the instance specified in the + """Open a pagure ticket against the instance specified in the configuration file when something does not work. """ url = f"https://pagure.io/api/0/{project}/new_issue" @@ -51,10 +51,9 @@ Full log: def blocking_issues(project, tags): - """Lists blocking issues we track in the fedora-infrastructure project. - """ + """Lists blocking issues we track in the fedora-infrastructure project.""" if not tags: - print(f"No tags to filter blocking issues by, returning empty.") + print("No tags to filter blocking issues by, returning empty.") return [] api = f"https://pagure.io/api/0/{project}/issues?status=Open&tags={tags[0]}" @@ -81,13 +80,12 @@ class MonitoringException(Exception): class MonitoringUtils: def __init__(self): - """ Instanciate the object. """ + """Instanciate the object.""" self.logs = [] self.failed = [] def print_user(self, content, success=None): - """ Prints the specified content to the user. - """ + """Prints the specified content to the user.""" spaces = 90 if success is not None: end = None @@ -107,8 +105,7 @@ class MonitoringUtils: print(f"{time} - {content}", end=end, flush=True) def clone_repo(self, command, username, namespace, name, folder): - """ Clone the specified git repo into the specified folder. - """ + """Clone the specified git repo into the specified folder.""" info_log = f"Cloning as {username} the git repo: {namespace}/{name}" self.print_user(info_log) try: @@ -124,7 +121,8 @@ class MonitoringUtils: # Assume these commands can't fail clone_folder = os.path.join(folder, name) run_command( - ["git", "config", "user.name", "packagerbot"], cwd=clone_folder, + ["git", "config", "user.name", "packagerbot"], + cwd=clone_folder, ) run_command( ["git", "config", "user.email", "admin@fedoraproject.org"], @@ -136,7 +134,7 @@ class MonitoringUtils: self.print_user(info_log, success=False) def add_remote(self, name, url, folder): - """ Add the specified remote to the git repo in the folder with the + """Add the specified remote to the git repo in the folder with the specified url. """ info_log = f"Adding remote: {name}" @@ -149,8 +147,7 @@ class MonitoringUtils: self.print_user(info_log, success=False) def switch_branch(self, command, name, folder): - """ Switch to the specified git branch in the specified git repo. - """ + """Switch to the specified git branch in the specified git repo.""" info_log = f"Switching to branch: {name}" self.print_user(info_log) try: @@ -161,8 +158,7 @@ class MonitoringUtils: self.print_user(info_log, success=False) def bump_release(self, name, version, folder): - """ Bump the release of the spec file the specified git repo. - """ + """Bump the release of the spec file the specified git repo.""" info_log = f"Bumping release of: {name}.spec" self.print_user(info_log) try: @@ -177,10 +173,10 @@ class MonitoringUtils: self.print_user(info_log, success=False) def commit_changes(self, commit_log, folder): - """ Commit all the changes made to *tracked* files in the git repo + """Commit all the changes made to *tracked* files in the git repo with the specified commit log. """ - info_log = f"Commiting changes" + info_log = "Committing changes" self.print_user(info_log) try: run_command(["git", "commit", "-asm", commit_log], cwd=folder) @@ -190,9 +186,8 @@ class MonitoringUtils: self.print_user(info_log, success=False) def push_changes(self, folder, target, branch, force=False): - """ Push all changes using git. - """ - info_log = f"Pushing changes" + """Push all changes using git.""" + info_log = "Pushing changes" self.print_user(info_log) try: cmd = ["git", "push", target, branch] @@ -205,9 +200,8 @@ class MonitoringUtils: self.print_user(info_log, success=False) def pull_changes(self, folder, target, branch): - """ Pull all changes using git. - """ - info_log = f"Pulling changes" + """Pull all changes using git.""" + info_log = "Pulling changes" self.print_user(info_log) try: cmd = ["git", "pull", "--rebase", target, branch] @@ -218,14 +212,12 @@ class MonitoringUtils: self.print_user(info_log, success=False) def open_pullrequest(self, base_url, username, namespace, name, branch, token): - """ Open a pull-request from the user's fork to the main project for + """Open a pull-request from the user's fork to the main project for the specified branch. """ info_log = f"Creating PR from forks/{username}/{namespace}/{name}" self.print_user(info_log) - url = "/".join( - [base_url.rstrip("/"), "api/0", namespace, name, "pull-request/new"] - ) + url = "/".join([base_url.rstrip("/"), "api/0", namespace, name, "pull-request/new"]) data = { "branch_to": branch, "branch_from": branch, @@ -247,18 +239,15 @@ class MonitoringUtils: output = req.json() pr_id = str(output["id"]) pr_uid = output["uid"] - url = "/".join( - [base_url.rstrip("/"), namespace, name, "pull-request", pr_id] - ) + url = "/".join([base_url.rstrip("/"), namespace, name, "pull-request", pr_id]) info_log = f"PR created {url}" success = True self.print_user(info_log, success=success) return (success, pr_id, pr_uid) def get_nevr(self, command, folder): - """ Get the name-epoch-version-release presently in git - """ - info_log = f"Getting nevr" + """Get the name-epoch-version-release presently in git""" + info_log = "Getting nevr" self.print_user(info_log) try: nevr = run_command([command, "verrel"], cwd=folder) @@ -269,9 +258,8 @@ class MonitoringUtils: self.print_user(info_log, success=False) def build_package(self, command, folder, target=None): - """ Build the package in the current branch - """ - info_log = f"Building the package" + """Build the package in the current branch""" + info_log = "Building the package" self.print_user(info_log) command = [command, "build"] if target: @@ -284,13 +272,10 @@ class MonitoringUtils: self.print_user(info_log, success=False) def chain_build_packages(self, command, packages, folder, target=None): - """ Chain-build the packages in the current branch - """ + """Chain-build the packages in the current branch""" if not isinstance(packages, list): packages = [packages] - info_log = ( - f"Chain-building the packages: {packages + [os.path.basename(folder)]}" - ) + info_log = f"Chain-building the packages: {packages + [os.path.basename(folder)]}" self.print_user(info_log) command = [command, "chain-build"] command.extend(packages) @@ -304,11 +289,10 @@ class MonitoringUtils: self.print_user(info_log, success=False) def get_build_tags(self, koji_url, nevr, expected_ends): - """ List the tags associated with the specified build. - """ + """List the tags associated with the specified build.""" # return start = datetime.datetime.utcnow() - info_log = f"Retrieving koji tags" + info_log = "Retrieving koji tags" self.print_user(info_log) command = [ "koji", @@ -362,11 +346,16 @@ class MonitoringUtils: self.print_user(info_log, success=success) def create_update( - self, command, item, prod=True, username=None, password=None, from_tag=False, + self, + command, + item, + prod=True, + username=None, + password=None, + from_tag=False, ): - """ Create the update for the package built. - """ - info_log = f"Creating a bodhi update" + """Create the update for the package built.""" + info_log = "Creating a bodhi update" self.print_user(info_log) command = [ command, @@ -396,7 +385,7 @@ class MonitoringUtils: self.print_user(info_log, success=False) def get_update_id(self, nevr, url): - """ Retrieve the update identifier from bodhi for the given nevr. """ + """Retrieve the update identifier from bodhi for the given nevr.""" start = datetime.datetime.utcnow() url = f"{url}/updates/?builds={nevr}" info_log = f"Retrieving update created from {url}" @@ -438,7 +427,7 @@ class MonitoringUtils: start=None, duration=15, ): - """ Check the CI results in datagrepper for results about our specified + """Check the CI results in datagrepper for results about our specified build. """ start_lookup = datetime.datetime.utcnow() @@ -449,10 +438,7 @@ class MonitoringUtils: # Start pulling messages 10 minutes before now start_time = start - datetime.timedelta(minutes=10) # Limiting the number of row per page to 10 allows for quicker results - url = ( - base_url + f"?topic={topic}" - f"&start={start_time.timestamp()}&row_per_page=10" - ) + url = base_url + f"?topic={topic}" f"&start={start_time.timestamp()}&row_per_page=10" success = None returned_status = None @@ -477,19 +463,14 @@ class MonitoringUtils: # Old message format from the CI pipeline if "ci.pipeline" in message["topic"] and ( - message["msg"]["nvr"] == nevr - or message["msg"]["nvr"] in nevrs - or message["msg"]["rev"] == rev + message["msg"]["nvr"] == nevr or message["msg"]["nvr"] in nevrs or message["msg"]["rev"] == rev ): success = True returned_status = message["msg"]["status"] break # New message format from the CI pipeline for koji builds - if ( - "ci.koji-build" in message["topic"] - and message["msg"]["artifact"]["nvr"] == nevr - ): + if "ci.koji-build" in message["topic"] and message["msg"]["artifact"]["nvr"] == nevr: if message["topic"].endswith("test.complete"): success = True returned_status = message["msg"]["test"]["result"] @@ -522,10 +503,7 @@ class MonitoringUtils: if ( "resultsdb" in message["topic"] and "nvr" in message["msg"]["data"] - and ( - nevr in message["msg"]["data"]["nvr"] - or message["msg"]["data"]["nvr"] in nevrs - ) + and (nevr in message["msg"]["data"]["nvr"] or message["msg"]["data"]["nvr"] in nevrs) ): success = True returned_status = message["msg"]["outcome"] @@ -533,8 +511,7 @@ class MonitoringUtils: # greenwave messages if "greenwave" in message["topic"] and ( - message["msg"]["subject_identifier"] == nevr - or message["msg"]["subject_identifier"] in nevrs + message["msg"]["subject_identifier"] == nevr or message["msg"]["subject_identifier"] in nevrs ): success = True returned_status = message["msg"]["policies_satisfied"] @@ -542,17 +519,16 @@ class MonitoringUtils: # waiverdb messages if "waiverdb" in message["topic"] and ( - message["msg"]["subject_identifier"] == nevr - or message["msg"]["subject_identifier"] in nevrs + message["msg"]["subject_identifier"] == nevr or message["msg"]["subject_identifier"] in nevrs ): success = True returned_status = "" break # bodhi messages - if "bodhi.update.status.testing" in message["topic"] and message[ - "msg" - ]["artifact"]["id"].startswith(bodhi_id): + if "bodhi.update.status.testing" in message["topic"] and message["msg"]["artifact"][ + "id" + ].startswith(bodhi_id): success = True returned_status = "" break @@ -579,16 +555,13 @@ class MonitoringUtils: self.failed.append("datagrepper") def lookup_ci_resultsdb(self, nevr, name, url, start=None, duration=(60 * 60)): - """ Check the CI results in the specified resultsdb for results about + """Check the CI results in the specified resultsdb for results about our specified build. """ if start is None: start = datetime.datetime.utcnow() # previously "org.centos.prod.ci.pipeline.allpackages-build.complete" - topics = [ - "fedora-ci.koji-build.tier0.functional", - "fedora-ci.koji-build.tier0-tf.functional" - ] + topics = ["fedora-ci.koji-build.tier0.functional", "fedora-ci.koji-build.tier0-tf.functional"] if ".stg" in url: topics = ["org.centos.stage.ci.pipeline.allpackages-build.complete"] urls = [f"{url}?testcases={topic}" for topic in topics] @@ -626,9 +599,7 @@ class MonitoringUtils: if (datetime.datetime.utcnow() - start).seconds > duration: success = False - info_log = ( - f"CI results did not show in {name} for {nevr} within {duration} minutes since {start}" - ) + info_log = f"CI results did not show in {name} for {nevr} within {duration} minutes since {start}" break # Only query datagrepper every 30 seconds @@ -644,10 +615,10 @@ class MonitoringUtils: self.failed.append("resultsdb") def waive_update(self, command, updateid, prod=True, username=None, password=None): - """ Waive all the tests results for the specified update using bodhi's + """Waive all the tests results for the specified update using bodhi's CLI. """ - info_log = f"Waiving test results for bodhi update" + info_log = "Waiving test results for bodhi update" self.print_user(info_log) command = [ command, @@ -681,7 +652,7 @@ class MonitoringUtils: flag_status, duration=10, ): - """ Retrieve the flags of the PR and assert the last one from the + """Retrieve the flags of the PR and assert the last one from the specified flag_username has the given status. """ pr = "/".join([namespace, name, "pull-request", pr_id]) @@ -726,8 +697,7 @@ class MonitoringUtils: self.failed.append("dist-git") def merge_pr(self, base_url, username, namespace, name, pr_id, token): - """ Merge the specified PR - """ + """Merge the specified PR""" pr = "/".join([namespace, name, "pull-request", pr_id]) info_log = f"Merge PR: {pr}" self.print_user(info_log) @@ -747,15 +717,15 @@ class MonitoringUtils: self.failed.append("dist-git") def finalize(self, start): - """ End data returned. """ + """End data returned.""" end = datetime.datetime.utcnow() delta = (end - start).seconds self.logs.append(f"Ran for {delta} seconds ({delta/60:.2f} minutes)") print(f"Ran for {delta} seconds ({delta/60:.2f} minutes)") def create_side_tag(self, command, folder): - """ Create a side-tag to build packages in it. """ - info_log = f"Creating the side-tag" + """Create a side-tag to build packages in it.""" + info_log = "Creating the side-tag" self.print_user(info_log) command = [command, "request-side-tag"] side_tag_name = None @@ -771,19 +741,19 @@ class MonitoringUtils: self.print_user(info_log, success=False) return side_tag_name - def clone_and_bump( - self, folder, nevrs, conf, name, version, target=None, new_side_tag=False - ): + def clone_and_bump(self, folder, nevrs, conf, name, version, target=None, new_side_tag=False): """Clone the repo, bump the release, commit and push.""" namespace = conf["namespace"] self.clone_repo( - conf["fedpkg"], conf["fas_username"], namespace, name, folder=folder, + conf["fedpkg"], + conf["fas_username"], + namespace, + name, + folder=folder, ) return self.bump(folder, nevrs, conf, name, version, target, new_side_tag) - def bump( - self, folder, nevrs, conf, name, version, target=None, new_side_tag=False - ): + def bump(self, folder, nevrs, conf, name, version, target=None, new_side_tag=False): """Clone the repo, bump the release, commit and push.""" branch = conf["branch"] gitfolder = os.path.join(folder, name) @@ -813,8 +783,8 @@ class MonitoringUtils: nevr_two = nevrs[package_two] version_1, version_2 = [ - [int(x) for x in re.search(r'(\d+)-(\d+)', nevr).groups()] - for nevr in [nevr_one, nevr_two]] + [int(x) for x in re.search(r"(\d+)-(\d+)", nevr).groups()] for nevr in [nevr_one, nevr_two] + ] if version_1 == version_2: return f"{version_1[0]}-{version_1[1]}", True @@ -825,7 +795,7 @@ class MonitoringUtils: def run_command(command, cwd=None): - """ Run the specified command in a specific working directory if one + """Run the specified command in a specific working directory if one is specified. """ output = None @@ -835,9 +805,7 @@ def run_command(command, cwd=None): if "--password" in command: idx = command.index("--password") command[idx + 1] = "" - _log.error( - "Command `{}` return code: `{}`".format(" ".join(command), e.returncode) - ) + _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)) raise MonitoringException("Command failed to run")