|
1 | 1 | import base64 |
2 | 2 | import os |
3 | 3 | import shutil |
4 | | -from typing import Any, Generator |
| 4 | +from typing import Any, Callable, Generator |
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 | import shortuuid |
8 | 8 | import yaml |
9 | 9 | from _pytest.tmpdir import TempPathFactory |
10 | 10 | from ocp_resources.config_map import ConfigMap |
| 11 | +from ocp_resources.dsc_initialization import DSCInitialization |
| 12 | +from ocp_resources.node import Node |
11 | 13 | from ocp_resources.pod import Pod |
12 | 14 | from ocp_resources.secret import Secret |
13 | 15 | from ocp_resources.service import Service |
14 | 16 | from pyhelper_utils.shell import run_command |
15 | 17 | from pytest import FixtureRequest, Config |
16 | 18 | from kubernetes.dynamic import DynamicClient |
17 | | -from kubernetes.dynamic.exceptions import ResourceNotFoundError |
18 | 19 | from ocp_resources.data_science_cluster import DataScienceCluster |
19 | 20 | from ocp_resources.namespace import Namespace |
20 | 21 | from ocp_resources.resource import get_client |
|
25 | 26 | from utilities.exceptions import ClusterLoginError |
26 | 27 | from utilities.general import get_s3_secret_dict |
27 | 28 | from utilities.infra import ( |
| 29 | + verify_cluster_sanity, |
28 | 30 | create_ns, |
29 | 31 | get_dsci_applications_namespace, |
30 | 32 | get_operator_distribution, |
@@ -277,12 +279,14 @@ def unprivileged_client( |
277 | 279 | raise ClusterLoginError(user=non_admin_user_name) |
278 | 280 |
|
279 | 281 |
|
| 282 | +@pytest.fixture(scope="session") |
| 283 | +def dsci_resource(admin_client: DynamicClient) -> DSCInitialization: |
| 284 | + return DSCInitialization(client=admin_client, name=py_config["dsci_name"], ensure_exists=True) |
| 285 | + |
| 286 | + |
280 | 287 | @pytest.fixture(scope="session") |
281 | 288 | def dsc_resource(admin_client: DynamicClient) -> DataScienceCluster: |
282 | | - name = py_config["dsc_name"] |
283 | | - for dsc in DataScienceCluster.get(dyn_client=admin_client, name=name): |
284 | | - return dsc |
285 | | - raise ResourceNotFoundError(f"DSC resource {name} not found") |
| 289 | + return DataScienceCluster(client=admin_client, name=py_config["dsc_name"], ensure_exists=True) |
286 | 290 |
|
287 | 291 |
|
288 | 292 | @pytest.fixture(scope="module") |
@@ -444,3 +448,33 @@ def minio_data_connection( |
444 | 448 | }, |
445 | 449 | ) as minio_secret: |
446 | 450 | yield minio_secret |
| 451 | + |
| 452 | + |
| 453 | +@pytest.fixture(scope="session") |
| 454 | +def nodes(admin_client: DynamicClient) -> Generator[list[Node], Any, Any]: |
| 455 | + yield list(Node.get(dyn_client=admin_client)) |
| 456 | + |
| 457 | + |
| 458 | +@pytest.fixture(scope="session") |
| 459 | +def junitxml_plugin( |
| 460 | + request: FixtureRequest, record_testsuite_property: Callable[[str, object], None] |
| 461 | +) -> Callable[[str, object], None] | None: |
| 462 | + return record_testsuite_property if request.config.pluginmanager.has_plugin("junitxml") else None |
| 463 | + |
| 464 | + |
| 465 | +@pytest.fixture(scope="session", autouse=True) |
| 466 | +@pytest.mark.early(order=0) |
| 467 | +def cluster_sanity_scope_session( |
| 468 | + request: FixtureRequest, |
| 469 | + nodes: list[Node], |
| 470 | + dsci_resource: DSCInitialization, |
| 471 | + dsc_resource: DataScienceCluster, |
| 472 | + junitxml_plugin: Callable[[str, object], None], |
| 473 | +) -> None: |
| 474 | + verify_cluster_sanity( |
| 475 | + request=request, |
| 476 | + nodes=nodes, |
| 477 | + dsc_resource=dsc_resource, |
| 478 | + dsci_resource=dsci_resource, |
| 479 | + junitxml_property=junitxml_plugin, |
| 480 | + ) |
0 commit comments