From a122575903dc29ca9db84cccea22e025a3ff5785 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 06 2020 16:05:29 +0000 Subject: Rename monitor_gating to monitor_gating_single_build This is more consistent with the monitor_gating_multi_builds and more self-explicit. Signed-off-by: Pierre-Yves Chibon --- diff --git a/monitor_gating.py b/monitor_gating.py deleted file mode 100644 index a7c1d64..0000000 --- a/monitor_gating.py +++ /dev/null @@ -1,318 +0,0 @@ -#!/usr/bin/env python3 - -""" -This is a script to test how dist-git, koji, bodhi, resultsdb, fedora-ci, -greenwave and waiverdb act together and if any piece of them is failing to -do its part. - -Requirements: - - Have installed on your machine - - python3-requests - - bodhi-client - - fedpkg - - fedpkg-stage - - Ensure git is configured correctly in your system (username, email...) - - You should have tests and gating setup in the package's repo you're - playing with - - Fork that repo in your name - - Make sure the repo has the f30 branch - - Ensure your ssh key is unlocked - - A valid kerberos ticket for staging and/or production - -""" - -import argparse -import datetime -import logging -import os -import sys -import tempfile - -import toml - -from utils import MonitoringUtils - -_log = logging.getLogger(__name__) - - -def get_arguments(args): - """ 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", - ) - parser.add_argument( - "--update", - help="Alias for the update, allows by-passing creating the udpate " "", - ) - parser.add_argument( - "--no-pr", - action="store_true", - default=False, - help="Skip testing the testing of pull-requests", - ) - parser.add_argument( - "--staging", - action="store_true", - default=False, - help="Changes to environment in which this runs from prod to staging", - ) - parser.add_argument( - "--auto-update", - action="store_true", - default=False, - help="Wait for the update to be created automatically instead of " - "doing it manually", - ) - parser.add_argument( - "--no-waive", - action="store_true", - default=False, - help="Skip the end of the workflow when the failing tests are waived", - ) - parser.add_argument( - "--conf", - default="monitor_gating.cfg", - help="Configuration file to use, specifying the URLs and all", - ) - - return parser.parse_args(args) - - -def main(args): - """ Main method used by this script. """ - start = datetime.datetime.utcnow() - - args = get_arguments(args) - - conf = toml.load(args.conf) - utils = MonitoringUtils() - - name = conf["name_single"] - namespace = conf["namespace"] - fas_username = conf["fas_username"] - branch = conf["branch"] - - with tempfile.TemporaryDirectory(prefix="ci-test-") as folder: - print(f"Working in {folder}\n") - if not args.nevr: - utils.clone_repo(conf["fedpkg"], namespace, name, folder=folder) - gitfolder = os.path.join(folder, name) - utils.switch_branch(conf["fedpkg"], branch, folder=gitfolder) - utils.bump_release(name, folder=gitfolder) - utils.commit_changes("Bump release", folder=gitfolder) - nevr = utils.get_nevr(conf["fedpkg"], folder=gitfolder) - print(f" Upcoming build : {nevr}") - - if args.no_pr: - # Push to the main repo - utils.push_changes(gitfolder, "origin", branch) - else: - # Add the fork as remote, push to the it, open the PR, - # 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", - folder=gitfolder, - ) - utils.push_changes(gitfolder, fas_username, branch, force=True) - pr_created, pr_id, pr_uid = utils.open_pullrequest( - base_url=conf["pagure_dist_git"], - username=fas_username, - namespace=namespace, - name=name, - branch=branch, - token=conf["pagure_token"], - ) - if pr_created: - # Check that pr pipeline is running - utils.lookup_results_datagrepper( - base_url=conf["datagrepper"], - name="CI (running)", - topic=f"org.centos.{conf['_ci_env']}.ci.dist-git-pr.test.running", - rev=pr_uid, - ) - # Check that CI flag pending was set - utils.get_pr_flag( - base_url=conf["pagure_dist_git"], - username=fas_username, - namespace=namespace, - name=name, - pr_id=pr_id, - flag_username="Fedora CI", - flag_status="pending", - ) - # Check that pr pipeline has finished - utils.lookup_results_datagrepper( - base_url=conf["datagrepper"], - name="CI (complete)", - topic=f"org.centos.{conf['_ci_env']}.ci.dist-git-pr.test.error", - rev=pr_uid, - ) - # Check that CI flag failure was set - utils.get_pr_flag( - base_url=conf["pagure_dist_git"], - username=fas_username, - namespace=namespace, - name=name, - pr_id=pr_id, - flag_username="Fedora CI", - flag_status="error", - duration=25, - ) - # Merge the PR: TODO - utils.merge_pr( - base_url=conf["pagure_dist_git"], - username=fas_username, - namespace=namespace, - name=name, - pr_id=pr_id, - token=conf["pagure_token"], - ) - utils.pull_changes(gitfolder, "origin", branch) - else: - return - - # Build the package - utils.build_package(conf["fedpkg"], folder=gitfolder) - - # Check the tag of the build - utils.get_build_tags( - conf.get("koji_hub"), - nevr, - expected_ends=["updates-candidate", "signing-pending"], - ) - else: - nevr = args.nevr - - # Retrieve or create the update - updateid = utils.get_update_id(nevr, conf["bodhi"]) - if not args.update and not args.auto_update: - utils.create_update(conf["bodhi-cli"], - nevr, - prod=conf["_env"] == "prod", - username=conf.get("bodhi-user"), - password=conf.get("bodhi-password"),) - print(f" Update created : {updateid}") - elif args.auto_update: - print(f" Update automatically created : {updateid}") - else: - updateid = args.update - - # Check the tag of the build - utils.get_build_tags( - conf.get("koji_hub"), - nevr, - expected_ends=["signing-pending", "testing-pending"], - ) - - if not updateid: - utils.finalize(start) - return - - # Check that bodhi notified the pipeline it can run - 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", - bodhi_id=updateid, - ) - - # Check that the CI pipeline is running - utils.lookup_results_datagrepper( - base_url=conf["datagrepper"], - name="CI (running)", - topic=f"org.centos.{conf['_ci_env']}.ci.koji-build.test.running", - nevr=nevr, - ) - # Check at the CI pipeline has completed - utils.lookup_results_datagrepper( - base_url=conf["datagrepper"], - name="CI (complete)", - topic=f"org.centos.{conf['_ci_env']}.ci.koji-build.test.error", - nevr=nevr, - duration=30, - ) - - # Check the tag of the build - utils.get_build_tags( - conf.get("koji_hub"), - nevr, - expected_ends=["testing-pending"], - ) - - # Check that the CI results made it to resultsdb - utils.lookup_ci_resultsdb( - nevr=nevr, name="resultsdb(phx)", url=conf["resultsdb"] - ) - - # Check that resultsdb announced the new results - utils.lookup_results_datagrepper( - base_url=conf["datagrepper"], - name="resultsdb", - topic=f"org.fedoraproject.{conf['_env']}.resultsdb.result.new", - nevr=nevr, - ) - - # Check that greenwave reacted to resultsdb's new results - utils.lookup_results_datagrepper( - base_url=conf["datagrepper"], - name="greenwave", - topic=f"org.fedoraproject.{conf['_env']}.greenwave.decision.update", - nevr=nevr, - ) - - # 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"], - ) - - if not args.no_waive: - utils.waive_update( - conf["bodhi-cli"], - updateid, - prod=conf["_env"] == "prod", - username=conf.get("bodhi-user"), - password=conf.get("bodhi-password"), - ) - - # Check that waiverdb announced the new waiver - utils.lookup_results_datagrepper( - base_url=conf["datagrepper"], - name="waiverdb", - topic=f"org.fedoraproject.{conf['_env']}.waiverdb.waiver.new", - nevr=nevr, - ) - - # Check that greenwave reacted to the new waiver - utils.lookup_results_datagrepper( - base_url=conf["datagrepper"], - name="greenwave", - topic=f"org.fedoraproject.{conf['_env']}.greenwave.decision.update", - nevr=nevr, - ) - - # Check the tag of the build -- build was waived, let is through - utils.get_build_tags( - conf.get("koji_hub"), - nevr, - expected_ends=["f32"], - ) - - utils.finalize(start) - return utils.logs - - -if __name__ == "__main__": - try: - main(sys.argv[1:]) - except KeyboardInterrupt: - print(" -- Interupted --") diff --git a/monitor_gating_single_build.py b/monitor_gating_single_build.py new file mode 100644 index 0000000..a7c1d64 --- /dev/null +++ b/monitor_gating_single_build.py @@ -0,0 +1,318 @@ +#!/usr/bin/env python3 + +""" +This is a script to test how dist-git, koji, bodhi, resultsdb, fedora-ci, +greenwave and waiverdb act together and if any piece of them is failing to +do its part. + +Requirements: + - Have installed on your machine + - python3-requests + - bodhi-client + - fedpkg + - fedpkg-stage + - Ensure git is configured correctly in your system (username, email...) + - You should have tests and gating setup in the package's repo you're + playing with + - Fork that repo in your name + - Make sure the repo has the f30 branch + - Ensure your ssh key is unlocked + - A valid kerberos ticket for staging and/or production + +""" + +import argparse +import datetime +import logging +import os +import sys +import tempfile + +import toml + +from utils import MonitoringUtils + +_log = logging.getLogger(__name__) + + +def get_arguments(args): + """ 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", + ) + parser.add_argument( + "--update", + help="Alias for the update, allows by-passing creating the udpate " "", + ) + parser.add_argument( + "--no-pr", + action="store_true", + default=False, + help="Skip testing the testing of pull-requests", + ) + parser.add_argument( + "--staging", + action="store_true", + default=False, + help="Changes to environment in which this runs from prod to staging", + ) + parser.add_argument( + "--auto-update", + action="store_true", + default=False, + help="Wait for the update to be created automatically instead of " + "doing it manually", + ) + parser.add_argument( + "--no-waive", + action="store_true", + default=False, + help="Skip the end of the workflow when the failing tests are waived", + ) + parser.add_argument( + "--conf", + default="monitor_gating.cfg", + help="Configuration file to use, specifying the URLs and all", + ) + + return parser.parse_args(args) + + +def main(args): + """ Main method used by this script. """ + start = datetime.datetime.utcnow() + + args = get_arguments(args) + + conf = toml.load(args.conf) + utils = MonitoringUtils() + + name = conf["name_single"] + namespace = conf["namespace"] + fas_username = conf["fas_username"] + branch = conf["branch"] + + with tempfile.TemporaryDirectory(prefix="ci-test-") as folder: + print(f"Working in {folder}\n") + if not args.nevr: + utils.clone_repo(conf["fedpkg"], namespace, name, folder=folder) + gitfolder = os.path.join(folder, name) + utils.switch_branch(conf["fedpkg"], branch, folder=gitfolder) + utils.bump_release(name, folder=gitfolder) + utils.commit_changes("Bump release", folder=gitfolder) + nevr = utils.get_nevr(conf["fedpkg"], folder=gitfolder) + print(f" Upcoming build : {nevr}") + + if args.no_pr: + # Push to the main repo + utils.push_changes(gitfolder, "origin", branch) + else: + # Add the fork as remote, push to the it, open the PR, + # 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", + folder=gitfolder, + ) + utils.push_changes(gitfolder, fas_username, branch, force=True) + pr_created, pr_id, pr_uid = utils.open_pullrequest( + base_url=conf["pagure_dist_git"], + username=fas_username, + namespace=namespace, + name=name, + branch=branch, + token=conf["pagure_token"], + ) + if pr_created: + # Check that pr pipeline is running + utils.lookup_results_datagrepper( + base_url=conf["datagrepper"], + name="CI (running)", + topic=f"org.centos.{conf['_ci_env']}.ci.dist-git-pr.test.running", + rev=pr_uid, + ) + # Check that CI flag pending was set + utils.get_pr_flag( + base_url=conf["pagure_dist_git"], + username=fas_username, + namespace=namespace, + name=name, + pr_id=pr_id, + flag_username="Fedora CI", + flag_status="pending", + ) + # Check that pr pipeline has finished + utils.lookup_results_datagrepper( + base_url=conf["datagrepper"], + name="CI (complete)", + topic=f"org.centos.{conf['_ci_env']}.ci.dist-git-pr.test.error", + rev=pr_uid, + ) + # Check that CI flag failure was set + utils.get_pr_flag( + base_url=conf["pagure_dist_git"], + username=fas_username, + namespace=namespace, + name=name, + pr_id=pr_id, + flag_username="Fedora CI", + flag_status="error", + duration=25, + ) + # Merge the PR: TODO + utils.merge_pr( + base_url=conf["pagure_dist_git"], + username=fas_username, + namespace=namespace, + name=name, + pr_id=pr_id, + token=conf["pagure_token"], + ) + utils.pull_changes(gitfolder, "origin", branch) + else: + return + + # Build the package + utils.build_package(conf["fedpkg"], folder=gitfolder) + + # Check the tag of the build + utils.get_build_tags( + conf.get("koji_hub"), + nevr, + expected_ends=["updates-candidate", "signing-pending"], + ) + else: + nevr = args.nevr + + # Retrieve or create the update + updateid = utils.get_update_id(nevr, conf["bodhi"]) + if not args.update and not args.auto_update: + utils.create_update(conf["bodhi-cli"], + nevr, + prod=conf["_env"] == "prod", + username=conf.get("bodhi-user"), + password=conf.get("bodhi-password"),) + print(f" Update created : {updateid}") + elif args.auto_update: + print(f" Update automatically created : {updateid}") + else: + updateid = args.update + + # Check the tag of the build + utils.get_build_tags( + conf.get("koji_hub"), + nevr, + expected_ends=["signing-pending", "testing-pending"], + ) + + if not updateid: + utils.finalize(start) + return + + # Check that bodhi notified the pipeline it can run + 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", + bodhi_id=updateid, + ) + + # Check that the CI pipeline is running + utils.lookup_results_datagrepper( + base_url=conf["datagrepper"], + name="CI (running)", + topic=f"org.centos.{conf['_ci_env']}.ci.koji-build.test.running", + nevr=nevr, + ) + # Check at the CI pipeline has completed + utils.lookup_results_datagrepper( + base_url=conf["datagrepper"], + name="CI (complete)", + topic=f"org.centos.{conf['_ci_env']}.ci.koji-build.test.error", + nevr=nevr, + duration=30, + ) + + # Check the tag of the build + utils.get_build_tags( + conf.get("koji_hub"), + nevr, + expected_ends=["testing-pending"], + ) + + # Check that the CI results made it to resultsdb + utils.lookup_ci_resultsdb( + nevr=nevr, name="resultsdb(phx)", url=conf["resultsdb"] + ) + + # Check that resultsdb announced the new results + utils.lookup_results_datagrepper( + base_url=conf["datagrepper"], + name="resultsdb", + topic=f"org.fedoraproject.{conf['_env']}.resultsdb.result.new", + nevr=nevr, + ) + + # Check that greenwave reacted to resultsdb's new results + utils.lookup_results_datagrepper( + base_url=conf["datagrepper"], + name="greenwave", + topic=f"org.fedoraproject.{conf['_env']}.greenwave.decision.update", + nevr=nevr, + ) + + # 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"], + ) + + if not args.no_waive: + utils.waive_update( + conf["bodhi-cli"], + updateid, + prod=conf["_env"] == "prod", + username=conf.get("bodhi-user"), + password=conf.get("bodhi-password"), + ) + + # Check that waiverdb announced the new waiver + utils.lookup_results_datagrepper( + base_url=conf["datagrepper"], + name="waiverdb", + topic=f"org.fedoraproject.{conf['_env']}.waiverdb.waiver.new", + nevr=nevr, + ) + + # Check that greenwave reacted to the new waiver + utils.lookup_results_datagrepper( + base_url=conf["datagrepper"], + name="greenwave", + topic=f"org.fedoraproject.{conf['_env']}.greenwave.decision.update", + nevr=nevr, + ) + + # Check the tag of the build -- build was waived, let is through + utils.get_build_tags( + conf.get("koji_hub"), + nevr, + expected_ends=["f32"], + ) + + utils.finalize(start) + return utils.logs + + +if __name__ == "__main__": + try: + main(sys.argv[1:]) + except KeyboardInterrupt: + print(" -- Interupted --") diff --git a/runner.py b/runner.py index a4f69cd..08af462 100644 --- a/runner.py +++ b/runner.py @@ -15,7 +15,7 @@ import fedora_messaging.api import fedora_messaging.exceptions import toml -import monitor_gating +import monitor_gating_single_build import monitor_gating_multi_builds s = sched.scheduler(time.time, time.sleep) @@ -63,7 +63,7 @@ def schedule(conf): "arguments": single_args, } ) - output = monitor_gating.main(single_args) + output = monitor_gating_single_build.main(single_args) output_text="\n".join(output) success="[FAILED]" not in output_text notify(