|
| 1 | +import pytest |
| 2 | +from ocp_resources.deployment import Deployment |
| 3 | + |
| 4 | +from tests.model_serving.model_server.serverless.utils import verify_no_inference_pods |
| 5 | +from tests.model_serving.model_server.utils import verify_inference_response |
| 6 | +from utilities.constants import ( |
| 7 | + ModelFormat, |
| 8 | + ModelInferenceRuntime, |
| 9 | + ModelVersion, |
| 10 | + Protocols, |
| 11 | +) |
| 12 | +from utilities.exceptions import DeploymentValidationError |
| 13 | +from utilities.inference_utils import Inference |
| 14 | +from utilities.manifests.onnx import ONNX_INFERENCE_CONFIG |
| 15 | + |
| 16 | +pytestmark = [ |
| 17 | + pytest.mark.serverless, |
| 18 | + pytest.mark.sanity, |
| 19 | + pytest.mark.usefixtures("valid_aws_config"), |
| 20 | +] |
| 21 | + |
| 22 | + |
| 23 | +@pytest.mark.serverless |
| 24 | +@pytest.mark.parametrize( |
| 25 | + "model_namespace, openvino_kserve_serving_runtime, ovms_serverless_inference_service", |
| 26 | + [ |
| 27 | + pytest.param( |
| 28 | + {"name": "serverless-scale-zero"}, |
| 29 | + { |
| 30 | + "runtime-name": ModelInferenceRuntime.ONNX_RUNTIME, |
| 31 | + "model-format": {ModelFormat.ONNX: ModelVersion.OPSET13}, |
| 32 | + }, |
| 33 | + { |
| 34 | + "name": ModelFormat.ONNX, |
| 35 | + "model-version": ModelVersion.OPSET13, |
| 36 | + "model-dir": "test-dir", |
| 37 | + }, |
| 38 | + ) |
| 39 | + ], |
| 40 | + indirect=True, |
| 41 | +) |
| 42 | +class TestServerlessScaleToZero: |
| 43 | + def test_serverless_before_scale_to_zero(self, ovms_serverless_inference_service): |
| 44 | + """Verify model can be queried before scaling to zero""" |
| 45 | + verify_inference_response( |
| 46 | + inference_service=ovms_serverless_inference_service, |
| 47 | + inference_config=ONNX_INFERENCE_CONFIG, |
| 48 | + inference_type=Inference.INFER, |
| 49 | + protocol=Protocols.HTTPS, |
| 50 | + use_default_query=True, |
| 51 | + ) |
| 52 | + |
| 53 | + @pytest.mark.parametrize( |
| 54 | + "inference_service_patched_replicas", |
| 55 | + [pytest.param({"min-replicas": 0})], |
| 56 | + indirect=True, |
| 57 | + ) |
| 58 | + @pytest.mark.dependency(name="test_no_serverless_pods_after_scale_to_zero") |
| 59 | + def test_no_serverless_pods_after_scale_to_zero(self, admin_client, inference_service_patched_replicas): |
| 60 | + """Verify pods are scaled to zero""" |
| 61 | + verify_no_inference_pods(client=admin_client, isvc=inference_service_patched_replicas) |
| 62 | + |
| 63 | + @pytest.mark.dependency(depends=["test_no_serverless_pods_after_scale_to_zero"]) |
| 64 | + def test_serverless_inference_after_scale_to_zero(self, ovms_serverless_inference_service): |
| 65 | + """Verify model can be queried after scaling to zero""" |
| 66 | + verify_inference_response( |
| 67 | + inference_service=ovms_serverless_inference_service, |
| 68 | + inference_config=ONNX_INFERENCE_CONFIG, |
| 69 | + inference_type=Inference.INFER, |
| 70 | + protocol=Protocols.HTTPS, |
| 71 | + use_default_query=True, |
| 72 | + ) |
| 73 | + |
| 74 | + @pytest.mark.dependency(depends=["test_no_serverless_pods_after_scale_to_zero"]) |
| 75 | + def test_no_serverless_pods_when_no_traffic(self, admin_client, ovms_serverless_inference_service): |
| 76 | + """Verify pods are scaled to zero when no traffic is sent""" |
| 77 | + verify_no_inference_pods(client=admin_client, isvc=ovms_serverless_inference_service) |
| 78 | + |
| 79 | + @pytest.mark.parametrize( |
| 80 | + "inference_service_patched_replicas", |
| 81 | + [pytest.param({"min-replicas": 1})], |
| 82 | + indirect=True, |
| 83 | + ) |
| 84 | + def test_serverless_pods_after_scale_to_one_replica(self, admin_client, inference_service_patched_replicas): |
| 85 | + """Verify pod is running after scaling to 1 replica""" |
| 86 | + for deployment in Deployment.get( |
| 87 | + client=admin_client, |
| 88 | + namespace=inference_service_patched_replicas.namespace, |
| 89 | + ): |
| 90 | + if deployment.labels["serving.knative.dev/configurationGeneration"] == "3": |
| 91 | + deployment.wait_for_replicas() |
| 92 | + return |
| 93 | + |
| 94 | + raise DeploymentValidationError( |
| 95 | + f"Inference Service {inference_service_patched_replicas.name} new deployment not found" |
| 96 | + ) |
0 commit comments