Skip to content

Commit 130b812

Browse files
committed
fix: update timeout
1 parent 4782efb commit 130b812

File tree

4 files changed

+118
-3
lines changed

4 files changed

+118
-3
lines changed

tests/model_serving/model_server/inference_service_configuration/conftest.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import pytest
44
from kubernetes.dynamic import DynamicClient
55
from ocp_resources.inference_service import InferenceService
6+
from ocp_resources.pod import Pod
67

78
from tests.model_serving.model_server.inference_service_configuration.constants import (
89
ISVC_ENV_VARS,
910
)
1011
from tests.model_serving.model_server.inference_service_configuration.utils import (
1112
update_inference_service,
1213
)
14+
from utilities.infra import get_pods_by_isvc_label
1315

1416

1517
@pytest.fixture(scope="class")
@@ -29,3 +31,31 @@ def removed_isvc_env_vars(
2931
isvc_updated_dict={"spec": {"predictor": {"model": {"env": isvc_predictor_spec_model_env}}}},
3032
):
3133
yield ovms_kserve_inference_service
34+
35+
36+
@pytest.fixture
37+
def isvc_pods(
38+
admin_client: DynamicClient, ovms_kserve_inference_service: InferenceService
39+
) -> Generator[list[Pod], Any, Any]:
40+
yield get_pods_by_isvc_label(client=admin_client, isvc=ovms_kserve_inference_service)
41+
42+
43+
@pytest.fixture(scope="class")
44+
def patched_isvc_replicas(
45+
request: pytest.FixtureRequest,
46+
admin_client: DynamicClient,
47+
ovms_kserve_inference_service: InferenceService,
48+
) -> Generator[InferenceService, Any, Any]:
49+
with update_inference_service(
50+
client=admin_client,
51+
isvc=ovms_kserve_inference_service,
52+
isvc_updated_dict={
53+
"spec": {
54+
"predictor": {
55+
"maxReplicas": request.param["max-replicas"],
56+
"minReplicas": request.param["min-replicas"],
57+
}
58+
}
59+
},
60+
):
61+
yield ovms_kserve_inference_service

tests/model_serving/model_server/inference_service_configuration/test_isvc_env_vars_updates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def test_serverless_with_isvc_env_vars(self, ovms_kserve_inference_service):
8383
"""Test adding environment variables to the inference service"""
8484
verify_env_vars_in_isvc_pods(isvc=ovms_kserve_inference_service, env_vars=ISVC_ENV_VARS, vars_exist=True)
8585

