Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

from scripts.upload_artifact_s3 import upload_artifact_s3
from tests.e2e.utils import client as client_utils
from tests.e2e.utils import ols_installer
from tests.e2e.utils import cluster, ols_installer
from tests.e2e.utils.adapt_ols_config import adapt_ols_config
from tests.e2e.utils.wait_for_ols import wait_for_ols
from tests.scripts.must_gather import must_gather

Expand All @@ -45,11 +46,38 @@ def pytest_sessionstart():
# OLS_URL env only needs to be set when running against a local ols instance,
# when ols is run against a cluster the url is retrieved from the cluster.
ols_url = os.getenv("OLS_URL", "")

if "localhost" not in ols_url:
on_cluster = True
try:
ols_url, token, metrics_token = ols_installer.install_ols()
result = cluster.run_oc(
[
"get",
"clusterserviceversion",
"-n",
"openshift-lightspeed",
"-o",
"json",
]
)
csv_data = json.loads(result.stdout)
print(csv_data)

if not csv_data["items"]:
print("OLS Operator is not installed yet.")
ols_url, token, metrics_token = ols_installer.install_ols()
else:
print("OLS Operator is already installed. Skipping install.")
provider = os.getenv("PROVIDER", "openai")
creds = os.getenv("PROVIDER_KEY_PATH", "empty")
# create the llm api key secret ols will mount
provider_list = provider.split()
creds_list = creds.split()
for i, prov in enumerate(provider_list):
ols_installer.create_secrets(
prov, creds_list[i], len(provider_list)
)
ols_url, token, metrics_token = adapt_ols_config()

except Exception as e:
print(f"Error setting up OLS on cluster: {e}")
must_gather()
Expand Down Expand Up @@ -271,8 +299,8 @@ def get_secret_value(env: str) -> str:

def pytest_sessionfinish(session):
"""Create datarouter compatible archive to upload into report portal."""
# Gather OLS artifacts at the end of tests
if on_cluster:
# Gather OLS artifacts only if there were failures
if on_cluster and session.testsfailed > 0:
must_gather()
# Sending reports to report portal
try:
Expand Down
Loading