Skip to content

Commit fe06373

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent bc5a63b commit fe06373

File tree

2 files changed

+33
-58
lines changed

2 files changed

+33
-58
lines changed

tests/model_explainability/guardrails/conftest.py

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
from typing import Generator, Any
22

33
import pytest
4-
import yaml
54
from kubernetes.dynamic import DynamicClient
65
from kubernetes.dynamic.exceptions import ResourceNotFoundError
76
from ocp_resources.cluster_service_version import ClusterServiceVersion
8-
from ocp_resources.config_map import ConfigMap
97
from ocp_resources.deployment import Deployment
10-
from ocp_resources.exceptions import MissingRequiredArgumentError
11-
from ocp_resources.guardrails_orchestrator import GuardrailsOrchestrator
128
from ocp_resources.inference_service import InferenceService
13-
from ocp_resources.jaeger import Jaeger
149
from ocp_resources.namespace import Namespace
1510
from ocp_resources.open_telemetry_collector import OpenTelemetryCollector
1611
from ocp_resources.pod import Pod
17-
from ocp_resources.resource import ResourceEditor, NamespacedResource
1812
from ocp_resources.route import Route
1913
from ocp_resources.secret import Secret
2014
from ocp_resources.serving_runtime import ServingRuntime
21-
from ocp_resources.subscription import Subscription
2215
from ocp_utilities.operators import install_operator, uninstall_operator
23-
from pytest_testconfig import py_config
2416
from timeout_sampler import TimeoutSampler
2517

2618
from tests.model_explainability.guardrails.constants import AUTOCONFIG_DETECTOR_LABEL
2719
from utilities.certificates_utils import create_ca_bundle_file
2820
from utilities.constants import (
2921
KServeDeploymentType,
30-
Labels,
31-
Timeout, OPENSHIFT_OPERATORS, RuntimeTemplates,
22+
Timeout,
23+
OPENSHIFT_OPERATORS,
24+
RuntimeTemplates,
3225
)
3326
from utilities.inference_utils import create_isvc
3427
from utilities.operator_utils import get_cluster_service_version
@@ -153,6 +146,7 @@ def hap_detector_route(
153146
wait_for_resource=True,
154147
)
155148

149+
156150
@pytest.fixture(scope="class")
157151
def installed_opentelemetry_operator(admin_client: DynamicClient) -> Generator[None, Any, None]:
158152
"""
@@ -191,6 +185,7 @@ def installed_opentelemetry_operator(admin_client: DynamicClient) -> Generator[N
191185
clean_up_namespace=False,
192186
)
193187

188+
194189
@pytest.fixture(scope="class")
195190
def otel_operator_cr(
196191
admin_client: DynamicClient,
@@ -206,14 +201,13 @@ def otel_operator_cr(
206201

207202
alm_examples: list[dict[str, Any]] = otel_csv.get_alm_examples()
208203
otel_cr_dict: dict[str, Any] = next(
209-
example for example in alm_examples if example["kind"] == "OpenTelemetryCollector" and example["apiVersion"]=="opentelemetry.io/v1beta1"
204+
example
205+
for example in alm_examples
206+
if example["kind"] == "OpenTelemetryCollector" and example["apiVersion"] == "opentelemetry.io/v1beta1"
210207
)
211208

212-
213209
if not otel_cr_dict:
214-
raise ResourceNotFoundError(
215-
f"No OpenTelemetryCollector dict found in alm_examples for CSV {otel_csv.name}"
216-
)
210+
raise ResourceNotFoundError(f"No OpenTelemetryCollector dict found in alm_examples for CSV {otel_csv.name}")
217211

218212
otel_cr_dict["metadata"]["namespace"] = model_namespace.name
219213

@@ -224,10 +218,9 @@ def otel_operator_cr(
224218
)
225219
yield otel_cr
226220

221+
227222
@pytest.fixture(scope="class")
228-
def installed_tempo_operator(
229-
admin_client: DynamicClient, model_namespace: Namespace
230-
) -> Generator[None, Any, None]:
223+
def installed_tempo_operator(admin_client: DynamicClient, model_namespace: Namespace) -> Generator[None, Any, None]:
231224
"""
232225
Installs the Tempo operator and waits for its deployment.
233226
"""
@@ -264,12 +257,11 @@ def installed_tempo_operator(
264257
)
265258

266259

267-
268260
@pytest.fixture(scope="class")
269261
def tempo_instance(
270-
admin_client: DynamicClient,
271-
installed_tempo_operator: None,
272-
model_namespace: Namespace,
262+
admin_client: DynamicClient,
263+
installed_tempo_operator: None,
264+
model_namespace: Namespace,
273265
) -> Generator[Any, Any, None]:
274266
"""
275267
Create a Tempo instance in the test namespace.
@@ -283,23 +275,16 @@ def tempo_instance(
283275
)
284276

