Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

[ART-5863] closure for Real Time team when OCP ships a kernel-rt #585

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 31 additions & 47 deletions elliottlib/cli/find_bugs_kernel_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from jira import JIRA, Issue
from tenacity import retry, stop_after_attempt

from elliottlib import Runtime, brew
from elliottlib import Runtime, brew, early_kernel
from elliottlib.assembly import AssemblyTypes
from elliottlib.cli.common import cli, click_coroutine
from elliottlib.config_model import KernelBugSweepConfig
Expand All @@ -25,13 +25,13 @@ def _search_issues(jira_client, *args, **kwargs):

class FindBugsKernelCli:
def __init__(self, runtime: Runtime, trackers: Sequence[str],
clone: bool, reconcile: bool, comment: bool, dry_run: bool):
clone: bool, reconcile: bool, update_tracker: bool, dry_run: bool):
self._runtime = runtime
self._logger = runtime.logger
self.trackers = list(trackers)
self.clone = clone
self.reconcile = reconcile
self.comment = comment
self.update_tracker = update_tracker
self.dry_run = dry_run
self._id_bugs: Dict[int, Bug] = {} # cache for kernel bug; key is bug_id, value is Bug object
self._tracker_map: Dict[int, Issue] = {} # bug_id -> KMAINT jira mapping
Expand All @@ -57,17 +57,17 @@ async def run(self):
# Getting KMAINT trackers
trackers_keys = self.trackers
trackers: List[Issue] = []
if not trackers_keys:
logger.info("Searching for open trackers...")
trackers = self._find_kmaint_trackers(jira_client, config.tracker_jira.project, config.tracker_jira.labels)
trackers_keys = [t.key for t in trackers]
logger.info("Found %s tracker(s): %s", len(trackers_keys), trackers_keys)
else:
if trackers_keys:
logger.info("Find kernel bugs linked from KMAINT tracker(s): %s", trackers_keys)
for key in trackers_keys:
logger.info("Getting tracker JIRA %s...", key)
tracker = jira_client.issue(key)
trackers.append(tracker)
else:
logger.info("Searching for open trackers...")
trackers = self._find_kmaint_trackers(jira_client, config.tracker_jira.project, config.tracker_jira.labels)
trackers_keys = [t.key for t in trackers]
logger.info("Found %s tracker(s): %s", len(trackers_keys), trackers_keys)

# Get kernel bugs linked from KMAINT trackers
report: Dict[str, Any] = {"kernel_bugs": []}
Expand All @@ -86,9 +86,8 @@ async def run(self):
"summary": bug.summary,
"tracker": tracker,
})
if self.comment:
logger.info("Checking if making a comment on tracker %s is needed...", tracker.key)
self._comment_on_tracker(jira_client, tracker, koji_api, config.target_jira)
if self.update_tracker:
self._update_tracker(jira_client, tracker, koji_api, config.target_jira)

