Skip to content

Commit e0a089f

Browse files
authored
fix: use the correct value for the namespace (#342)
1 parent 58cc592 commit e0a089f

2 files changed

Lines changed: 34 additions & 23 deletions

File tree

conftest.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
get_base_dir,
3434
)
3535

36+
from kubernetes.dynamic import DynamicClient
37+
from utilities.infra import get_operator_distribution, get_dsci_applications_namespace, get_data_science_cluster
38+
from ocp_resources.resource import get_client
39+
3640
LOGGER = logging.getLogger(name=__name__)
3741
BASIC_LOGGER = logging.getLogger(name="basic")
3842

@@ -233,6 +237,36 @@ def pytest_sessionstart(session: Session) -> None:
233237
path=must_gather_dict["must_gather_base_directory"],
234238
ignore_errors=True,
235239
)
240+
config = session.config
241+
if config.getoption("--collect-only") or config.getoption("--setup-plan"):
242+
LOGGER.info("Skipping global config update for collect-only or setup-plan")
243+
return
244+
updated_global_config(admin_client=get_client())
245+
246+
247+
def updated_global_config(admin_client: DynamicClient) -> None:
248+
"""
249+
Updates the global config with the distribution, applications namespace, and model registry namespace.
250+
Args:
251+
admin_client: The admin client to use to get resources.
252+
Returns:
253+
None
254+
"""
255+
distribution = get_operator_distribution(client=admin_client)
256+
if distribution == "Open Data Hub":
257+
py_config["distribution"] = "upstream"
258+
259+
elif distribution.startswith("OpenShift AI"):
260+
py_config["distribution"] = "downstream"
261+
else:
262+
import pytest
263+
264+
pytest.exit(f"Unknown distribution: {distribution}")
265+
266+
py_config["applications_namespace"] = get_dsci_applications_namespace(client=admin_client)
267+
py_config["model_registry_namespace"] = get_data_science_cluster(
268+
client=admin_client
269+
).instance.spec.components.modelregistry.registriesNamespace
236270

237271

238272
def pytest_fixture_setup(fixturedef: FixtureDef[Any], request: FixtureRequest) -> None:
@@ -276,9 +310,6 @@ def pytest_runtest_setup(item: Item) -> None:
276310
elif KServeDeploymentType.MODEL_MESH.lower() in item.keywords:
277311
item.fixturenames.insert(0, "enabled_modelmesh_in_dsc")
278312

279-
# The above fixtures require the global config to be updated before being called
280-
item.fixturenames.insert(0, "updated_global_config")
281-
282313

283314
def pytest_runtest_call(item: Item) -> None:
284315
BASIC_LOGGER.info(f"{separator(symbol_='-', val='CALL')}")

tests/conftest.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@
3030
from utilities.infra import (
3131
verify_cluster_sanity,
3232
create_ns,
33-
get_dsci_applications_namespace,
34-
get_operator_distribution,
3533
login_with_user_password,
3634
get_openshift_token,
37-
get_data_science_cluster,
3835
)
3936
from utilities.constants import (
4037
AcceleratorType,
@@ -65,23 +62,6 @@ def tests_tmp_dir(request: FixtureRequest, tmp_path_factory: TempPathFactory) ->
6562
shutil.rmtree(path=str(tests_tmp_path), ignore_errors=True)
6663

6764

68-
@pytest.fixture(scope="session")
69-
def updated_global_config(request: FixtureRequest, admin_client: DynamicClient) -> None:
70-
distribution = get_operator_distribution(client=admin_client)
71-
if distribution == "Open Data Hub":
72-
py_config["distribution"] = "upstream"
73-
74-
elif distribution.startswith("OpenShift AI"):
75-
py_config["distribution"] = "downstream"
76-
else:
77-
pytest.exit(f"Unknown distribution: {distribution}")
78-
79-
py_config["applications_namespace"] = get_dsci_applications_namespace(client=admin_client)
80-
py_config["model_registry_namespace"] = get_data_science_cluster(
81-
client=admin_client
82-
).instance.spec.components.modelregistry.registriesNamespace
83-
84-
8565
@pytest.fixture(scope="session")
8666
def current_client_token(admin_client: DynamicClient) -> str:
8767
return get_openshift_token()

0 commit comments

Comments
 (0)