Skip to content

Commit 99c3cdb

Browse files
authored
Deleted runbook US url test and improve DS runbook urls tes (RedHatQE#1989)
Test for Upstream runbook urls is not relevant, this PR deletes it and simplify the runbook downstream urls test.
1 parent 50800dd commit 99c3cdb

3 files changed

Lines changed: 61 additions & 98 deletions

File tree

tests/conftest.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from ocp_resources.oauth import OAuth
4747
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
4848
from ocp_resources.pod import Pod
49-
from ocp_resources.prometheus_rule import PrometheusRule
5049
from ocp_resources.resource import Resource, ResourceEditor, get_client
5150
from ocp_resources.role_binding import RoleBinding
5251
from ocp_resources.secret import Secret
@@ -2396,25 +2395,6 @@ def gpu_nodes(nodes):
23962395
return get_nodes_with_label(nodes=nodes, label="nvidia.com/gpu.present")
23972396

23982397

2399-
@pytest.fixture()
2400-
def cnv_prometheus_rule_by_name(cnv_prometheus_rules_matrix__function__):
2401-
prometheus_rule = PrometheusRule(
2402-
namespace=py_config["hco_namespace"],
2403-
name=cnv_prometheus_rules_matrix__function__,
2404-
)
2405-
assert prometheus_rule.exists
2406-
return prometheus_rule
2407-
2408-
2409-
@pytest.fixture()
2410-
def cnv_alerts_from_prometheus_rule(cnv_prometheus_rule_by_name):
2411-
alerts = []
2412-
LOGGER.info(f"Checking rule: {cnv_prometheus_rule_by_name.name}")
2413-
for group in cnv_prometheus_rule_by_name.instance.spec.groups:
2414-
alerts.extend([rule for rule in group["rules"] if rule.get("alert")])
2415-
return alerts
2416-
2417-
24182398
@pytest.fixture(scope="session")
24192399
def worker_machine1(worker_node1):
24202400
machine = Machine(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import logging
2+
3+
import pytest
4+
from ocp_resources.prometheus_rule import PrometheusRule
5+
from pytest_testconfig import config as py_config
6+
7+
LOGGER = logging.getLogger(__name__)
8+
9+
10+
@pytest.fixture(scope="module")
11+
def cnv_prometheus_rules_names(hco_namespace):
12+
return [prometheus_rule.name for prometheus_rule in PrometheusRule.get(namespace=hco_namespace.name)]
13+
14+
15+
@pytest.fixture()
16+
def cnv_alerts_runbook_urls_from_prometheus_rule(cnv_prometheus_rules_matrix__function__):
17+
cnv_prometheus_rule_by_name = PrometheusRule(
18+
namespace=py_config["hco_namespace"],
19+
name=cnv_prometheus_rules_matrix__function__,
20+
)
21+
LOGGER.info(f"Checking rule: {cnv_prometheus_rule_by_name.name}")
22+
return {
23+
alert.get("alert"): alert.get("annotations").get("runbook_url")
24+
for group in cnv_prometheus_rule_by_name.instance.spec.groups
25+
for alert in group["rules"]
26+
if alert.get("alert")
27+
}
Lines changed: 34 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,46 @@
11
import logging
22

33
import pytest
4-
from ocp_resources.prometheus_rule import PrometheusRule
54

65
from tests.utils import validate_runbook_url_exists
76
from utilities.constants import CNV_PROMETHEUS_RULES, QUARANTINED
87

98
LOGGER = logging.getLogger(__name__)
109

1110

12-
def get_downstream_runbook_url(alert_name):
13-
return f"https://github.com/openshift/runbooks/blob/master/alerts/openshift-virtualization-operator/{alert_name}.md"
14-
15-
16-
def get_upstream_runbook_url(alert_name):
17-
return f"https://github.com/kubevirt/monitoring/blob/main/docs/runbooks/{alert_name}.md"
18-
19-
20-
@pytest.fixture(scope="module")
21-
def cnv_prometheus_rules_names(hco_namespace):
22-
return [prometheus_rule.name for prometheus_rule in PrometheusRule.get(namespace=hco_namespace.name)]
23-
24-
25-
@pytest.mark.polarion("CNV-10081")
26-
def test_no_new_prometheus_rules(cnv_prometheus_rules_names):
27-
"""
28-
Since validations for runbook url of all cnv alerts are done via polarion parameterization of prometheusrules,
29-
this test has been added to catch any new cnv prometheusrules that is not part of cnv_prometheus_rules_matrix
30-
"""
31-
assert sorted(CNV_PROMETHEUS_RULES) == sorted(cnv_prometheus_rules_names), (
32-
f"New cnv prometheusrule found: {set(cnv_prometheus_rules_names) - set(CNV_PROMETHEUS_RULES)}"
33-
)
34-
35-
36-
@pytest.fixture()
37-
def cnv_prometheus_rules_unique_alert_names_runbook(cnv_alerts_from_prometheus_rule):
38-
alert_runbook_dict = {}
39-
for alert in cnv_alerts_from_prometheus_rule:
40-
alert_runbook_dict.setdefault(alert["alert"], set()).add(alert["annotations"]["runbook_url"])
41-
alerts_with_multiple_runbooks = {
42-
alert_name: runbook_urls for alert_name, runbook_urls in alert_runbook_dict.items() if len(runbook_urls) > 1
43-
}
44-
assert not alerts_with_multiple_runbooks, (
45-
f"Alerts with multiple different runbook URLs found: {alerts_with_multiple_runbooks}"
46-
)
47-
return alert_runbook_dict
48-
49-
50-
@pytest.mark.polarion("CNV-10083")
51-
def test_runbook_upstream_urls(cnv_prometheus_rules_unique_alert_names_runbook):
52-
url_not_reachable = {}
53-
for alert_name in cnv_prometheus_rules_unique_alert_names_runbook.keys():
54-
url_not_reachable[alert_name] = validate_runbook_url_exists(url=get_upstream_runbook_url(alert_name=alert_name))
55-
not_reachable_url = list(
56-
filter(
57-
lambda _alert_name: url_not_reachable[_alert_name] is not None,
58-
url_not_reachable,
11+
class TestRunbookUrlsAndPrometheusRules:
12+
@pytest.mark.polarion("CNV-10081")
13+
def test_no_new_prometheus_rules(self, cnv_prometheus_rules_names):
14+
"""
15+
Since validations for runbook url of all cnv alerts are done via polarion parameterization of prometheusrules,
16+
this test has been added to catch any new cnv prometheusrules that is not part of cnv_prometheus_rules_matrix
17+
"""
18+
assert sorted(CNV_PROMETHEUS_RULES) == sorted(cnv_prometheus_rules_names), (
19+
f"New cnv prometheusrule found: {set(cnv_prometheus_rules_names) - set(CNV_PROMETHEUS_RULES)}"
5920
)
60-
)
61-
if not_reachable_url:
62-
LOGGER.error(f"Upstream runbook url not reachable for following CNV alerts: {not_reachable_url}")
63-
raise AssertionError("CNV alerts with unreachable runbook urls found.")
64-
6521

66-
@pytest.mark.xfail(
67-
reason=f"{QUARANTINED}: New alerts runbooks added to upstream and not merged yet for downstream, CNV-67890",
68-
run=False,
69-
)
70-
@pytest.mark.polarion("CNV-10084")
71-
def test_runbook_downstream_urls(cnv_prometheus_rules_unique_alert_names_runbook):
72-
error_messages = []
73-
alerts_without_runbook = {}
74-
for alert_name, runbook_url in cnv_prometheus_rules_unique_alert_names_runbook.items():
75-
runbook_url = next(iter(runbook_url))
76-
expected_url = get_downstream_runbook_url(alert_name=alert_name)
77-
if not runbook_url or runbook_url != expected_url:
78-
LOGGER.error(f"For alert: {alert_name}, expected url: {expected_url}, actual url: {runbook_url}")
79-
alerts_without_runbook[alert_name] = alert_name
80-
error = validate_runbook_url_exists(url=expected_url)
81-
if error:
82-
error_messages.append(error)
83-
if alerts_without_runbook:
84-
LOGGER.error(f"Runbook url missing for following CNV alerts: {alerts_without_runbook}")
85-
raise AssertionError("CNV alerts with missing runbook url found.")
86-
87-
if error_messages:
88-
message = f"Downstream runbook url validation failed for the followings: {error_messages}"
89-
LOGGER.error(message)
90-
raise AssertionError(message)
22+
@pytest.mark.xfail(
23+
reason=f"{QUARANTINED}: New alerts runbooks added to upstream and not merged yet for downstream, CNV-67890",
24+
run=False,
25+
)
26+
@pytest.mark.polarion("CNV-10084")
27+
def test_runbook_downstream_urls(self, cnv_alerts_runbook_urls_from_prometheus_rule):
28+
error_messages = {}
29+
alerts_without_runbook = []
30+
31+
for alert_name, runbook_url in cnv_alerts_runbook_urls_from_prometheus_rule.items():
32+
if not runbook_url:
33+
LOGGER.error(f"For alert: {alert_name} Url not found")
34+
alerts_without_runbook.append(alert_name)
35+
error = validate_runbook_url_exists(url=runbook_url)
36+
if error:
37+
LOGGER.error(f"Alert {alert_name} url {runbook_url} is not valid")
38+
error_messages[alert_name] = runbook_url
39+
if alerts_without_runbook:
40+
LOGGER.error(f"Runbook url missing for following CNV alerts: {alerts_without_runbook}")
41+
raise AssertionError("CNV alerts with missing runbook url found.")
42+
43+
if error_messages:
44+
message = f"Downstream runbook url validation failed for the followings: {error_messages}"
45+
LOGGER.error(message)
46+
raise AssertionError(message)

0 commit comments

Comments
 (0)