Skip to content

Commit 58bc804

Browse files
committed
removing unused constants
1 parent 07ca89d commit 58bc804

4 files changed

Lines changed: 32 additions & 28 deletions

File tree

tests/model_explainability/guardrails/conftest.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,10 @@
3333
from utilities.serving_runtime import ServingRuntimeFromTemplate
3434

3535

36-
USER_ONE: str = "user-one"
36+
GUARDRAILS_ORCHESTRATOR_NAME = "guardrails-orchestrator"
3737

38-
GORCH_NAME = "guardrails-orchestrator"
39-
GORCH_CONFIGMAP_NAME = "fms-orchestr8-config-nlp"
40-
GORCH_PORT: int = 8032
4138

42-
43-
# GuardrailsOrchestrator related fixtures
39+
# Fixtures related to the Guardrails Orchestrator
4440
@pytest.fixture(scope="class")
4541
def guardrails_orchestrator(
4642
request: FixtureRequest,
@@ -50,7 +46,7 @@ def guardrails_orchestrator(
5046
) -> Generator[GuardrailsOrchestrator, Any, Any]:
5147
gorch_kwargs = {
5248
"client": admin_client,
53-
"name": GORCH_NAME,
49+
"name": GUARDRAILS_ORCHESTRATOR_NAME,
5450
"namespace": model_namespace.name,
5551
"orchestrator_config": orchestrator_config.name,
5652
"replicas": 1,
@@ -104,7 +100,11 @@ def guardrails_orchestrator_pod(
104100
model_namespace: Namespace,
105101
guardrails_orchestrator: GuardrailsOrchestrator,
106102
) -> Pod:
107-
return list(Pod.get(namespace=model_namespace.name, label_selector=f"app.kubernetes.io/instance={GORCH_NAME}"))[0]
103+
return list(
104+
Pod.get(
105+
namespace=model_namespace.name, label_selector=f"app.kubernetes.io/instance={GUARDRAILS_ORCHESTRATOR_NAME}"
106+
)
107+
)[0]
108108

109109

110110
@pytest.fixture(scope="class")
@@ -154,10 +154,10 @@ def vllm_runtime(
154154
containers={
155155
"kserve-container": {
156156
"args": [
157-
f"--port={str(GORCH_PORT)}",
157+
f"--port={str(8032)}",
158158
"--model=/mnt/models",
159159
],
160-
"ports": [{"containerPort": GORCH_PORT, "protocol": "TCP"}],
160+
"ports": [{"containerPort": 8032, "protocol": "TCP"}],
161161
"volumeMounts": [{"mountPath": "/dev/shm", "name": "shm"}],
162162
}
163163
},
@@ -280,7 +280,7 @@ def prompt_injection_detector_route(
280280
)
281281

282282

283-
# Llama-stack fixtures
283+
# LlamaStack fixtures
284284
@pytest.fixture(scope="class")
285285
def llamastack_distribution_trustyai(
286286
admin_client: DynamicClient,
@@ -369,7 +369,7 @@ def llamastack_client_trustyai(
369369
return LlamaStackClient(base_url=f"http://{llamastack_distribution_trustyai_route.host}")
370370

371371

372-
# Other
372+
# Other "helper" fixtures
373373
@pytest.fixture(scope="class")
374374
def openshift_ca_bundle_file(
375375
admin_client: DynamicClient,
@@ -382,17 +382,16 @@ def guardrails_orchestrator_ssl_cert(guardrails_orchestrator_route: Route):
382382
hostname = guardrails_orchestrator_route.host
383383

384384
try:
385-
cmd = ["openssl", "s_client", "-showcerts", "-connect", f"{hostname}:443"]
386-
387-
process = subprocess.Popen(
388-
args=cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
385+
result = subprocess.run(
386+
args=["openssl", "s_client", "-showcerts", "-connect", f"{hostname}:443"],
387+
input="",
388+
capture_output=True,
389+
text=True,
389390
)
390391

391-
stdout, _ = process.communicate(input="")
392-
393392
cert_lines = []
394393
in_cert = False
395-
for line in stdout.split("\n"):
394+
for line in result.stdout.splitlines():
396395
if "-----BEGIN CERTIFICATE-----" in line:
397396
in_cert = True
398397
if in_cert:

tests/model_explainability/guardrails/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@
2020
"port": 8032,
2121
}
2222
}
23+
24+
EXAMPLE_EMAIL_ADDRESS: str = "myemail@domain.com"
25+
PROMPT_WITH_PII: str = f"This is my email address: {EXAMPLE_EMAIL_ADDRESS}, just answer ACK."

tests/model_explainability/guardrails/test_guardrails.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
QWEN_ISVC_NAME,
1212
CHAT_GENERATION_CONFIG,
1313
BUILTIN_DETECTOR_CONFIG,
14+
PROMPT_WITH_PII,
15+
EXAMPLE_EMAIL_ADDRESS,
1416
)
1517
from tests.model_explainability.guardrails.utils import (
1618
verify_builtin_detector_unsuitable_input_response,
@@ -25,8 +27,6 @@
2527

2628
LOGGER = get_logger(name=__name__)
2729

28-
EXAMPLE_EMAIL_ADDRESS: str = "myemail@domain.com"
29-
PROMPT_WITH_PII: str = f"This is my email address: {EXAMPLE_EMAIL_ADDRESS}, just answer ACK."
3030
HARMLESS_PROMPT: str = "What is the opposite of up?"
3131
MNT_MODELS: str = "/mnt/models"
3232

@@ -59,7 +59,6 @@
5959
indirect=True,
6060
)
6161
@pytest.mark.smoke
62-
@pytest.mark.usefixtures("guardrails_orchestrator")
6362
def test_validate_guardrails_orchestrator_images(guardrails_orchestrator_pod, trustyai_operator_configmap):
6463
"""Test to verify Guardrails pod images.
6564
Checks if the image tag from the ConfigMap is used within the Pod and if it's pinned using a sha256 digest.
@@ -112,7 +111,7 @@ def test_validate_guardrails_orchestrator_images(guardrails_orchestrator_pod, tr
112111
)
113112
@pytest.mark.smoke
114113
@pytest.mark.rawdeployment
115-
@pytest.mark.usefixtures("guardrails_gateway_config", "guardrails_orchestrator")
114+
@pytest.mark.usefixtures("guardrails_gateway_config")
116115
class TestGuardrailsOrchestratorWithBuiltInDetectors:
117116
"""
118117
Tests that the basic functionality of the GuardrailsOrchestrator work properly with the built-in (regex) detectors.
@@ -261,7 +260,6 @@ def test_guardrails_builtin_detectors_negative_detection(
261260
indirect=True,
262261
)
263262
@pytest.mark.rawdeployment
264-
@pytest.mark.usefixtures("guardrails_orchestrator")
265263
class TestGuardrailsOrchestratorWithHuggingFaceDetectors:
266264
"""
267265
These tests verify that the GuardrailsOrchestrator works as expected when using HuggingFace detectors

tests/model_explainability/guardrails/test_llamastack_fms_provider.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import yaml
33
from simple_logger.logger import get_logger
44

5-
from tests.model_explainability.guardrails.constants import CHAT_GENERATION_CONFIG, BUILTIN_DETECTOR_CONFIG
5+
from tests.model_explainability.guardrails.constants import (
6+
CHAT_GENERATION_CONFIG,
7+
BUILTIN_DETECTOR_CONFIG,
8+
PROMPT_WITH_PII,
9+
)
610
from tests.model_explainability.guardrails.test_guardrails import MNT_MODELS
711
from utilities.constants import MinIo
812

@@ -30,7 +34,6 @@
3034
],
3135
indirect=True,
3236
)
33-
@pytest.mark.usefixtures("minio_pod", "guardrails_orchestrator")
3437
class TestLlamaStackFMSGuardrailsProvider:
3538
"""
3639
Adds basic tests for the LlamaStack FMS Guardrails provider.
@@ -41,7 +44,7 @@ class TestLlamaStackFMSGuardrailsProvider:
4144
1. Register the generator model via lls client
4245
2. Test that we can run inferences on said model via lls client
4346
3. Register the shields (detectors)
44-
4. TODO: Add tests for run_shields
47+
4. Test a basic detection (PII) by using run_shields
4548
"""
4649

4750
def test_fms_guardrails_register_model(self, qwen_isvc, llamastack_client_trustyai):
@@ -85,6 +88,7 @@ def test_fms_guardrails_register_shield(
8588
provider_shield_id=PII_REGEX_SHIELD_ID,
8689
provider_id=trustyai_fms_provider_id,
8790
params=shield_params,
91+
timeout=120,
8892
)
8993
shields = llamastack_client_trustyai.shields.list()
9094

@@ -98,7 +102,7 @@ def test_fms_guardrails_run_shield(self, llamastack_client_trustyai):
98102
shield_id=PII_REGEX_SHIELD_ID,
99103
messages=[
100104
{
101-
"content": "my email is example@mail.com",
105+
"content": PROMPT_WITH_PII,
102106
"role": "system",
103107
},
104108
],

0 commit comments

Comments
 (0)