Skip to content

Commit 14c31bc

Browse files
Snomaan6846mwaykole
authored andcommitted
test: verify RHODS admin can import and delete ServingRuntimes from custom templates (opendatahub-io#397)
Signed-off-by: Snomaan6846 <syedali@redhat.com> rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED
1 parent 9c87c52 commit 14c31bc

4 files changed

Lines changed: 164 additions & 0 deletions

File tree

tests/model_serving/model_runtime/rhoai_upgrade/__init__.py

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from typing import Any, Generator
2+
3+
import pytest
4+
from kubernetes.dynamic import DynamicClient
5+
from pytest_testconfig import config as py_config
6+
7+
from ocp_resources.template import Template
8+
9+
from tests.model_serving.model_runtime.rhoai_upgrade.constant import (
10+
OVMS_SERVING_RUNTIME_TEMPLATE_DICT,
11+
SERVING_RUNTIME_TEMPLATE_NAME,
12+
SERVING_RUNTIME_INSTANCE_NAME,
13+
)
14+
15+
from utilities.serving_runtime import ServingRuntimeFromTemplate
16+
17+
18+
@pytest.fixture(scope="class")
19+
def serving_runtime_template(admin_client: DynamicClient) -> Generator[Any, Any, Any]:
20+
"""
21+
Class-scoped fixture that deploys a ServingRuntime Template and cleans it up after tests.
22+
"""
23+
with Template(
24+
client=admin_client,
25+
namespace=py_config["applications_namespace"],
26+
kind_dict=OVMS_SERVING_RUNTIME_TEMPLATE_DICT,
27+
) as template:
28+
yield template
29+
30+
31+
@pytest.fixture(scope="class")
32+
def serving_runtime_instance(admin_client: DynamicClient) -> Generator[Any, Any, Any]:
33+
"""
34+
Class-scoped fixture that deploys a ServingRuntime from a template
35+
and cleans it up after all tests in the class.
36+
"""
37+
with ServingRuntimeFromTemplate(
38+
client=admin_client,
39+
name=SERVING_RUNTIME_INSTANCE_NAME,
40+
namespace=py_config["applications_namespace"],
41+
template_name=SERVING_RUNTIME_TEMPLATE_NAME,
42+
) as instance:
43+
yield instance
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
from typing import Dict, Any, List, Union
2+
3+
SERVING_RUNTIME_TEMPLATE_NAME: str = "kserve-ovms-serving-runtime-template"
4+
SERVING_RUNTIME_INSTANCE_NAME: str = "kserve-ovms-serving-runtime-instance"
5+
6+
OVMS_SERVING_RUNTIME_IMAGE: str = (
7+
"quay.io/modh/openvino_model_server@sha256:53b7fcf95de9b81e4c8652d0bf4e84e22d5b696827a5d951d863420c68b9cfe8"
8+
)
9+
10+
OVMS_TEMPLATE_LABELS: Dict[str, str] = {
11+
"opendatahub.io/dashboard": "true",
12+
"opendatahub.io/ootb": "true",
13+
}
14+
15+
OVMS_TEMPLATE_ANNOTATIONS: Dict[str, str] = {
16+
"tags": "kserve-ovms,servingruntime",
17+
"description": "OpenVino Model Serving Definition",
18+
"opendatahub.io/modelServingSupport": '["single"]',
19+
"opendatahub.io/apiProtocol": "REST",
20+
}
21+
22+
OVMS_RUNTIME_LABELS: Dict[str, str] = {
23+
"opendatahub.io/dashboard": "true",
24+
}
25+
26+
OVMS_RUNTIME_ANNOTATIONS: Dict[str, str] = {
27+
"openshift.io/display-name": "OpenVINO Model Server",
28+
"opendatahub.io/recommended-accelerators": '["nvidia.com/gpu"]',
29+
"opendatahub.io/runtime-version": "v2025.1",
30+
}
31+
32+
OVMS_RUNTIME_PROMETHEUS_ANNOTATIONS: Dict[str, str] = {
33+
"prometheus.io/port": "8888",
34+
"prometheus.io/path": "/metrics",
35+
}
36+
37+
OVMS_SUPPORTED_MODEL_FORMATS: List[Dict[str, Union[str, bool]]] = [
38+
{"name": "openvino_ir", "version": "opset13", "autoSelect": True},
39+
{"name": "onnx", "version": "1"},
40+
{"name": "tensorflow", "version": "1", "autoSelect": True},
41+
{"name": "tensorflow", "version": "2", "autoSelect": True},
42+
{"name": "paddle", "version": "2", "autoSelect": True},
43+
{"name": "pytorch", "version": "2", "autoSelect": True},
44+
]
45+
46+
OVMS_CONTAINER_ARGS: List[str] = [
47+
"--model_name={{.Name}}",
48+
"--port=8001",
49+
"--rest_port=8888",
50+
"--model_path=/mnt/models",
51+
"--file_system_poll_wait_seconds=0",
52+
"--grpc_bind_address=0.0.0.0",
53+
"--rest_bind_address=0.0.0.0",
54+
"--target_device=AUTO",
55+
"--metrics_enable",
56+
]
57+
58+
OVMS_SERVING_RUNTIME_TEMPLATE_DICT: Dict[str, Any] = {
59+
"metadata": {
60+
"name": SERVING_RUNTIME_TEMPLATE_NAME,
61+
"labels": OVMS_TEMPLATE_LABELS,
62+
"annotations": OVMS_TEMPLATE_ANNOTATIONS,
63+
},
64+
"objects": [
65+
{
66+
"apiVersion": "serving.kserve.io/v1alpha1",
67+
"kind": "ServingRuntime",
68+
"metadata": {
69+
"name": SERVING_RUNTIME_INSTANCE_NAME,
70+
"labels": OVMS_RUNTIME_LABELS,
71+
"annotations": OVMS_RUNTIME_ANNOTATIONS,
72+
},
73+
"spec": {
74+
"multiModel": False,
75+
"annotations": OVMS_RUNTIME_PROMETHEUS_ANNOTATIONS,
76+
"supportedModelFormats": OVMS_SUPPORTED_MODEL_FORMATS,
77+
"protocolVersions": ["v2", "grpc-v2"],
78+
"containers": [
79+
{
80+
"name": "kserve-container",
81+
"image": OVMS_SERVING_RUNTIME_IMAGE,
82+
"args": OVMS_CONTAINER_ARGS,
83+
"ports": [{"containerPort": 8888, "protocol": "TCP"}],
84+
}
85+
],
86+
},
87+
}
88+
],
89+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from typing import Any, Generator
2+
3+
import pytest
4+
from simple_logger.logger import get_logger
5+
6+
from tests.model_serving.model_runtime.rhoai_upgrade.constant import (
7+
SERVING_RUNTIME_INSTANCE_NAME,
8+
SERVING_RUNTIME_TEMPLATE_NAME,
9+
)
10+
11+
LOGGER = get_logger(name=__name__)
12+
13+
14+
class TestServingRuntimeLifecycle:
15+
"""
16+
Tests to validate the lifecycle of ServingRuntime resources
17+
including creation, verification, and deletion.
18+
"""
19+
20+
@pytest.mark.post_upgrade
21+
@pytest.mark.order(1)
22+
def test_serving_runtime_template_lifecycle(self, serving_runtime_template: Generator[Any, Any, Any]) -> None:
23+
assert serving_runtime_template.exists, (
24+
f"Failed to validate Serving Runtime template lifecycle'{SERVING_RUNTIME_TEMPLATE_NAME}'"
25+
)
26+
27+
@pytest.mark.post_upgrade
28+
@pytest.mark.order(2)
29+
def test_serving_runtime_instance_lifecycle(self, serving_runtime_instance: Generator[Any, Any, Any]) -> None:
30+
assert serving_runtime_instance.exists, (
31+
f"Failed to validate Serving Runtime instance lifecycle'{SERVING_RUNTIME_INSTANCE_NAME}'"
32+
)

0 commit comments

Comments
 (0)