| |
@@ -11,33 +11,67 @@
|
| |
import os
|
| |
import subprocess
|
| |
import time
|
| |
+ import re
|
| |
|
| |
import requests
|
| |
|
| |
_log = logging.getLogger(__name__)
|
| |
|
| |
|
| |
- def blocking_issues(tags):
|
| |
+ def report_failure(project, token, env, workflow, monit_utils):
|
| |
+ """ 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"
|
| |
+ title = f"Failure in {env} of the {workflow} packager workflow"
|
| |
+ logs = "\n".join(monit_utils.logs)
|
| |
+ content = f"""A run of monitor-gating has just failed in {env} for the {workflow} workflow.
|
| |
+
|
| |
+ The suspects are '{", ".join(monit_utils.failed)}'.
|
| |
+
|
| |
+ Full log:
|
| |
+ ````
|
| |
+ {logs}
|
| |
+ ````
|
| |
+ """
|
| |
+ tag = env
|
| |
+
|
| |
+ data = {
|
| |
+ "title": title,
|
| |
+ "content": content,
|
| |
+ "tag": tag,
|
| |
+ }
|
| |
+ headers = {
|
| |
+ "Authorization": f"token {token}",
|
| |
+ }
|
| |
+
|
| |
+ req = requests.post(url, data=data, headers=headers)
|
| |
+ if not req.ok:
|
| |
+ print(f"Error when trying to open a ticket at: {url} to report the failure", flush=True)
|
| |
+
|
| |
+
|
| |
+ def blocking_issues(project, 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 = f"?status=Open&tags={tags[0]}"
|
| |
+
|
| |
+ api = f"https://pagure.io/api/0/{project}/issues?status=Open&tags={tags[0]}"
|
| |
issues = []
|
| |
try:
|
| |
- r = requests.get(api + q)
|
| |
- issues = r.json()["issues"]
|
| |
- if 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']}"
|
| |
- )
|
| |
+ r = requests.get(api)
|
| |
+ if not r.ok:
|
| |
+ print(f"Failed to query: {api} -- returned : {r.status_code}", flush=True)
|
| |
+ else:
|
| |
+ issues = r.json()["issues"]
|
| |
+ if 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/{project}/issue/{i['id']}", flush=True)
|
| |
except Exception as e:
|
| |
- print(f"Error when querying pagure for blocking issues: {e}")
|
| |
+ print(f"Error when querying pagure for blocking issues: {e}", flush=True)
|
| |
return issues
|
| |
|
| |
|
| |
@@ -49,6 +83,7 @@
|
| |
def __init__(self):
|
| |
""" Instanciate the object. """
|
| |
self.logs = []
|
| |
+ self.failed = []
|
| |
|
| |
def print_user(self, content, success=None):
|
| |
""" Prints the specified content to the user.
|
| |
@@ -81,17 +116,24 @@
|
| |
[command, "--user", username, "clone", f"{namespace}/{name}"],
|
| |
cwd=folder,
|
| |
)
|
| |
- clone_folder = os.path.join(folder, name)
|
| |
- run_command(
|
| |
- ["git", "config", "user.name", "packagerbot"], cwd=clone_folder,
|
| |
- )
|
| |
- run_command(
|
| |
- ["git", "config", "user.email", "admin@fedoraproject.org"],
|
| |
- cwd=clone_folder,
|
| |
- )
|
| |
- self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("git/dist-git")
|
| |
self.print_user(info_log, success=False)
|
| |
+ else:
|
| |
+ try:
|
| |
+ # Assume these commands can't fail
|
| |
+ clone_folder = os.path.join(folder, name)
|
| |
+ run_command(
|
| |
+ ["git", "config", "user.name", "packagerbot"], cwd=clone_folder,
|
| |
+ )
|
| |
+ run_command(
|
| |
+ ["git", "config", "user.email", "admin@fedoraproject.org"],
|
| |
+ cwd=clone_folder,
|
| |
+ )
|
| |
+ self.print_user(info_log, success=True)
|
| |
+ except MonitoringException:
|
| |
+ self.failed.append("git")
|
| |
+ 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
|
| |
@@ -103,6 +145,7 @@
|
| |
run_command(["git", "remote", "add", name, url], cwd=folder)
|
| |
self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("git")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
def switch_branch(self, command, name, folder):
|
| |
@@ -114,17 +157,23 @@
|
| |
run_command([command, "switch-branch", f"{name}"], cwd=folder)
|
| |
self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("fedpkg")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
- def bump_release(self, name, folder):
|
| |
+ def bump_release(self, name, version, folder):
|
| |
""" 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:
|
| |
- run_command(["rpmdev-bumpspec", f"{name}.spec"], cwd=folder)
|
| |
- self.print_user(info_log, success=True)
|
| |
+ if version:
|
| |
+ run_command(["rpmdev-bumpspec", f"{name}.spec", "-n", f"{version}"], cwd=folder)
|
| |
+ self.print_user(info_log, success=True)
|
| |
+ else:
|
| |
+ run_command(["rpmdev-bumpspec", f"{name}.spec"], cwd=folder)
|
| |
+ self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("rpmdev-bumspec")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
def commit_changes(self, commit_log, folder):
|
| |
@@ -137,6 +186,7 @@
|
| |
run_command(["git", "commit", "-asm", commit_log], cwd=folder)
|
| |
self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("git")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
def push_changes(self, folder, target, branch, force=False):
|
| |
@@ -151,6 +201,7 @@
|
| |
run_command(cmd, cwd=folder)
|
| |
self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("git/dist-git")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
def pull_changes(self, folder, target, branch):
|
| |
@@ -163,6 +214,7 @@
|
| |
run_command(cmd, cwd=folder)
|
| |
self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("git/dist-git")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
def open_pullrequest(self, base_url, username, namespace, name, branch, token):
|
| |
@@ -172,7 +224,7 @@
|
| |
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",]
|
| |
+ [base_url.rstrip("/"), "api/0", namespace, name, "pull-request/new"]
|
| |
)
|
| |
data = {
|
| |
"branch_to": branch,
|
| |
@@ -190,6 +242,7 @@
|
| |
success = False
|
| |
pr_id = None
|
| |
pr_uid = None
|
| |
+ self.failed.append("dist-git")
|
| |
else:
|
| |
output = req.json()
|
| |
pr_id = str(output["id"])
|
| |
@@ -212,6 +265,7 @@
|
| |
self.print_user(info_log, success=True)
|
| |
return nevr.strip().decode("utf-8")
|
| |
except MonitoringException:
|
| |
+ self.failed.append("fedpkg")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
def build_package(self, command, folder, target=None):
|
| |
@@ -226,6 +280,7 @@
|
| |
run_command(command, cwd=folder)
|
| |
self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("koji")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
def chain_build_packages(self, command, packages, folder, target=None):
|
| |
@@ -245,6 +300,7 @@
|
| |
run_command(command, cwd=folder)
|
| |
self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("koji")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
def get_build_tags(self, koji_url, nevr, expected_ends):
|
| |
@@ -258,9 +314,7 @@
|
| |
"koji",
|
| |
]
|
| |
if koji_url:
|
| |
- command.extend(
|
| |
- ["-s", koji_url,]
|
| |
- )
|
| |
+ command.extend(["-s", koji_url])
|
| |
command.extend(["call", "listTags", nevr])
|
| |
|
| |
success = False
|
| |
@@ -303,6 +357,8 @@
|
| |
break
|
| |
|
| |
info_log = f"Retrieving koji tags: {tags}"
|
| |
+ if not success:
|
| |
+ self.failed.append("koji")
|
| |
self.print_user(info_log, success=success)
|
| |
|
| |
def create_update(
|
| |
@@ -336,6 +392,7 @@
|
| |
run_command(command)
|
| |
self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("bodhi")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
def get_update_id(self, nevr, url):
|
| |
@@ -356,6 +413,7 @@
|
| |
|
| |
if (datetime.datetime.utcnow() - start).seconds > (15 * 60):
|
| |
success = False
|
| |
+ self.failed.append("bodhi")
|
| |
info_log = f"Update for {nevr} not created within 15 minutes"
|
| |
break
|
| |
|
| |
@@ -514,6 +572,8 @@
|
| |
end = datetime.datetime.utcnow()
|
| |
info_log += f" - ran for: {(end - start_lookup).seconds}s"
|
| |
self.print_user(info_log, success=success)
|
| |
+ if not success:
|
| |
+ self.failed.append("datagrepper")
|
| |
|
| |
def lookup_ci_resultsdb(self, nevr, name, url):
|
| |
""" Check the CI results in the specified resultsdb for results about
|
| |
@@ -563,6 +623,8 @@
|
| |
end = datetime.datetime.utcnow()
|
| |
info_log += f" - ran for: {(end - start).seconds}s"
|
| |
self.print_user(info_log, success=success)
|
| |
+ if not success:
|
| |
+ 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
|
| |
@@ -588,6 +650,7 @@
|
| |
run_command(command)
|
| |
self.print_user(info_log, success=True)
|
| |
except MonitoringException:
|
| |
+ self.failed.append("waiverdb")
|
| |
self.print_user(info_log, success=False)
|
| |
|
| |
def get_pr_flag(
|
| |
@@ -642,6 +705,8 @@
|
| |
break
|
| |
|
| |
self.print_user(info_log, success=success)
|
| |
+ if not success:
|
| |
+ self.failed.append("dist-git")
|
| |
|
| |
def merge_pr(self, base_url, username, namespace, name, pr_id, token):
|
| |
""" Merge the specified PR
|
| |
@@ -661,6 +726,8 @@
|
| |
success = True
|
| |
|
| |
self.print_user(info_log, success=success)
|
| |
+ if not success:
|
| |
+ self.failed.append("dist-git")
|
| |
|
| |
def finalize(self, start):
|
| |
""" End data returned. """
|
| |
@@ -683,11 +750,12 @@
|
| |
self.print_user(info_log, success=True)
|
| |
except (MonitoringException, Exception) as err:
|
| |
print(err)
|
| |
+ self.failed.append("dist-git")
|
| |
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
|
| |
+ self, folder, nevrs, conf, name, version, target=None, new_side_tag=False
|
| |
):
|
| |
"""Clone the repo, bump the release, commit and push."""
|
| |
namespace = conf["namespace"]
|
| |
@@ -703,7 +771,11 @@
|
| |
if new_side_tag:
|
| |
side_tag_name = self.create_side_tag(conf["fedpkg"], folder=gitfolder)
|
| |
target = side_tag_name
|
| |
- self.bump_release(name, folder=gitfolder)
|
| |
+ if version:
|
| |
+ version += version
|
| |
+ self.bump_release(name, version, folder=gitfolder)
|
| |
+ else:
|
| |
+ self.bump_release(name, version=0, folder=gitfolder)
|
| |
self.commit_changes("Bump release", folder=gitfolder)
|
| |
nevr = self.get_nevr(conf["fedpkg"], folder=gitfolder)
|
| |
nevrs[name] = nevr
|
| |
@@ -712,6 +784,25 @@
|
| |
print(f" Upcoming build : {nevr}")
|
| |
return (nevrs, target)
|
| |
|
| |
+ def nevrs_synced(self, nevrs, conf):
|
| |
+ package_one = conf["name_multi_1"]
|
| |
+ package_two = conf["name_multi_2"]
|
| |
+
|
| |
+ nevr_one = nevrs[package_one]
|
| |
+ nevr_two = nevrs[package_two]
|
| |
+
|
| |
+ if nevr_one.startswith(package_one):
|
| |
+ release_one = nevr_one[len(package_one):]
|
| |
+ version = int(re.search(r'\d+', nevr_one).group())
|
| |
+
|
| |
+ if nevr_two.startswith(package_two):
|
| |
+ release_two = nevr_one[len(package_two):]
|
| |
+
|
| |
+ if release_one != release_two:
|
| |
+ return version, False
|
| |
+
|
| |
+ return version, True
|
| |
+
|
| |
|
| |
def run_command(command, cwd=None):
|
| |
""" Run the specified command in a specific working directory if one
|
| |