Skip to content

Commit 012e353

Browse files
authored
fix: use headed KServe services in guardrails tests (#874)
1 parent b8f73c2 commit 012e353

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed

tests/fixtures/inference.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import pytest
44
from kubernetes.dynamic import DynamicClient
5+
from ocp_resources.data_science_cluster import DataScienceCluster
6+
from ocp_resources.deployment import Deployment
57
from ocp_resources.inference_service import InferenceService
68
from ocp_resources.namespace import Namespace
79
from ocp_resources.pod import Pod
10+
from ocp_resources.resource import ResourceEditor
811
from ocp_resources.secret import Secret
912
from ocp_resources.service import Service
1013
from ocp_resources.serving_runtime import ServingRuntime
14+
from pytest_testconfig import py_config
1115

1216
from utilities.constants import (
1317
RuntimeTemplates,
@@ -16,6 +20,7 @@
1620
LLMdInferenceSimConfig,
1721
)
1822
from utilities.inference_utils import create_isvc
23+
from utilities.infra import get_data_science_cluster
1924
from utilities.serving_runtime import ServingRuntimeFromTemplate
2025

2126

@@ -177,3 +182,24 @@ def llm_d_inference_sim_isvc(
177182
},
178183
) as isvc:
179184
yield isvc
185+
186+
187+
@pytest.fixture(scope="class")
188+
def kserve_controller_manager_deployment(admin_client: DynamicClient) -> Generator[Deployment, Any, Any]:
189+
yield Deployment(
190+
client=admin_client,
191+
name="kserve-controller-manager",
192+
namespace=py_config["applications_namespace"],
193+
ensure_exists=True,
194+
)
195+
196+
197+
@pytest.fixture(scope="class")
198+
def patched_dsc_kserve_headed(
199+
admin_client, kserve_controller_manager_deployment: Deployment
200+
) -> Generator[DataScienceCluster, None, None]:
201+
"""Configure KServe Services to work in Headed mode i.e. using the Service port instead of the Pod port"""
202+
dsc = get_data_science_cluster(client=admin_client)
203+
with ResourceEditor(patches={dsc: {"spec": {"components": {"kserve": {"rawDeploymentServiceConfig": "Headed"}}}}}):
204+
kserve_controller_manager_deployment.wait_for_replicas()
205+
yield dsc

tests/llama_stack/safety/test_trustyai_fms_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
indirect=True,
3939
)
4040
@pytest.mark.rawdeployment
41-
@pytest.mark.usefixtures("orchestrator_config", "guardrails_orchestrator")
41+
@pytest.mark.usefixtures("patched_dsc_kserve_headed", "orchestrator_config", "guardrails_orchestrator")
4242
@pytest.mark.model_explainability
4343
class TestLlamaStackFMSGuardrailsProvider:
4444
"""

tests/model_explainability/guardrails/test_guardrails.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_validate_guardrails_orchestrator_images(
124124
)
125125
@pytest.mark.smoke
126126
@pytest.mark.rawdeployment
127-
@pytest.mark.usefixtures("guardrails_gateway_config")
127+
@pytest.mark.usefixtures("patched_dsc_kserve_headed", "guardrails_gateway_config")
128128
class TestGuardrailsOrchestratorWithBuiltInDetectors:
129129
"""
130130
Tests if basic functions of the GuardrailsOrchestrator are working properly with the built-in (regex) detectors.
@@ -297,6 +297,7 @@ def test_guardrails_builtin_detectors_negative_detection(
297297
)
298298
@pytest.mark.rawdeployment
299299
@pytest.mark.usefixtures(
300+
"patched_dsc_kserve_headed",
300301
"guardrails_gateway_config",
301302
"minio_pvc_otel",
302303
"minio_deployment_otel",
@@ -428,6 +429,7 @@ def check_traces():
428429
],
429430
indirect=True,
430431
)
432+
@pytest.mark.usefixtures("patched_dsc_kserve_headed")
431433
@pytest.mark.rawdeployment
432434
class TestGuardrailsOrchestratorAutoConfig:
433435
"""
@@ -515,6 +517,7 @@ def test_guardrails_autoconfig_negative_detection(
515517
],
516518
indirect=True,
517519
)
520+
@pytest.mark.usefixtures("patched_dsc_kserve_headed")
518521
@pytest.mark.rawdeployment
519522
class TestGuardrailsOrchestratorAutoConfigWithGateway:
520523
"""

tests/model_explainability/guardrails/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def create_detector_config(*detector_names: str) -> Dict[str, Dict[str, Any]]:
239239
}
240240

241241

242-
@retry(exceptions_dict={TimeoutError: []}, wait_timeout=10, sleep=1)
242+
@retry(exceptions_dict={TimeoutError: []}, wait_timeout=120, sleep=10)
243243
def check_guardrails_health_endpoint(
244244
host,
245245
token,
@@ -300,7 +300,7 @@ def send_chat_detections_request(
300300
)
301301

302302

303-
@retry(exceptions_dict={TimeoutError: []}, wait_timeout=10, sleep=1)
303+
@retry(exceptions_dict={TimeoutError: []}, wait_timeout=120, sleep=1)
304304
def send_and_verify_unsuitable_input_detection(
305305
url: str,
306306
token: str,
@@ -324,7 +324,7 @@ def send_and_verify_unsuitable_input_detection(
324324
return response
325325

326326

327-
@retry(exceptions_dict={TimeoutError: []}, wait_timeout=10, sleep=1)
327+
@retry(exceptions_dict={TimeoutError: []}, wait_timeout=120, sleep=1)
328328
def send_and_verify_unsuitable_output_detection(
329329
url: str,
330330
token: str,

tests/model_explainability/lm_eval/test_lm_eval.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def test_lmeval_local_offline_unitxt_tasks_flan_20newsgroups(
114114
],
115115
indirect=True,
116116
)
117+
@pytest.mark.usefixtures("patched_dsc_kserve_headed")
117118
def test_lmeval_vllm_emulator(admin_client, model_namespace, lmevaljob_vllm_emulator_pod):
118119
"""Basic test that verifies LMEval works with vLLM using a vLLM emulator for more efficient evaluation"""
119120
validate_lmeval_job_pod_and_logs(lmevaljob_pod=lmevaljob_vllm_emulator_pod)

utilities/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ class OpenVINO:
460460
CHAT_GENERATION_CONFIG: Dict[str, Any] = {
461461
"service": {
462462
"hostname": f"{QWEN_MODEL_NAME}-predictor",
463-
"port": 8032,
463+
"port": 80,
464464
"request_timeout": 600,
465465
}
466466
}

0 commit comments

Comments
 (0)