285277
alm_examples: list[dict[str, Any]] = tempo_csv.get_alm_examples()
286-
tempo_dict: dict[str, Any] = next(
287-
example for example in alm_examples if example["kind"] == "TempoMonolithic"
288-
)
278+
tempo_dict: dict[str, Any] = next(example for example in alm_examples if example["kind"] == "TempoMonolithic")
289279

290280
if not tempo_dict:
291-
raise ResourceNotFoundError(
292-
f"No Tempo dict found in alm_examples for CSV {tempo_csv.name}"
293-
)
281+
raise ResourceNotFoundError(f"No Tempo dict found in alm_examples for CSV {tempo_csv.name}")
294282

295283
tempo_dict["metadata"]["namespace"] = model_namespace.name
296284
tempo_dict["metadata"]["name"] = "my-tempo"
297285

298286
# Create Tempo resource
299-
tempo_resource = admin_client.resources.get(
300-
api_version=tempo_dict["apiVersion"],
301-
kind=tempo_dict["kind"]
302-
)
287+
tempo_resource = admin_client.resources.get(api_version=tempo_dict["apiVersion"], kind=tempo_dict["kind"])
303288
created_tempo = tempo_resource.create(body=tempo_dict, namespace=model_namespace.name)
304289

305290
wait_for_tempo_pods(
@@ -320,6 +305,7 @@ def wait_for_tempo_pods(
320305
"""
321306
Wait for pods created by a Tempo instance to be ready.
322307
"""
308+
323309
def _get_tempo_pods() -> list[Pod]:
324310
return [
325311
_pod
@@ -330,9 +316,7 @@ def _get_tempo_pods() -> list[Pod]:
330316
)
331317
]
332318

333-
sampler = TimeoutSampler(
334-
wait_timeout=timeout, sleep=1, func=lambda: bool(_get_tempo_pods())
335-
)
319+
sampler = TimeoutSampler(wait_timeout=timeout, sleep=1, func=lambda: bool(_get_tempo_pods()))
336320

337321
for sample in sampler:
338322
if sample:
@@ -361,14 +345,12 @@ def _get_collector_pods() -> list[Pod]:
361345
for _pod in Pod.get(
362346
dyn_client=client,
363347
namespace=namespace,
364-
label_selector=f"app.kubernetes.io/component=opentelemetry-collector",
348+
label_selector="app.kubernetes.io/component=opentelemetry-collector",
365349
)
366350
]
367351
return pods
368352

369-
sampler = TimeoutSampler(
370-
wait_timeout=timeout, sleep=1, func=lambda: bool(_get_collector_pods())
371-
)
353+
sampler = TimeoutSampler(wait_timeout=timeout, sleep=1, func=lambda: bool(_get_collector_pods()))
372354

373355
for sample in sampler:
374356
if sample:
@@ -384,13 +366,11 @@ def _get_collector_pods() -> list[Pod]:
384366

385367
@pytest.fixture(scope="class")
386368
def tempo_query_route(
387-
admin_client: DynamicClient,
388-
model_namespace: Namespace,
389-
tempo_instance
369+
admin_client: DynamicClient, model_namespace: Namespace, tempo_instance
390370
) -> Generator[Route, Any, Any]:
391371
tempo_query_route = Route(
392372
name="tempo-query",
393373
namespace=model_namespace.name,
394374
wait_for_resource=True,
395375
ensure_exists=True,
396-
)
376+
)

tests/model_explainability/guardrails/test_guardrails.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
import pytest
66
import requests
77
import yaml
8-
from ocp_resources.pod import Pod
98
from simple_logger.logger import get_logger
109
from timeout_sampler import retry
1110

12-
from tests.model_explainability.constants import MNT_MODELS
13-
from tests.model_explainability.guardrails.conftest import wait_for_jaeger_pods
1411
from tests.model_explainability.guardrails.constants import (
1512
AUTOCONFIG_DETECTOR_LABEL,
1613
PII_INPUT_DETECTION_PROMPT,
@@ -259,17 +256,16 @@ def test_guardrails_builtin_detectors_unsuitable_output(
259256
)
260257

261258
def test_guardrails_traces_in_jaeger(
262-
self,
263-
admin_client,
264-
jaeger_instance,
265-
otel_operator_cr,
266-
model_namespace,
267-
minio_pod,
268-
minio_data_connection,
269-
orchestrator_config,
270-
guardrails_orchestrator,
271-
guardrails_gateway_config,
272-
259+
self,
260+
admin_client,
261+
jaeger_instance,
262+
otel_operator_cr,
263+
model_namespace,
264+
minio_pod,
265+
minio_data_connection,
266+
orchestrator_config,
267+
guardrails_orchestrator,
268+
guardrails_gateway_config,
273269
):
274270
"""
275271
Ensure that OpenTelemetry traces from Guardrails Orchestrator are collected in Jaeger.
@@ -797,4 +793,3 @@ def test_guardrails_autoconfig_gateway_negative_detection(
797793
)
798794

799795
verify_negative_detection_response(response=response)
800-

0 commit comments

Comments
 (0)