-
Notifications
You must be signed in to change notification settings - Fork 23
Implement EWA workflow and tool to parse TCMS Run results #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| #!/usr/bin/python3 | ||
| import typer | ||
| import re | ||
| import nitrate | ||
|
|
||
martinky82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # This script extracts information from the TCMS notes fields as generated | ||
| # by Errata Workflow Automation (EWA). An example entry looks like: | ||
| # | ||
| # ``` | ||
| # [structured-field-start] | ||
| # This is StructuredField version 1. Please, edit with care. | ||
| # | ||
| # [errata-resolution] | ||
| # Old PASSED & New PASSED => WORKING | ||
| # | ||
| # [result-summary] | ||
| # old-files = PASSED [3-0/3] | ||
| # new-files = PASSED [3-0/3] | ||
| # old-avc = PASSED [3-0/3] | ||
| # new-avc = PASSED [3-0/3] | ||
| # old-duration = 0:00:21 [0:00:19 - 0:00:37] | ||
| # new-duration = 0:00:30 [0:00:18 - 0:00:38] | ||
| # | ||
| # [result-details] | ||
| # beaker-task = https://beaker.engineering.redhat.com/tasks/executed?recipe_task_id=203402088&recipe_task_id=203402051&recipe_task_id=203402393&recipe_task_id=203402430&recipe_task_id=203402125&recipe_task_id=203402467&old_pkg_tasks=203402393,203402467,203402430&new_pkg_tasks=203402088,203402125,203402051 | ||
| # tcms-results-version = 3.0 | ||
| # | ||
| # [structured-field-end] | ||
| # ``` | ||
| # Rather than formally parsing this (using qe.py) we just pull out the lines | ||
| # we are interested in using a regular expression. | ||
|
|
||
| # Include only meaningful lines from the notes | ||
| NOTES_INCLUDE_PATTERN = re.compile(r'CR#|=>|-files|-avc|beaker-task') | ||
| # Unless called with --full, skip the Errata Workflow caseruns | ||
| CASERUN_EXCLUDE_PATTERN = re.compile(r'Errata Workflow') | ||
|
|
||
| # get the run details from the run specified by its id and return | ||
| # a multiline string containing the results and for tests which didn't | ||
| # PASS, also usable information from caserun.notes: | ||
| # 1) errata resulotion (comparison of results with unfixed / old and | ||
| # fixed / new builds | ||
| # 2) link to results in Beaker | ||
| # optionally you can enable: | ||
| # full output (include Errata Workflow and print full notes for all tests) | ||
| # color output (include escape codes for colored test status) | ||
| def get_tcms_run_details(run_id: str, *, full: bool = False, color: bool = False) -> str: | ||
| """ | ||
| Fetches and filters TCMS test run details. | ||
| """ | ||
| if not color: | ||
| nitrate.set_color_mode(nitrate.COLOR_OFF) | ||
| else: | ||
| nitrate.set_color_mode(nitrate.COLOR_ON) | ||
|
|
||
| testrun = nitrate.TestRun(int(run_id)) | ||
| output = [] | ||
|
|
||
| for caserun in testrun.caseruns: | ||
| caserun_str = str(caserun) | ||
| notes_str = str(caserun.notes) | ||
|
|
||
| passed = (caserun.status == nitrate.Status('PASSED')) | ||
|
|
||
| output_entry = [] | ||
| if full: | ||
| output_entry.append(caserun_str) | ||
| # The original script used print() which added a newline. | ||
| # To replicate that, we split the notes into lines and add them | ||
| # individually to our list. | ||
| output_entry.extend(notes_str.splitlines()) | ||
| else: | ||
| # filter out Errata Workflow and not useful lines from notes | ||
| if CASERUN_EXCLUDE_PATTERN.search(caserun_str): | ||
| continue | ||
| output_entry.append(caserun_str) | ||
| # add the details from notes only for tests that do not pass | ||
| if not passed: | ||
| for line in notes_str.splitlines(): | ||
| if NOTES_INCLUDE_PATTERN.search(line): | ||
| output_entry.append(line) | ||
| if output_entry: | ||
| output.append(output_entry) | ||
|
|
||
| # Flatten the list of lists into a single list of strings | ||
| flattened_output = [item for sublist in output for item in sublist] | ||
| # Join the strings into a single multiline string | ||
| return "\n".join(flattened_output) | ||
|
|
||
| def main( | ||
| test_run_id: str, | ||
| full: bool = typer.Option(False, help="Show the full, unfiltered output."), | ||
| color: bool = typer.Option(False, help="Enable colorized output.") | ||
| ): | ||
|
|
||
| # get_tcms_run_details returns a single string. | ||
| result = get_tcms_run_details(test_run_id, full=full, color=color) | ||
| if result: | ||
| print(result) | ||
|
|
||
| if __name__ == "__main__": | ||
| typer.run(main) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import logging | ||
| from pydantic import BaseModel, Field | ||
|
|
||
| from beeai_framework.context import RunContext | ||
| from beeai_framework.emitter import Emitter | ||
| from beeai_framework.tools import StringToolOutput, Tool, ToolRunOptions | ||
|
|
||
| from ..ewa_utils import get_tcms_run_details | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class AnalyzeEwaTestRunToolInput(BaseModel): | ||
| run_id: int = Field(description="TCMS Test Run ID (e.g., 12345)") | ||
|
|
||
|
|
||
| class AnalyzeEwaTestRunTool(Tool[AnalyzeEwaTestRunToolInput, ToolRunOptions, StringToolOutput]): | ||
| name = "analyze_ewa_testrun" # type: ignore | ||
| description = ( # type: ignore | ||
| "Analyzes a TCMS test run generated by Errata Workflow Automation (EWA) " | ||
| "and creates a test-case by test-case report." | ||
| ) | ||
| input_schema = AnalyzeEwaTestRunToolInput # type: ignore | ||
|
|
||
| def _create_emitter(self) -> Emitter: | ||
| return Emitter.root().child( | ||
| namespace=["tool", "analyze_ewa_testrun"], | ||
| creator=self, | ||
| ) | ||
|
|
||
| async def _run( | ||
| self, | ||
| input: AnalyzeEwaTestRunToolInput, | ||
| options: ToolRunOptions | None, | ||
| context: RunContext, | ||
| ) -> StringToolOutput: | ||
| try: | ||
| # Fetch the TCMS run details | ||
| run_details = get_tcms_run_details(input.run_id) | ||
|
|
||
| # Return the formatted details | ||
| return StringToolOutput( | ||
| result=run_details | ||
| ) | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Failed to get TCMS run details for {input.run_id}: {e}") | ||
| return StringToolOutput( | ||
| result=f"Error: Failed to get TCMS run details for {input.run_id}: {str(e)}" | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.