11from typing import Generator , Any
22
33import pytest
4- import yaml
54from kubernetes .dynamic import DynamicClient
65from kubernetes .dynamic .exceptions import ResourceNotFoundError
76from ocp_resources .cluster_service_version import ClusterServiceVersion
8- from ocp_resources .config_map import ConfigMap
97from ocp_resources .deployment import Deployment
10- from ocp_resources .exceptions import MissingRequiredArgumentError
11- from ocp_resources .guardrails_orchestrator import GuardrailsOrchestrator
128from ocp_resources .inference_service import InferenceService
13- from ocp_resources .jaeger import Jaeger
149from ocp_resources .namespace import Namespace
1510from ocp_resources .open_telemetry_collector import OpenTelemetryCollector
1611from ocp_resources .pod import Pod
17- from ocp_resources .resource import ResourceEditor , NamespacedResource
1812from ocp_resources .route import Route
1913from ocp_resources .secret import Secret
2014from ocp_resources .serving_runtime import ServingRuntime
21- from ocp_resources .subscription import Subscription
2215from ocp_utilities .operators import install_operator , uninstall_operator
23- from pytest_testconfig import py_config
2416from timeout_sampler import TimeoutSampler
2517
2618from tests .model_explainability .guardrails .constants import AUTOCONFIG_DETECTOR_LABEL
2719from utilities .certificates_utils import create_ca_bundle_file
2820from utilities .constants import (
2921 KServeDeploymentType ,
30- Labels ,
31- Timeout , OPENSHIFT_OPERATORS , RuntimeTemplates ,
22+ Timeout ,
23+ OPENSHIFT_OPERATORS ,
24+ RuntimeTemplates ,
3225)
3326from utilities .inference_utils import create_isvc
3427from 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" )
157151def 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" )
195190def 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" )
269261def 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" )
386368def 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+ )
0 commit comments