From 4c5a74896810e50f28c723f21ee0ee66d5dd4bb6 Mon Sep 17 00:00:00 2001 From: Adam Saleh Date: Feb 25 2020 22:41:06 +0000 Subject: [PATCH 1/3] Test for open issues based on packager_workflow_blocker and staging tags in fedora-infrastructure, and schedule next run in 12 hour instead 1 . --- diff --git a/runner.cfg b/runner.cfg index 7a996c0..e59692d 100644 --- a/runner.cfg +++ b/runner.cfg @@ -1,6 +1,9 @@ # Time between two runs in second delay = 3600 +# Time between two blocked runs in second +delay_when_failing = 43200 + # CLI arguments to give to the script testing the single build gating workflow workflow_single_gating_args = "--conf monitor_gating_stg.cfg --auto-update --no-pr" diff --git a/runner.py b/runner.py index 08af462..2956f45 100644 --- a/runner.py +++ b/runner.py @@ -53,6 +53,7 @@ def notify(topic, message): def schedule(conf): """ Run the test and schedules the next one. """ delay = conf["delay"] + delay_when_failing = conf["delay_when_failing"] print("Tests started:", datetime.datetime.utcnow()) try: # Single Build Gating @@ -99,14 +100,21 @@ def schedule(conf): except Exception as err: print(f"Tests failed with: {err}") print(sys.exc_info()[0]) - print(f"Next run in: {delay} seconds") - s.enter(delay, 1, schedule, argument=(conf,)) + + blocking_issues = utils.blocking_issues('staging') + if blocking_issues: + print(f"Next run in: {delay_when_failing} seconds because of {len(blocking_issues)} open issues") + s.enter(delay_when_failing, 1, schedule, argument=(conf,)) + else: + print(f"Next run in: {delay} seconds") + s.enter(delay, 1, schedule, argument=(conf,)) def main(args): """ Schedule the first test and run the scheduler. """ args = get_arguments(args) conf = toml.load(args.conf) + utils.blocking_issues('staging') s.enter(0, 1, schedule, argument=(conf,)) s.run() diff --git a/utils.py b/utils.py index 7fc042c..267530b 100644 --- a/utils.py +++ b/utils.py @@ -17,16 +17,27 @@ import requests _log = logging.getLogger(__name__) +def blocking_issues(*tags): + r = requests.get(f"https://pagure.io/api/0/fedora-infrastructure/issues?status=Open&tags=packager_workflow_blocker") + issues = r.json()['issues'] + if tags: + t = set(tags) + issues = [i for i in issues if t & set(i['tags'])] + for i in issues: + print(f"Found blocking issue https://pagure.io/fedora-infrastructure/issue/{i['id']}") + return issues + + class MonitoringException(Exception): """The base class for all exceptions raised by this script.""" - class MonitoringUtils: def __init__(self): """ Instanciate the object. """ self.logs = [] + def print_user(self, content, success=None): """ Prints the specified content to the user. """ From 617356ac1500dc83df6deceaf78089de9e057d9d Mon Sep 17 00:00:00 2001 From: Adam Saleh Date: Feb 26 2020 11:35:39 +0000 Subject: [PATCH 2/3] Flake fixes, added pre-commit and flake config. --- diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..2cdb126 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +ignore = E128, W503 +max-line-length = 120 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c8cc69e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: check-ast + - id: check-merge-conflict + - id: check-toml + - id: debug-statements +- repo: https://gitlab.com/PyCQA/flake8 + rev: master + hooks: + - id: flake8 diff --git a/runner.py b/runner.py index 2956f45..a2e95da 100644 --- a/runner.py +++ b/runner.py @@ -42,7 +42,7 @@ def notify(topic, message): body=message ) fedora_messaging.api.publish(msg) - except fedora_messaging.exceptions.PublishReturned as e: + except fedora_messaging.exceptions.PublishReturned as err: print(f"Fedora Messaging broker rejected message {msg.id}: {err}") except fedora_messaging.exceptions.ConnectionException as err: print(f"Error sending message {msg.id}: {err}") @@ -65,8 +65,8 @@ def schedule(conf): } ) output = monitor_gating_single_build.main(single_args) - output_text="\n".join(output) - success="[FAILED]" not in output_text + output_text = "\n".join(output) + success = "[FAILED]" not in output_text notify( topic=f"single-build.end.{success}", message={ @@ -85,8 +85,8 @@ def schedule(conf): } ) output = monitor_gating_multi_builds.main(multi_args) - output_text="\n".join(output) - success="[FAILED]" not in output_text + output_text = "\n".join(output) + success = "[FAILED]" not in output_text notify( topic=f"multi-build.end.{success}", message={ @@ -100,7 +100,7 @@ def schedule(conf): except Exception as err: print(f"Tests failed with: {err}") print(sys.exc_info()[0]) - + blocking_issues = utils.blocking_issues('staging') if blocking_issues: print(f"Next run in: {delay_when_failing} seconds because of {len(blocking_issues)} open issues") diff --git a/utils.py b/utils.py index 267530b..b5e020a 100644 --- a/utils.py +++ b/utils.py @@ -18,26 +18,33 @@ _log = logging.getLogger(__name__) def blocking_issues(*tags): - r = requests.get(f"https://pagure.io/api/0/fedora-infrastructure/issues?status=Open&tags=packager_workflow_blocker") - issues = r.json()['issues'] - if tags: - t = set(tags) - issues = [i for i in issues if t & set(i['tags'])] - for i in issues: - print(f"Found blocking issue https://pagure.io/fedora-infrastructure/issue/{i['id']}") + """Lists blocking issues we track in the fedora-infrastructure project.""" + api = f"https://pagure.io/api/0/fedora-infrastructure/issues" + q = "?status=Open&tags=packager_workflow_blocker" + issues = [] + try: + r = requests.get(api + q) + issues = r.json()['issues'] + if tags: + t = set(tags) + issues = [i for i in issues if t & set(i['tags'])] + for i in issues: + print(f"Found blocking issue https://pagure.io/fedora-infrastructure/issue/{i['id']}") + except Exception as e: + print(f"Error when querying pagure for blocking issues: {e}") return issues class MonitoringException(Exception): """The base class for all exceptions raised by this script.""" + class MonitoringUtils: def __init__(self): """ Instanciate the object. """ self.logs = [] - def print_user(self, content, success=None): """ Prints the specified content to the user. """ @@ -56,7 +63,6 @@ class MonitoringUtils: self.logs.append(f"{time} - {content}") print(f"{time} - {content}", end=end, flush=True) - def clone_repo(self, command, namespace, name, folder): """ Clone the specified git repo into the specified folder. """ @@ -77,7 +83,6 @@ class MonitoringUtils: except MonitoringException: 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 specified url. @@ -90,7 +95,6 @@ class MonitoringUtils: except MonitoringException: 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. """ @@ -102,7 +106,6 @@ class MonitoringUtils: except MonitoringException: self.print_user(info_log, success=False) - def bump_release(self, name, folder): """ Bump the release of the spec file the specified git repo. """ @@ -114,7 +117,6 @@ class MonitoringUtils: except MonitoringException: 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 with the specified commit log. @@ -127,7 +129,6 @@ class MonitoringUtils: except MonitoringException: self.print_user(info_log, success=False) - def push_changes(self, folder, target, branch, force=False): """ Push all changes using git. """ @@ -142,7 +143,6 @@ class MonitoringUtils: except MonitoringException: self.print_user(info_log, success=False) - def pull_changes(self, folder, target, branch): """ Pull all changes using git. """ @@ -155,7 +155,6 @@ class MonitoringUtils: except MonitoringException: 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 the specified branch. @@ -193,7 +192,6 @@ class MonitoringUtils: 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 """ @@ -206,7 +204,6 @@ class MonitoringUtils: except MonitoringException: self.print_user(info_log, success=False) - def build_package(self, command, folder, target=None): """ Build the package in the current branch """ @@ -221,7 +218,6 @@ class MonitoringUtils: except MonitoringException: 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 """ @@ -239,7 +235,6 @@ class MonitoringUtils: except MonitoringException: 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. """ @@ -303,7 +298,6 @@ class MonitoringUtils: info_log = f"Retrieving koji tags: {tags}" self.print_user(info_log, success=success) - def create_update(self, command, item, prod=True, username=None, password=None, from_tag=False): """ Create the update for the package built. """ @@ -335,7 +329,6 @@ class MonitoringUtils: except MonitoringException: self.print_user(info_log, success=False) - def get_update_id(self, nevr, url): """ Retrieve the update identifier from bodhi for the given nevr. """ start = datetime.datetime.utcnow() @@ -363,7 +356,6 @@ class MonitoringUtils: self.print_user(info_log, success=success) return updateid - def lookup_results_datagrepper( self, base_url, name, topic, nevr=None, nevrs=None, rev=None, bodhi_id=None, start=None, duration=15 @@ -416,8 +408,8 @@ class MonitoringUtils: # New message format from the CI pipeline for koji builds if ( - "ci.koji-build" in message["topic"] and - message["msg"]["artifact"]["nvr"] == nevr + "ci.koji-build" in message["topic"] + and message["msg"]["artifact"]["nvr"] == nevr ): if message["topic"].endswith("test.complete"): success = True @@ -462,9 +454,8 @@ class MonitoringUtils: 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 @@ -475,9 +466,8 @@ class MonitoringUtils: 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 @@ -512,7 +502,6 @@ class MonitoringUtils: info_log += f" - ran for: {(end - start).seconds}s" self.print_user(info_log, success=success) - def lookup_ci_resultsdb(self, nevr, name, url): """ Check the CI results in the specified resultsdb for results about our specified build. @@ -560,7 +549,6 @@ class MonitoringUtils: info_log += f" - ran for: {(end - start).seconds}s" self.print_user(info_log, success=success) - def waive_update(self, command, updateid, prod=True, username=None, password=None): """ Waive all the tests results for the specified update using bodhi's CLI. @@ -587,7 +575,6 @@ class MonitoringUtils: except MonitoringException: self.print_user(info_log, success=False) - def get_pr_flag( self, base_url, @@ -641,7 +628,6 @@ class MonitoringUtils: self.print_user(info_log, success=success) - def merge_pr(self, base_url, username, namespace, name, pr_id, token): """ Merge the specified PR """ @@ -661,7 +647,6 @@ class MonitoringUtils: self.print_user(info_log, success=success) - def finalize(self, start): """ End data returned. """ end = datetime.datetime.utcnow() @@ -686,7 +671,6 @@ class MonitoringUtils: self.print_user(info_log, success=False) return side_tag_name - def clone_and_bump(self, folder, nevrs, conf, name, target=None, new_side_tag=False): """Clone the repo, bump the release, commit and push.""" namespace = conf["namespace"] From 7d1f9ceaf244bee2beea37ed48909ee5d7df5fda Mon Sep 17 00:00:00 2001 From: Adam Saleh Date: Feb 26 2020 15:59:46 +0000 Subject: [PATCH 3/3] Tags to search blokcing issues no longer hardcoded. --- diff --git a/runner.cfg b/runner.cfg index e59692d..06cd659 100644 --- a/runner.cfg +++ b/runner.cfg @@ -4,6 +4,9 @@ delay = 3600 # Time between two blocked runs in second delay_when_failing = 43200 +# blocker issue tags, issue has to have all of them +blocker_tags = ['packager_workflow_blocker', 'staging'] + # CLI arguments to give to the script testing the single build gating workflow workflow_single_gating_args = "--conf monitor_gating_stg.cfg --auto-update --no-pr" diff --git a/runner.py b/runner.py index a2e95da..0c3be7b 100644 --- a/runner.py +++ b/runner.py @@ -54,6 +54,7 @@ def schedule(conf): """ Run the test and schedules the next one. """ delay = conf["delay"] delay_when_failing = conf["delay_when_failing"] + blocker_tags = conf["blocker_tags"] print("Tests started:", datetime.datetime.utcnow()) try: # Single Build Gating @@ -101,7 +102,7 @@ def schedule(conf): print(f"Tests failed with: {err}") print(sys.exc_info()[0]) - blocking_issues = utils.blocking_issues('staging') + blocking_issues = utils.blocking_issues(blocker_tags) if blocking_issues: print(f"Next run in: {delay_when_failing} seconds because of {len(blocking_issues)} open issues") s.enter(delay_when_failing, 1, schedule, argument=(conf,)) @@ -114,7 +115,6 @@ def main(args): """ Schedule the first test and run the scheduler. """ args = get_arguments(args) conf = toml.load(args.conf) - utils.blocking_issues('staging') s.enter(0, 1, schedule, argument=(conf,)) s.run() diff --git a/utils.py b/utils.py index b5e020a..a621d23 100644 --- a/utils.py +++ b/utils.py @@ -17,16 +17,20 @@ import requests _log = logging.getLogger(__name__) -def blocking_issues(*tags): - """Lists blocking issues we track in the fedora-infrastructure project.""" +def blocking_issues(tags): + """Lists blocking issues we track in the fedora-infrastructure project. + """ + if not tags: + print(f"No tags to filter blocking issues by, returning empty.") + return [] api = f"https://pagure.io/api/0/fedora-infrastructure/issues" - q = "?status=Open&tags=packager_workflow_blocker" + q = f"?status=Open&tags={tags[0]}" issues = [] try: r = requests.get(api + q) issues = r.json()['issues'] if tags: - t = set(tags) + t = set(tags[1:]) issues = [i for i in issues if t & set(i['tags'])] for i in issues: print(f"Found blocking issue https://pagure.io/fedora-infrastructure/issue/{i['id']}")