From 788baaad76d81503896a3e5738d7996694cc49e0 Mon Sep 17 00:00:00 2001 From: Jeny Sadadia Date: Wed, 18 Sep 2024 16:19:13 +0530 Subject: [PATCH 1/3] Enable passing context variable to email notification templates Add argument to provide context variables to `NotificationMessage` class. Use the context variable to generate email notification message in `Notification` class. Signed-off-by: Jeny Sadadia --- kcidb/monitor/output.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kcidb/monitor/output.py b/kcidb/monitor/output.py index 855aeb20..0039001b 100644 --- a/kcidb/monitor/output.py +++ b/kcidb/monitor/output.py @@ -31,12 +31,14 @@ LOGGER = logging.getLogger(__name__) +# pylint: disable=too-many-instance-attributes class NotificationMessage: """ Message for a notification about a report object state. """ # It's OK pylint: disable=too-many-arguments - def __init__(self, to, subject, body, cc=None, bcc=None, id="", due=None): + def __init__(self, to, subject, body, cc=None, bcc=None, id="", due=None, + context=None): """ Initialize a notification message. @@ -100,6 +102,7 @@ def __init__(self, to, subject, body, cc=None, bcc=None, id="", due=None): self.bcc = bcc self.id = id self.due = due + self.context = context class Notification: @@ -180,6 +183,8 @@ def render(self): ctx = { self.obj.get_type().name: self.obj, } + if self.message.context: + ctx.update(self.message.context) subject = TEMPLATE_ENV.from_string(self.message.subject).render(ctx) subject_extra_characters = \ len(subject) - NOTIFICATION_MESSAGE_SUBJECT_MAX_LEN From ef4b5c138d012f6d51cb40375cfb1e188b3ea8da Mon Sep 17 00:00:00 2001 From: Jeny Sadadia Date: Wed, 18 Sep 2024 16:22:33 +0530 Subject: [PATCH 2/3] Send repo URL as context variable Provide `stable-rc` repo URL as context variable to `stable_rc_revision_description` template. It will enable us to re-use the same template to get revision description information for a different tree such as `omap`. Signed-off-by: Jeny Sadadia --- kcidb/monitor/subscriptions/linux_stable_rc.py | 3 ++- kcidb/templates/stable_rc_revision_description.txt.j2 | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/kcidb/monitor/subscriptions/linux_stable_rc.py b/kcidb/monitor/subscriptions/linux_stable_rc.py index 912540c6..a6033e5c 100644 --- a/kcidb/monitor/subscriptions/linux_stable_rc.py +++ b/kcidb/monitor/subscriptions/linux_stable_rc.py @@ -32,5 +32,6 @@ def match_revision(revision): "Shreeya Patel "], body='{% include "stable_rc_revision_description.txt.j2" %}', cc=["KernelCI Results Staging "], - due=datetime.now(timezone.utc) + timedelta(hours=3) + due=datetime.now(timezone.utc) + timedelta(hours=3), + context={'main_repo_url': repo_url} ),) diff --git a/kcidb/templates/stable_rc_revision_description.txt.j2 b/kcidb/templates/stable_rc_revision_description.txt.j2 index c3a0b719..6d91b37b 100644 --- a/kcidb/templates/stable_rc_revision_description.txt.j2 +++ b/kcidb/templates/stable_rc_revision_description.txt.j2 @@ -29,15 +29,12 @@ REVISION {% if revision.git_commit_hash %} {{- " hash: " + revision.git_commit_hash }} {% endif %} - {# The stable-rc repo's URL #} - {% set stable_rc_repo = 'https://git.kernel.org/pub/scm/linux/' + - 'kernel/git/stable/linux-stable-rc.git' %} {# List of other repo's URLs #} {% set other_repos = revision.repo_branch_checkouts.keys() | - reject('==', stable_rc_repo) | reject("none") | list %} + reject('==', main_repo_url) | reject("none") | list %} Checked out from {{- "\n " + - (([stable_rc_repo] + (revision.repo_branch_checkouts[stable_rc_repo] | list)) | + (([main_repo_url] + (revision.repo_branch_checkouts[main_repo_url] | list)) | reject("none") | join(" ")) }} {% if other_repos %} Also checked out from From dd1de388a2b18bf88969d6e3b1aa45928a9078f1 Mon Sep 17 00:00:00 2001 From: Jeny Sadadia Date: Wed, 18 Sep 2024 16:44:00 +0530 Subject: [PATCH 3/3] Enable email notifications for `omap` tree The report would contain build and boot failures. Signed-off-by: Jeny Sadadia --- kcidb/monitor/subscriptions/linux_omap.py | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 kcidb/monitor/subscriptions/linux_omap.py diff --git a/kcidb/monitor/subscriptions/linux_omap.py b/kcidb/monitor/subscriptions/linux_omap.py new file mode 100644 index 00000000..3fdf5a42 --- /dev/null +++ b/kcidb/monitor/subscriptions/linux_omap.py @@ -0,0 +1,38 @@ +"""Linux omap subscription""" +from datetime import (timezone, datetime, timedelta) + +from kcidb.monitor.output import NotificationMessage as Message + + +def match_revision(revision): + """Match revisions of omap tree""" + # Repo we're interested in + repo_url = "https://git.kernel.org/pub/scm/linux/kernel/git/tmlind/" \ + "linux-omap.git" + + # If the revision is not from omap repo, + # or there are no finished builds + + if repo_url not in revision.repo_branch_checkouts: + return () + + if revision.builds_valid is None: + return () + + # If the revision is not from 'maestro' or 'broonie' origin + if not {c.origin for c in revision.checkouts} & {'maestro', 'broonie'}: + return () + + # Send notification 3 hours after a revision is created/updated + return (Message( + subject='KernelCI report for omap: ' + '{% include "stable_revision_summary.txt.j2" %}', + to=["Kevin Hilman "], + cc=["KernelCI Results Staging ", + "Jeny Sadadia ", + "Gustavo Padovan ", + "Helen Mae Koike Fornazier "], + body='{% include "stable_rc_revision_description.txt.j2" %}', + due=datetime.now(timezone.utc) + timedelta(hours=3), + context={'main_repo_url': repo_url} + ),)