Skip to content
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

Fix bug #133 #141

Merged
merged 8 commits into from
Jan 23, 2024
Merged
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
4 changes: 4 additions & 0 deletions cli/objects/failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(
failure_type: str,
failed_test_name: Optional[str] = None,
failed_test_junit_path: Optional[str] = None,
ignore: bool = False,
amp-rh marked this conversation as resolved.
Show resolved Hide resolved
):
"""
Initializes the Failure object.
Expand All @@ -35,6 +36,7 @@ def __init__(
failure_type (str): The failure type
failed_test_name (Optional[str], optional): The failed test name. Defaults to None.
failed_test_junit_path (Optional[str], optional): The path to the failed test's junit file. Defaults to None.
ignore (bool): Flag to indicate that the failure should be ignored.
"""
self.logger = get_logger(__name__)

Expand All @@ -46,6 +48,8 @@ def __init__(
self.failed_test_name = failed_test_name
self.failed_test_junit_path = failed_test_junit_path

self.ignore = ignore

def _get_failure_type(self, failure_type: str) -> str:
"""
Gets the failure type. Used to validate the value provided.
Expand Down
9 changes: 9 additions & 0 deletions cli/objects/failure_rule.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fnmatch
from typing import Any
from typing import Optional

from cli.objects.failure import Failure
from cli.objects.rule import Rule


Expand Down Expand Up @@ -185,3 +187,10 @@ def _get_ignore(self, rule_dict: dict[Any, Any]) -> bool:
f'Value for "ignore" is not a boolean or string value in firewatch rule: "{rule_dict}"',
)
exit(1)

def matches_failure(self, failure: Failure) -> bool:
return (
hasattr(self, "step")
and fnmatch.fnmatch(failure.step, self.step)
myakove marked this conversation as resolved.
Show resolved Hide resolved
and failure.failure_type in (self.failure_type, "all")
)
17 changes: 8 additions & 9 deletions cli/objects/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,16 @@ def _find_failures(self, logs_dir: str, junit_dir: str) -> Optional[list[Failure
pod_failures = self._find_pod_failures(logs_dir=logs_dir)
test_failures = self._find_test_failures(junit_dir=junit_dir)
failures_list = []
unique_steps_with_failures = set()

# Combine lists into one list
for test_failure in test_failures:
failures_list.append(test_failure)
for pod_failure in pod_failures:
already_exists = False
for existing_failure in failures_list:
if existing_failure.step == pod_failure.step:
already_exists = True
if not already_exists:
failures_list.append(pod_failure)
for failure in test_failures + pod_failures:
if failure.step not in unique_steps_with_failures:
unique_steps_with_failures.add(failure.step)
if failure_rules := self.firewatch_config.failure_rules:
for rule in failure_rules:
failure.ignore = rule.matches_failure(failure) and rule.ignore
failures_list.append(failure)

if len(failures_list) > 0:
return failures_list
Expand Down
12 changes: 2 additions & 10 deletions cli/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import fnmatch
import os
import shutil
from datetime import datetime
Expand Down Expand Up @@ -325,14 +324,7 @@ def failure_matches_rule(
default_rule = FailureRule(default_rule_dict)

for rule in rules:
if (
hasattr(rule, "step")
and fnmatch.fnmatch(failure.step, rule.step)
and (
(failure.failure_type == rule.failure_type)
or rule.failure_type == "all"
)
):
if rule.matches_failure(failure):
if rule.ignore:
ignored_rules.append(rule)
else:
Expand Down Expand Up @@ -511,7 +503,7 @@ def _get_issue_description(
"""
link_line = f"*Prow Job Link:* [{job_name} #{build_id}|https://prow.ci.openshift.org/view/gs/test-platform-results/logs/{job_name}/{build_id}]"
build_id_line = f"*Build ID:* {build_id}"
firewatch_link_line = f"This {'issue' if success_issue else 'bug'} was filed using [firewatch in OpenShift CI|https://github.com/CSPI-QE/firewatch)]"
firewatch_link_line = f"This {'issue' if success_issue else 'bug'} was filed using [firewatch in OpenShift CI|https://github.com/CSPI-QE/firewatch]"

# If the issue is being created for a failure
if not success_issue:
Expand Down
393 changes: 203 additions & 190 deletions poetry.lock

Large diffs are not rendered by default.

Loading
Loading