|
33 | 33 | get_base_dir, |
34 | 34 | ) |
35 | 35 |
|
| 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 | + |
36 | 40 | LOGGER = logging.getLogger(name=__name__) |
37 | 41 | BASIC_LOGGER = logging.getLogger(name="basic") |
38 | 42 |
|
@@ -233,6 +237,36 @@ def pytest_sessionstart(session: Session) -> None: |
233 | 237 | path=must_gather_dict["must_gather_base_directory"], |
234 | 238 | ignore_errors=True, |
235 | 239 | ) |
| 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 |
236 | 270 |
|
237 | 271 |
|
238 | 272 | def pytest_fixture_setup(fixturedef: FixtureDef[Any], request: FixtureRequest) -> None: |
@@ -276,9 +310,6 @@ def pytest_runtest_setup(item: Item) -> None: |
276 | 310 | elif KServeDeploymentType.MODEL_MESH.lower() in item.keywords: |
277 | 311 | item.fixturenames.insert(0, "enabled_modelmesh_in_dsc") |
278 | 312 |
|
279 | | - # The above fixtures require the global config to be updated before being called |
280 | | - item.fixturenames.insert(0, "updated_global_config") |
281 | | - |
282 | 313 |
|
283 | 314 | def pytest_runtest_call(item: Item) -> None: |
284 | 315 | BASIC_LOGGER.info(f"{separator(symbol_='-', val='CALL')}") |
|
0 commit comments