-
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
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,17 @@ 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 alerts tests, if explicitly asked or if running upgrade/install tests | ||
|
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. please use google docstring formatting |
||
| if ( | ||
| config.getoption("--skip-post-test-alerts") | ||
| or config.getoption("--install") | ||
| or config.getoption("--upgrade") | ||
| or config.getoption("--upgrade_custom") | ||
|
Comment on lines
+727
to
+728
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 | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |||||||||||||||||||||||||||||||||||||
| exit_pytest_execution, | ||||||||||||||||||||||||||||||||||||||
| filter_hpp_tests, | ||||||||||||||||||||||||||||||||||||||
| filter_multiarch_tests, | ||||||||||||||||||||||||||||||||||||||
| filter_post_test_alerts_tests, | ||||||||||||||||||||||||||||||||||||||
| generate_common_template_matrix_dicts, | ||||||||||||||||||||||||||||||||||||||
| generate_instance_type_matrix_dicts, | ||||||||||||||||||||||||||||||||||||||
| get_artifactory_server_url, | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -2493,6 +2494,81 @@ def test_empty_marker_expression_filters_hpp(self): | |||||||||||||||||||||||||||||||||||||
| config.hook.pytest_deselected.assert_called_once_with(items=[item_hpp]) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| class TestFilterPostTestAlertsTests: | ||||||||||||||||||||||||||||||||||||||
| """Test cases for filter_post_test_alerts_tests function.""" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_filters_when_skip_post_test_alerts_flag_set(self): | ||||||||||||||||||||||||||||||||||||||
| """Post-test alert tests are filtered out when --skip-post-test-alerts flag is set.""" | ||||||||||||||||||||||||||||||||||||||
| item_post_test_alerts = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| item_post_test_alerts.keywords = {"post_test_alerts": True} | ||||||||||||||||||||||||||||||||||||||
| item_other = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| item_other.keywords = {"other_test": True} | ||||||||||||||||||||||||||||||||||||||
| config = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| config.getoption.side_effect = lambda flag: flag == "--skip-post-test-alerts" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| result = filter_post_test_alerts_tests(items=[item_post_test_alerts, item_other], config=config) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert result == [item_other] | ||||||||||||||||||||||||||||||||||||||
| config.hook.pytest_deselected.assert_called_once_with(items=[item_post_test_alerts]) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_filters_when_install_flag_set(self): | ||||||||||||||||||||||||||||||||||||||
| """Post-test alert tests are filtered out when --install flag is set.""" | ||||||||||||||||||||||||||||||||||||||
| item_post_test_alerts = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| item_post_test_alerts.keywords = {"post_test_alerts": True} | ||||||||||||||||||||||||||||||||||||||
| item_other = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| item_other.keywords = {"other_test": True} | ||||||||||||||||||||||||||||||||||||||
| config = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| config.getoption.side_effect = lambda flag: flag == "--install" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| result = filter_post_test_alerts_tests(items=[item_post_test_alerts, item_other], config=config) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert result == [item_other] | ||||||||||||||||||||||||||||||||||||||
| config.hook.pytest_deselected.assert_called_once_with(items=[item_post_test_alerts]) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_filters_when_upgrade_flag_set(self): | ||||||||||||||||||||||||||||||||||||||
| """Post-test alert tests are filtered out when --upgrade flag is set.""" | ||||||||||||||||||||||||||||||||||||||
| item_post_test_alerts = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| item_post_test_alerts.keywords = {"post_test_alerts": True} | ||||||||||||||||||||||||||||||||||||||
| item_other = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| item_other.keywords = {"other_test": True} | ||||||||||||||||||||||||||||||||||||||
| config = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| config.getoption.side_effect = lambda flag: flag == "--upgrade" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| result = filter_post_test_alerts_tests(items=[item_post_test_alerts, item_other], config=config) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert result == [item_other] | ||||||||||||||||||||||||||||||||||||||
| config.hook.pytest_deselected.assert_called_once_with(items=[item_post_test_alerts]) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_filters_when_upgrade_custom_flag_set(self): | ||||||||||||||||||||||||||||||||||||||
| """Post-test alert tests are filtered out when --upgrade_custom flag is set.""" | ||||||||||||||||||||||||||||||||||||||
| item_post_test_alerts = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| item_post_test_alerts.keywords = {"post_test_alerts": True} | ||||||||||||||||||||||||||||||||||||||
| item_other = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| item_other.keywords = {"other_test": True} | ||||||||||||||||||||||||||||||||||||||
| config = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| config.getoption.side_effect = lambda flag: flag == "--upgrade_custom" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| result = filter_post_test_alerts_tests(items=[item_post_test_alerts, item_other], config=config) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert result == [item_other] | ||||||||||||||||||||||||||||||||||||||
| config.hook.pytest_deselected.assert_called_once_with(items=[item_post_test_alerts]) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_no_filtering_when_no_flags_set(self): | ||||||||||||||||||||||||||||||||||||||
| """All items are returned unchanged when no filtering flags are set.""" | ||||||||||||||||||||||||||||||||||||||
| item_post_test_alerts = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| item_post_test_alerts.keywords = {"post_test_alerts": True} | ||||||||||||||||||||||||||||||||||||||
| item_other = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| item_other.keywords = {"other_test": True} | ||||||||||||||||||||||||||||||||||||||
| items = [item_post_test_alerts, item_other] | ||||||||||||||||||||||||||||||||||||||
| config = MagicMock() | ||||||||||||||||||||||||||||||||||||||
| config.getoption.side_effect = lambda flag: False | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2556
to
+2564
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. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Avoid the unused lambda parameter. Ruff reports Proposed fix- config.getoption.side_effect = lambda flag: False
+ config.getoption.return_value = False📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.15.21)[warning] 2564-2564: Unused lambda argument: (ARG005) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| result = filter_post_test_alerts_tests(items=items, config=config) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert result == items | ||||||||||||||||||||||||||||||||||||||
| config.hook.pytest_deselected.assert_not_called() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| class TestFilterMultiarchTests: | ||||||||||||||||||||||||||||||||||||||
| """Test cases for filter_multiarch_tests function.""" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.