86+
@pytest.mark.slow
8687
def test_serverless_remove_isvc_env_vars(self, removed_isvc_env_vars):
8788
"""Test removing environment variables from the inference service"""
8889
verify_env_vars_in_isvc_pods(isvc=removed_isvc_env_vars, env_vars=ISVC_ENV_VARS, vars_exist=False)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import pytest
2+
3+
from tests.model_serving.model_server.inference_service_configuration.constants import (
4+
BASE_ISVC_CONFIG,
5+
RUNTIME_CONFIG,
6+
)
7+
from tests.model_serving.model_server.inference_service_configuration.utils import (
8+
wait_for_new_running_inference_pods,
9+
)
10+
from tests.model_serving.model_server.utils import verify_inference_response
11+
from utilities.constants import (
12+
KServeDeploymentType,
13+
Protocols,
14+
)
15+
from utilities.inference_utils import Inference
16+
from utilities.manifests.onnx import ONNX_INFERENCE_CONFIG
17+
18+
pytestmark = [pytest.mark.sanity, pytest.mark.usefixtures("valid_aws_config")]
19+
20+
21+
@pytest.mark.rawdeployment
22+
@pytest.mark.parametrize(
23+
"model_namespace, openvino_kserve_serving_runtime, ovms_kserve_inference_service",
24+
[
25+
pytest.param(
26+
{"name": "raw-isvc-replicas"},
27+
RUNTIME_CONFIG,
28+
{
29+
**BASE_ISVC_CONFIG,
30+
"min-replicas": 2,
31+
"max-replicas": 4,
32+
"deployment-mode": KServeDeploymentType.RAW_DEPLOYMENT,
33+
},
34+
)
35+
],
36+
indirect=True,
37+
)
38+
class TestRawISVCReplicasUpdates:
39+
@pytest.mark.dependency(name="test_raw_increase_isvc_replicas")
40+
def test_raw_increase_isvc_replicas(self, isvc_pods, patched_isvc_replicas):
41+
"""Test replicas increase"""
42+
wait_for_new_running_inference_pods(isvc=patched_isvc_replicas, orig_pods=isvc_pods, expected_num_pods=2)
43+
44+
@pytest.mark.dependency(depends=["test_raw_increase_isvc_replicas"])
45+
def test_raw_increase_isvc_replicas_inference(self, ovms_kserve_inference_service):
46+
"""Verify inference after replicas increase"""
47+
verify_inference_response(
48+
inference_service=ovms_kserve_inference_service,
49+
inference_config=ONNX_INFERENCE_CONFIG,
50+
inference_type=Inference.INFER,
51+
protocol=Protocols.HTTP,
52+
use_default_query=True,
53+
)
54+
55+
@pytest.mark.parametrize(
56+
"patched_isvc_replicas",
57+
[
58+
pytest.param({"min-replicas": 1, "max-replicas": 1}),
59+
],
60+
indirect=True,
61+
)
62+
@pytest.mark.dependency(name="test_raw_decrease_isvc_replicas")
63+
def test_raw_decrease_isvc_replicas(self, isvc_pods, patched_isvc_replicas):
64+
"""Test replicas decrease"""
65+
wait_for_new_running_inference_pods(isvc=patched_isvc_replicas, orig_pods=isvc_pods, expected_num_pods=2)
66+
67+
@pytest.mark.dependency(depends=["test_raw_decrease_isvc_replicas"])
68+
def test_raw_decrease_isvc_replicas_inference(self, ovms_kserve_inference_service):
69+
"""Verify inference after replicas decrease"""
70+
verify_inference_response(
71+
inference_service=ovms_kserve_inference_service,
72+
inference_config=ONNX_INFERENCE_CONFIG,
73+
inference_type=Inference.INFER,
74+
protocol=Protocols.HTTP,
75+
use_default_query=True,
76+
)

tests/model_serving/model_server/inference_service_configuration/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from contextlib import contextmanager
24
from typing import Any, Generator
35

@@ -70,13 +72,17 @@ def verify_env_vars_in_isvc_pods(isvc: InferenceService, env_vars: list[dict[str
7072
)
7173

7274

73-
def wait_for_new_running_inference_pods(isvc: InferenceService, orig_pods: list[Pod]) -> None:
75+
def wait_for_new_running_inference_pods(
76+
isvc: InferenceService, orig_pods: list[Pod], expected_num_pods: int | None = None
77+
) -> None:
7478
"""
7579
Wait for the inference pod to be replaced.
7680
7781
Args:
7882
isvc (InferenceService): InferenceService object.
7983
orig_pods (list): List of Pod objects.
84+
expected_num_pods (int): Number of pods expected to be running. I
85+
f not provided, the number of pods is expected to be len(orig_pods)
8086
8187
Raises:
8288
TimeoutError: If the pods are not replaced.
@@ -85,15 +91,17 @@ def wait_for_new_running_inference_pods(isvc: InferenceService, orig_pods: list[
8591
LOGGER.info("Waiting for pods to be replaced")
8692
oring_pods_names = [pod.name for pod in orig_pods]
8793

94+
expected_num_pods = expected_num_pods or len(orig_pods)
95+
8896
try:
8997
for pods in TimeoutSampler(
90-
wait_timeout=Timeout.TIMEOUT_4MIN,
98+
wait_timeout=Timeout.TIMEOUT_10MIN,
9199
sleep=5,
92100
func=get_pods_by_isvc_label,
93101
client=isvc.client,
94102
isvc=isvc,
95103
):
96-
if pods and len(pods) == len(orig_pods):
104+
if pods and len(pods) == expected_num_pods:
97105
if all(pod.name not in oring_pods_names and pod.status == pod.Status.RUNNING for pod in pods):
98106
return
99107

0 commit comments

Comments
 (0)