18
18
19
19
from scripts .upload_artifact_s3 import upload_artifact_s3
20
20
from tests .e2e .utils import client as client_utils
21
- from tests .e2e .utils import ols_installer
21
+ from tests .e2e .utils import cluster , ols_installer
22
+ from tests .e2e .utils .adapt_ols_config import adapt_ols_config
22
23
from tests .e2e .utils .wait_for_ols import wait_for_ols
23
24
from tests .scripts .must_gather import must_gather
24
25
@@ -45,11 +46,38 @@ def pytest_sessionstart():
45
46
# OLS_URL env only needs to be set when running against a local ols instance,
46
47
# when ols is run against a cluster the url is retrieved from the cluster.
47
48
ols_url = os .getenv ("OLS_URL" , "" )
48
-
49
49
if "localhost" not in ols_url :
50
50
on_cluster = True
51
51
try :
52
- ols_url , token , metrics_token = ols_installer .install_ols ()
52
+ result = cluster .run_oc (
53
+ [
54
+ "get" ,
55
+ "clusterserviceversion" ,
56
+ "-n" ,
57
+ "openshift-lightspeed" ,
58
+ "-o" ,
59
+ "json" ,
60
+ ]
61
+ )
62
+ csv_data = json .loads (result .stdout )
63
+ print (csv_data )
64
+
65
+ if not csv_data ["items" ]:
66
+ print ("OLS Operator is not installed yet." )
67
+ ols_url , token , metrics_token = ols_installer .install_ols ()
68
+ else :
69
+ print ("OLS Operator is already installed. Skipping install." )
70
+ provider = os .getenv ("PROVIDER" , "openai" )
71
+ creds = os .getenv ("PROVIDER_KEY_PATH" , "empty" )
72
+ # create the llm api key secret ols will mount
73
+ provider_list = provider .split ()
74
+ creds_list = creds .split ()
75
+ for i , prov in enumerate (provider_list ):
76
+ ols_installer .create_secrets (
77
+ prov , creds_list [i ], len (provider_list )
78
+ )
79
+ ols_url , token , metrics_token = adapt_ols_config ()
80
+
53
81
except Exception as e :
54
82
print (f"Error setting up OLS on cluster: { e } " )
55
83
must_gather ()
@@ -271,8 +299,8 @@ def get_secret_value(env: str) -> str:
271
299
272
300
def pytest_sessionfinish (session ):
273
301
"""Create datarouter compatible archive to upload into report portal."""
274
- # Gather OLS artifacts at the end of tests
275
- if on_cluster :
302
+ # Gather OLS artifacts only if there were failures
303
+ if on_cluster and session . testsfailed > 0 :
276
304
must_gather ()
277
305
# Sending reports to report portal
278
306
try :
0 commit comments