-
Notifications
You must be signed in to change notification settings - Fork 72
Add post-test KubeVirtDeprecatedAPIRequested check #5232
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
base: main
Are you sure you want to change the base?
Changes from all commits
c979475
d4b2479
4975066
ed5e4c8
b62637f
12c51bb
03c00d1
528f253
077412a
b18fcab
2288862
31c55b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| """ | ||
| Post-test alerts verification. | ||
|
|
||
| Verifies that critical CNV alerts were not triggered during test execution. | ||
|
|
||
| Jira: https://redhat.atlassian.net/browse/CNV-80353 | ||
| """ | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| import datetime | ||
| import logging | ||
|
|
||
| import pytest | ||
|
|
||
| LOGGER = logging.getLogger(__name__) | ||
|
|
||
| DEPRECATED_API_ALERT = "KubeVirtDeprecatedAPIRequested" | ||
|
|
||
|
|
||
| @pytest.mark.s390x | ||
| @pytest.mark.polarion("CNV-16276") | ||
| @pytest.mark.order("last") | ||
| def test_no_critical_alerts_after_tests(prometheus, request): | ||
| """ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test is not following the jira ticket description. more specifically:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, fixed the test |
||
| Test that critical CNV alerts were not triggered during test execution. | ||
|
|
||
| Preconditions: | ||
| - Prometheus is accessible on the cluster | ||
| - Test execution completed | ||
|
|
||
| Steps: | ||
| 1. Query Prometheus for alerts that fired at any point during test execution | ||
| 2. Check that none of the critical alerts were triggered | ||
|
|
||
| Expected: | ||
| - None of the critical alerts fired during test execution | ||
| """ | ||
| start_time = request.config._test_execution_start_time | ||
| duration_seconds = max(int((datetime.datetime.now(tz=datetime.UTC) - start_time).total_seconds()), 1) | ||
| LOGGER.info( | ||
| f"Checking {DEPRECATED_API_ALERT} alert was not triggered during test execution (last {duration_seconds}s)" | ||
| ) | ||
| query = f'ALERTS{{alertname="{DEPRECATED_API_ALERT}", alertstate="firing"}}[{duration_seconds}s]' | ||
| results = prometheus.query_sampler(query=query) | ||
| assert not results, f"{DEPRECATED_API_ALERT} alert fired during test execution.\n{results}" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ | |
| from typing import Any | ||
|
|
||
| import pytest | ||
| from _pytest.config import Config | ||
| from _pytest.nodes import Item | ||
| from kubernetes.dynamic import DynamicClient | ||
| from ocp_resources.config_map import ConfigMap | ||
| from ocp_resources.namespace import Namespace | ||
|
|
@@ -715,3 +717,25 @@ def assert_incremental_classes_fully_collected(items: list[pytest.Item]) -> None | |
|
|
||
| def _is_xfail_no_run(method: object) -> bool: | ||
| return any(mark.name == "xfail" and mark.kwargs.get("run") is False for mark in getattr(method, "pytestmark", [])) | ||
|
|
||
|
|
||
| def filter_post_test_alerts_tests(items: list[Item], config: Config) -> list[Item]: | ||
| """Filter out post-test alert tests when explicitly skipped or running install/upgrade tests. | ||
|
|
||
| Args: | ||
| items: Collected pytest test items. | ||
| config: Pytest config object. | ||
|
|
||
| Returns: | ||
| Filtered list of test items. | ||
| """ | ||
| if ( | ||
| config.getoption("--skip-post-test-alerts") | ||
| or config.getoption("--install") | ||
| or config.getoption("--upgrade") | ||
| or config.getoption("--upgrade_custom") | ||
|
Comment on lines
+735
to
+736
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hmeir you mentioned that upgrade tests should not be skipped, right? |
||
| ): | ||
| discard_tests, items_to_return = remove_tests_from_list(items=items, filter_str="post_test_alerts") | ||
| config.hook.pytest_deselected(items=discard_tests) | ||
| return items_to_return | ||
| return items | ||
Uh oh!
There was an error while loading. Please reload this page.