33import pytest
44
55from tests .utils import validate_runbook_url_exists
6- from utilities .constants import CNV_PROMETHEUS_RULES , QUARANTINED
6+ from utilities .constants import CNV_PROMETHEUS_RULES
77
88LOGGER = logging .getLogger (__name__ )
99
1010
11+ def validate_downstream_runbook_url (runbook_urls_from_prometheus_rule : dict [str , str ]) -> None :
12+ error_messages = {}
13+ alerts_without_runbook = []
14+
15+ for alert_name , runbook_url in runbook_urls_from_prometheus_rule :
16+ if not runbook_url :
17+ LOGGER .error (f"For alert: { alert_name } Url not found" )
18+ alerts_without_runbook .append (alert_name )
19+ error = validate_runbook_url_exists (url = runbook_url )
20+ if error :
21+ LOGGER .error (f"Alert { alert_name } url { runbook_url } is not valid" )
22+ error_messages [alert_name ] = runbook_url
23+ if alerts_without_runbook :
24+ LOGGER .error (f"Runbook url missing for following CNV alerts: { alerts_without_runbook } " )
25+ raise AssertionError ("CNV alerts with missing runbook url found." )
26+
27+ if error_messages :
28+ message = f"Downstream runbook url validation failed for the followings: { error_messages } "
29+ LOGGER .error (message )
30+ raise AssertionError (message )
31+
32+
1133class TestRunbookUrlsAndPrometheusRules :
1234 @pytest .mark .polarion ("CNV-10081" )
1335 def test_no_new_prometheus_rules (self , cnv_prometheus_rules_names ):
@@ -19,28 +41,8 @@ def test_no_new_prometheus_rules(self, cnv_prometheus_rules_names):
1941 f"New cnv prometheusrule found: { set (cnv_prometheus_rules_names ) - set (CNV_PROMETHEUS_RULES )} "
2042 )
2143
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- )
2644 @pytest .mark .polarion ("CNV-10084" )
2745 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 )
46+ validate_downstream_runbook_url (
47+ runbook_urls_from_prometheus_rule = cnv_alerts_runbook_urls_from_prometheus_rule .items ()
48+ )
0 commit comments