Skip to content

Commit f9b785f

Browse files
rnetserdbasunag
authored andcommitted
feat: fail on missing operators (opendatahub-io#257)
* fix: update tests * fix: update tests * feat: fail on missing operators * fix: rename to dependent * fix: address comment * fix: add log on failure * fix: type in raise * fix: remove MR check * fix: remove MR check * fix: use package scope
1 parent 13f9067 commit f9b785f

File tree

3 files changed

+43
-46
lines changed

3 files changed

+43
-46
lines changed

conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ def pytest_runtest_setup(item: Item) -> None:
245245
"""
246246
Performs the following actions:
247247
1. Updates global config (`updated_global_config`)
248-
2. Adds skip fixture for kserve if serverless or authorino operators are not installed.
249-
3. Adds skip fixture for serverless if authorino/serverless/service mesh are not deployed.
248+
2. Adds `fail_if_missing_dependent_operators` fixture for Serverless tests.
249+
3. Adds fixtures to enable KServe/model mesh in DSC for model server tests.
250250
"""
251251
BASIC_LOGGER.info(f"\n{separator(symbol_='-', val=item.name)}")
252252
BASIC_LOGGER.info(f"{separator(symbol_='-', val='SETUP')}")
@@ -268,9 +268,9 @@ def pytest_runtest_setup(item: Item) -> None:
268268
LOGGER.error(f"Database error: {db_exception}. Must-gather collection may not be accurate")
269269

270270
if KServeDeploymentType.SERVERLESS.lower() in item.keywords:
271-
item.fixturenames.insert(0, "skip_if_no_deployed_redhat_authorino_operator")
272-
item.fixturenames.insert(0, "skip_if_no_deployed_openshift_serverless")
273-
item.fixturenames.insert(0, "skip_if_no_deployed_openshift_service_mesh")
271+
item.fixturenames.insert(0, "fail_if_missing_dependent_operators")
272+
273+
if KServeDeploymentType.SERVERLESS.lower() in item.keywords:
274274
item.fixturenames.insert(0, "enabled_kserve_in_dsc")
275275

276276
elif KServeDeploymentType.RAW_DEPLOYMENT.lower() in item.keywords:

docs/GETTING_STARTED.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ By default, cluster sanity checks are run to make cluster ready for tests.
6767
To skip cluster sanity checks, pass `--cluster-sanity-skip-check` to skip all tests.
6868
To skip RHOAI/ODH-related tests (for example when running in upstream), pass `--cluster-sanity-skip-rhoai-check`.
6969

70+
### Check dependent operators
71+
By default, `Serveless` (serverless-operator), `Authorino` (authorino-operator) and `Service Mesh` (servicemeshoperator) operators are checked to be installed when
72+
running model server Serverless tests.
73+
To check only specific operator, pass `--tc=dependent_operators:<operator_name>` to pytest.
74+
For example, to check only `Serveless` and `Service Mesh` operators, pass `--tc=dependent_operators:serverless-operator,servicemeshoperator`.
75+
76+
7077
### jira integration
7178
To skip running tests which have open bugs, [pytest_jira](https://github.com/rhevm-qe-automation/pytest_jira) plugin is used.
7279
To run tests with jira integration, you need to set `PYTEST_JIRA_URL` and `PYTEST_JIRA_TOKEN` environment variables.

tests/model_serving/model_server/conftest.py

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@
44
import yaml
55
from _pytest.fixtures import FixtureRequest
66
from kubernetes.dynamic import DynamicClient
7-
from ocp_resources.authorino import Authorino
87
from ocp_resources.cluster_service_version import ClusterServiceVersion
98
from ocp_resources.config_map import ConfigMap
109
from ocp_resources.inference_service import InferenceService
1110
from ocp_resources.namespace import Namespace
1211
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
1312
from ocp_resources.secret import Secret
1413
from ocp_resources.service_account import ServiceAccount
15-
from ocp_resources.service_mesh_control_plane import ServiceMeshControlPlane
1614
from ocp_resources.serving_runtime import ServingRuntime
1715
from ocp_resources.storage_class import StorageClass
1816
from ocp_utilities.monitoring import Prometheus
1917
from pytest_testconfig import config as py_config
18+
from simple_logger.logger import get_logger
2019

2120
from utilities.constants import (
2221
KServeDeploymentType,
@@ -40,23 +39,7 @@
4039
from utilities.serving_runtime import ServingRuntimeFromTemplate
4140

4241

43-
@pytest.fixture(scope="package")
44-
def skip_if_no_deployed_openshift_serverless(admin_client: DynamicClient) -> None:
45-
name = "openshift-serverless"
46-
csvs = list(
47-
ClusterServiceVersion.get(
48-
client=admin_client,
49-
namespace=name,
50-
label_selector=f"operators.coreos.com/serverless-operator.{name}",
51-
)
52-
)
53-
if not csvs:
54-
pytest.skip("OpenShift Serverless is not deployed")
55-
56-
csv = csvs[0]
57-
58-
if not (csv.exists and csv.status == csv.Status.SUCCEEDED):
59-
pytest.skip("OpenShift Serverless is not deployed")
42+
LOGGER = get_logger(name=__name__)
6043

6144

6245
@pytest.fixture(scope="class")
@@ -189,28 +172,6 @@ def skip_if_no_nfs_storage_class(admin_client: DynamicClient) -> None:
189172
pytest.skip(f"StorageClass {StorageClassName.NFS} is missing from the cluster")
190173

191174

192-
@pytest.fixture(scope="package")
193-
def skip_if_no_deployed_redhat_authorino_operator(admin_client: DynamicClient) -> None:
194-
name = "authorino"
195-
namespace = f"{py_config['applications_namespace']}-auth-provider"
196-
197-
if not Authorino(
198-
client=admin_client,
199-
name=name,
200-
namespace=namespace,
201-
).exists:
202-
pytest.skip(f"Authorino {name} CR is missing from {namespace} namespace")
203-
204-
205-
@pytest.fixture(scope="package")
206-
def skip_if_no_deployed_openshift_service_mesh(admin_client: DynamicClient) -> None:
207-
smcp = ServiceMeshControlPlane(client=admin_client, name="data-science-smcp", namespace="istio-system")
208-
if not smcp or not smcp.exists:
209-
pytest.skip("OpenShift service mesh operator is not deployed")
210-
211-
smcp.wait_for_condition(condition=smcp.Condition.READY, status="True")
212-
213-
214175
@pytest.fixture(scope="class")
215176
def http_s3_openvino_model_mesh_inference_service(
216177
request: FixtureRequest,
@@ -608,3 +569,32 @@ def unprivileged_s3_caikit_serverless_inference_service(
608569
storage_path=request.param["model-dir"],
609570
) as isvc:
610571
yield isvc
572+
573+
574+
@pytest.fixture(scope="package")
575+
def fail_if_missing_dependent_operators(admin_client: DynamicClient) -> None:
576+
missing_operators: list[str] = []
577+
csvs = list(
578+
ClusterServiceVersion.get(
579+
dyn_client=admin_client,
580+
namespace=py_config["applications_namespace"],
581+
)
582+
)
583+
584+
for operator_name in py_config.get("dependent_operators", []).split(","):
585+
LOGGER.info(f"Verifying if {operator_name} is installed")
586+
for csv in csvs:
587+
if csv.name.startswith(operator_name):
588+
if csv.status == csv.Status.SUCCEEDED:
589+
break
590+
591+
else:
592+
missing_operators.append(
593+
f"Operator {operator_name} is installed but CSV is not in {csv.Status.SUCCEEDED} state"
594+
)
595+
596+
else:
597+
missing_operators.append(f"{operator_name} is not installed")
598+
599+
if missing_operators:
600+
pytest.fail(str(missing_operators))

0 commit comments

Comments
 (0)