if self.clone and self._id_bugs:
# Clone kernel bugs into OCP Jira
Expand Down Expand Up @@ -175,7 +174,7 @@ def _clone_bugs(self, jira_client: JIRA, bugs: Sequence[Bug], conf: KernelBugSwe
jira_client.create_issue_link("Blocks", issue.key, kmaint_tracker)
result[bug_id] = [issue]
else:
logger.warning("[DRY RUN] Would have created Jira for bug %s", bug_id)
logger.info("[DRY RUN] Would have created Jira for bug %s", bug_id)
else: # this bug is already cloned into OCP Jira
logger.info("Bug %s is already cloned into OCP: %s", bug_id, [issue.key for issue in found_issues])
result[bug_id] = found_issues
Expand All @@ -190,7 +189,7 @@ def _clone_bugs(self, jira_client: JIRA, bugs: Sequence[Bug], conf: KernelBugSwe
if not self.dry_run:
issue.update(fields)
else:
logger.warning("[DRY RUN] Would have updated Jira %s to match bug %s", issue.key, bug_id)
logger.info("[DRY RUN] Would have updated Jira %s to match bug %s", issue.key, bug_id)

return result

Expand All @@ -204,39 +203,24 @@ def _print_report(report: Dict, out: TextIO):
text = f"{bug['tracker']}\t{bug['id']}\t{'N/A' if not cloned_issues else ','.join(cloned_issues)}\t{bug['status']}\t{bug['summary']}"
print_func(text, file=out)

def _comment_on_tracker(self, jira_client: JIRA, tracker: Issue, koji_api: koji.ClientSession,
conf: KernelBugSweepConfig.TargetJiraConfig):
def _update_tracker(self, jira_client: JIRA, tracker: Issue, koji_api: koji.ClientSession,
conf: KernelBugSweepConfig.TargetJiraConfig):
logger = self._runtime.logger
logger.info("Checking if an update to tracker %s is needed...", tracker.key)
# Determine which NVRs have the fix. e.g. ["kernel-5.14.0-284.14.1.el9_2"]
nvrs = re.findall(r"(kernel(?:-rt)?-\S+-\S+)", tracker.fields.summary)
if not nvrs:
raise ValueError("Couldn't determine build NVRs for tracker %s", tracker.key)
nvrs = sorted(nvrs)
# Check if nvrs are already tagged into OCP
logger.info("Getting Brew tags for build(s) %s...", nvrs)
candidate_brew_tag = conf.candidate_brew_tag
prod_brew_tag = conf.prod_brew_tag
build_tags = brew.get_builds_tags(nvrs, koji_api)
shipped = all([any(map(lambda t: t["name"] == prod_brew_tag, tags)) for tags in build_tags])
modified = all([any(map(lambda t: t["name"] == candidate_brew_tag, tags)) for tags in build_tags])
tracker_message = None
nvrs, candidate, shipped = early_kernel.get_tracker_builds_and_tags(logger, tracker, koji_api, conf)

if shipped:
tracker_message = f"Build(s) {nvrs} was/were already shipped and tagged into {prod_brew_tag}."
elif modified:
tracker_message = f"Build(s) {nvrs} was/were already tagged into {candidate_brew_tag}."
if not tracker_message:
logger.info("No need to make a comment on %s", tracker.key)
return
comments = jira_client.comments(tracker.key)
if any(map(lambda comment: comment.body == tracker_message, comments)):
logger.info("A comment was already made on %s", tracker.key)
return
logger.info("Making a comment on tracker %s", tracker.key)
if not self.dry_run:
jira_client.add_comment(tracker.key, tracker_message)
logger.info("Left a comment on tracker %s", tracker.key)
early_kernel.process_shipped_tracker(logger, self.dry_run, jira_client, tracker, nvrs, shipped)
elif candidate:
early_kernel.comment_on_tracker(
logger, self.dry_run, jira_client, tracker,
[f"Build(s) {nvrs} was/were already tagged into {candidate}."]
# do not reword, see NOTE in method
)
else:
logger.warning("[DRY RUN] Would have left a comment on tracker %s", tracker.key)
logger.info("No need to update tracker %s", tracker.key)
return

@staticmethod
def _new_jira_fields_from_bug(bug: Bug, ocp_target_version: str, kmaint_tracker: Optional[str], conf: KernelBugSweepConfig.TargetJiraConfig):
Expand Down Expand Up @@ -303,10 +287,10 @@ def _new_jira_fields_from_bug(bug: Bug, ocp_target_version: str, kmaint_tracker:
is_flag=True,
default=False,
help="Update summary, description, etc for already cloned Jira bugs. Must be used with --clone")
@click.option("--comment",
@click.option("--update-tracker",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update aos-cd-jobs for the new option name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_flag=True,
default=False,
help="Make comments on KMAINT trackers")
help="Update KMAINT trackers state, links, and comments")
@click.option("--dry-run",
is_flag=True,
default=False,
Expand All @@ -315,7 +299,7 @@ def _new_jira_fields_from_bug(bug: Bug, ocp_target_version: str, kmaint_tracker:
@click_coroutine
async def find_bugs_kernel_cli(
runtime: Runtime, trackers: Tuple[str, ...], clone: bool,
reconcile: bool, comment: bool, dry_run: bool):
reconcile: bool, update_tracker: bool, dry_run: bool):
"""Find kernel bugs in Bugzilla for weekly kernel release through OCP.

Example 1: Find kernel bugs and print them out
Expand All @@ -336,7 +320,7 @@ async def find_bugs_kernel_cli(
trackers=trackers,
clone=clone,
reconcile=reconcile,
comment=comment,
update_tracker=update_tracker,
dry_run=dry_run
)
await cli.run()
Loading