77"""
88
99from collections .abc import Generator
10- from contextlib import contextmanager
1110from typing import Any
1211
1312import pytest
1413from kubernetes .dynamic import DynamicClient
15- from kubernetes .dynamic .exceptions import ResourceNotFoundError
16- from ocp_resources .inference_service import InferenceService
1714from ocp_resources .namespace import Namespace
1815from ocp_resources .pod import Pod
1916from 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
2620from 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
2822from 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
0 commit comments