Skip to content

Commit 3dd49d9

Browse files
committed
fixed suggestions
1 parent 77ec9ae commit 3dd49d9

2 files changed

Lines changed: 16 additions & 66 deletions

File tree

tests/model_serving/model_runtime/image_validation/conftest.py

Lines changed: 15 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,18 @@
77
"""
88

99
from collections.abc import Generator
10-
from contextlib import contextmanager
1110
from typing import Any
1211

1312
import pytest
1413
from kubernetes.dynamic import DynamicClient
15-
from kubernetes.dynamic.exceptions import ResourceNotFoundError
16-
from ocp_resources.inference_service import InferenceService
1714
from ocp_resources.namespace import Namespace
1815
from ocp_resources.pod import Pod
1916
from timeout_sampler import TimeoutSampler
2017

21-
from tests.model_serving.model_runtime.image_validation.constant import (
22-
PLACEHOLDER_STORAGE_URI,
23-
POD_WAIT_TIMEOUT,
24-
)
25-
from utilities.constants import KServeDeploymentType, Timeout
18+
from tests.model_serving.model_runtime.image_validation.constant import PLACEHOLDER_STORAGE_URI
19+
from utilities.constants import KServeDeploymentType
2620
from utilities.inference_utils import create_isvc
27-
from utilities.infra import create_ns, get_pods_by_isvc_label
21+
from utilities.infra import create_ns, wait_for_isvc_pods
2822
from utilities.serving_runtime import ServingRuntimeFromTemplate
2923

3024

@@ -60,36 +54,11 @@ def serving_runtime_pods_for_runtime(
6054
runtime_name = f"{name_slug}-runtime"
6155
isvc_name = f"{name_slug}-isvc"
6256

63-
with _serving_runtime_and_isvc(
64-
admin_client=admin_client,
65-
namespace_name=namespace_name,
66-
runtime_name=runtime_name,
67-
isvc_name=isvc_name,
68-
template_name=config["template"],
69-
) as isvc:
70-
pods = _wait_for_isvc_pods(
71-
client=admin_client,
72-
isvc=isvc,
73-
runtime_name=runtime_name,
74-
timeout=POD_WAIT_TIMEOUT,
75-
)
76-
yield (pods, display_name)
77-
78-
79-
@contextmanager
80-
def _serving_runtime_and_isvc(
81-
admin_client: DynamicClient,
82-
namespace_name: str,
83-
runtime_name: str,
84-
isvc_name: str,
85-
template_name: str,
86-
) -> Generator[InferenceService, Any, Any]:
87-
"""Create ServingRuntime from template and minimal InferenceService; yield ISVC."""
8857
with ServingRuntimeFromTemplate(
8958
client=admin_client,
9059
name=runtime_name,
9160
namespace=namespace_name,
92-
template_name=template_name,
61+
template_name=config["template"],
9362
deployment_type="raw",
9463
) as serving_runtime:
9564
# Get model format from the runtime for the InferenceService spec.
@@ -104,34 +73,18 @@ def _serving_runtime_and_isvc(
10473
deployment_mode=KServeDeploymentType.RAW_DEPLOYMENT,
10574
wait=False,
10675
wait_for_predictor_pods=False,
107-
timeout=Timeout.TIMEOUT_2MIN,
76+
timeout=120,
10877
teardown=True,
10978
) as isvc:
110-
yield isvc
111-
112-
113-
def _wait_for_isvc_pods(
114-
client: DynamicClient,
115-
isvc: InferenceService,
116-
runtime_name: str,
117-
timeout: int,
118-
) -> list[Pod]:
119-
"""Wait until at least one pod exists for the InferenceService; return list of pods."""
120-
121-
def _get_pods() -> list[Pod] | None:
122-
try:
123-
return get_pods_by_isvc_label(
124-
client=client,
79+
# Wait for pods to be created (300 seconds timeout)
80+
for pods in TimeoutSampler(
81+
wait_timeout=300,
82+
sleep=5,
83+
func=wait_for_isvc_pods,
84+
client=admin_client,
12585
isvc=isvc,
12686
runtime_name=runtime_name,
127-
)
128-
except ResourceNotFoundError:
129-
return None
130-
131-
for pods in TimeoutSampler(
132-
wait_timeout=timeout,
133-
sleep=5,
134-
func=_get_pods,
135-
):
136-
if pods:
137-
return pods
87+
):
88+
if pods:
89+
yield (pods, display_name)
90+
return

tests/model_serving/model_runtime/image_validation/constant.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
"""Constants for serving runtime image validation tests."""
22

3-
from utilities.constants import RuntimeTemplates, Timeout
3+
from utilities.constants import RuntimeTemplates
44

55
# Placeholder storage URI so the controller creates Deployment/Pod with runtime image.
66
# No actual model or inference is required; pod phase does not need to be Ready.
77
PLACEHOLDER_STORAGE_URI = "s3://dummy-bucket/dummy/"
88

9-
# Time to wait for at least one pod to be created for the InferenceService.
10-
POD_WAIT_TIMEOUT = Timeout.TIMEOUT_5MIN
11-
129
# Runtime configs: display name (for "name : passed") and template name.
1310
# For each we create ServingRuntime + InferenceService, wait for pod(s), validate, then teardown.
1411
RUNTIME_CONFIGS = [

0 commit comments

Comments
 (0)