1- import difflib
21import logging
3- import os
4- import re
5- import subprocess
62
73import pytest
84from validatedpatterns_tests .interop import subscription
@@ -21,100 +17,9 @@ def test_subscription_status_hub(openshift_dyn_client):
2117 "multicluster-engine" : ["multicluster-engine" ],
2218 }
2319
24- (
25- operator_versions ,
26- missing_subs ,
27- unhealthy_subs ,
28- missing_installplans ,
29- upgrades_pending ,
30- ) = subscription .subscription_status (openshift_dyn_client , expected_subs )
31-
32- if missing_subs :
33- logger .error (f"FAIL: The following subscriptions are missing: { missing_subs } " )
34- if unhealthy_subs :
35- logger .error (
36- f"FAIL: The following subscriptions are unhealthy: { unhealthy_subs } "
37- )
38- if missing_installplans :
39- logger .error (
40- f"FAIL: The install plan for the following subscriptions is missing: { missing_installplans } "
41- )
42- if upgrades_pending :
43- logger .error (
44- f"FAIL: The following subscriptions are in UpgradePending state: { upgrades_pending } "
45- )
46-
47- cluster_version = subscription .openshift_version (openshift_dyn_client )
48- logger .info (f"Openshift version:\n { cluster_version .instance .status .history } " )
49-
50- if os .getenv ("EXTERNAL_TEST" ) != "true" :
51- shortversion = re .sub ("(.[0-9]+$)" , "" , os .getenv ("OPENSHIFT_VER" ))
52- currentfile = os .getcwd () + "/operators_hub_current"
53- sourceFile = open (currentfile , "w" )
54- for line in operator_versions :
55- logger .info (line )
56- print (line , file = sourceFile )
57- sourceFile .close ()
58-
59- logger .info ("Clone operator-versions repo" )
60- try :
61- operator_versions_repo = (
62- "[email protected] :mpqe/mps/vp/operator-versions.git" 63- )
64- clone = subprocess .run (
65- ["git" , "clone" , operator_versions_repo ], capture_output = True , text = True
66- )
67- logger .info (clone .stdout )
68- logger .info (clone .stderr )
69- except Exception :
70- pass
71-
72- previouspath = os .getcwd () + f"/operator-versions/mcgitops_hub_{ shortversion } "
73- previousfile = f"mcgitops_hub_{ shortversion } "
74-
75- logger .info ("Ensure previous file exists" )
76- checkpath = os .path .exists (previouspath )
77- logger .info (checkpath )
78-
79- if checkpath is True :
80- logger .info ("Diff current operator list with previous file" )
81- diff = opdiff (open (previouspath ).readlines (), open (currentfile ).readlines ())
82- diffstring = "" .join (diff )
83- logger .info (diffstring )
84-
85- logger .info ("Write diff to file" )
86- sourceFile = open ("operator_diffs_hub.log" , "w" )
87- print (diffstring , file = sourceFile )
88- sourceFile .close ()
89- else :
90- logger .info ("Skipping operator diff - previous file not found" )
91-
92- if missing_subs or unhealthy_subs or missing_installplans or upgrades_pending :
93- err_msg = "Subscription status check failed"
20+ err_msg = subscription .subscription_status (openshift_dyn_client , expected_subs )
21+ if err_msg :
9422 logger .error (f"FAIL: { err_msg } " )
9523 assert False , err_msg
9624 else :
97- # Only push the new operarator list if the test passed
98- # and we are not testing a pre-release operator nor
99- # running externally
100- if os .getenv ("EXTERNAL_TEST" ) != "true" :
101- if checkpath is True and not os .environ ["INDEX_IMAGE" ]:
102- os .remove (previouspath )
103- os .rename (currentfile , previouspath )
104-
105- cwd = os .getcwd () + "/operator-versions"
106- logger .info (f"CWD: { cwd } " )
107-
108- logger .info ("Push new operator list" )
109- subprocess .run (["git" , "add" , previousfile ], cwd = cwd )
110- subprocess .run (
111- ["git" , "commit" , "-m" , "Update operator versions list" ],
112- cwd = cwd ,
113- )
114- subprocess .run (["git" , "push" ], cwd = cwd )
115-
11625 logger .info ("PASS: Subscription status check passed" )
117-
118-
119- def opdiff (* args ):
120- return filter (lambda x : not x .startswith (" " ), difflib .ndiff (* args ))
0 commit comments