33from urllib .parse import urlparse
44
55import pytest
6- from _pytest .fixtures import FixtureRequest
76from kubernetes .dynamic import DynamicClient
87from ocp_resources .inference_service import InferenceService
98from ocp_resources .namespace import Namespace
1514 RuntimeTemplates ,
1615)
1716from utilities .inference_utils import create_isvc
18- from utilities .infra import get_pods_by_isvc_label
17+ from utilities .infra import create_ns , get_pods_by_isvc_label , s3_endpoint_secret
1918from utilities .serving_runtime import ServingRuntimeFromTemplate
2019
2120
22- @pytest .fixture (scope = "class" )
21+ @pytest .fixture (scope = "package" )
22+ def negative_test_namespace (
23+ admin_client : DynamicClient ,
24+ unprivileged_client : DynamicClient ,
25+ ) -> Generator [Namespace , Any , Any ]:
26+ """Create a shared namespace for all negative tests."""
27+ with create_ns (
28+ admin_client = admin_client ,
29+ unprivileged_client = unprivileged_client ,
30+ name = "negative-test-kserve" ,
31+ ) as ns :
32+ yield ns
33+
34+
35+ @pytest .fixture (scope = "package" )
36+ def negative_test_s3_secret (
37+ unprivileged_client : DynamicClient ,
38+ negative_test_namespace : Namespace ,
39+ aws_access_key_id : str ,
40+ aws_secret_access_key : str ,
41+ ci_s3_bucket_name : str ,
42+ ci_s3_bucket_region : str ,
43+ ci_s3_bucket_endpoint : str ,
44+ ) -> Generator [Secret , Any , Any ]:
45+ """Create S3 secret shared across all negative tests."""
46+ with s3_endpoint_secret (
47+ client = unprivileged_client ,
48+ name = "ci-bucket-secret" ,
49+ namespace = negative_test_namespace .name ,
50+ aws_access_key = aws_access_key_id ,
51+ aws_secret_access_key = aws_secret_access_key ,
52+ aws_s3_region = ci_s3_bucket_region ,
53+ aws_s3_bucket = ci_s3_bucket_name ,
54+ aws_s3_endpoint = ci_s3_bucket_endpoint ,
55+ ) as secret :
56+ yield secret
57+
58+
59+ @pytest .fixture (scope = "package" )
2360def ovms_serving_runtime (
2461 admin_client : DynamicClient ,
25- unprivileged_model_namespace : Namespace ,
62+ negative_test_namespace : Namespace ,
2663) -> Generator [ServingRuntime , Any , Any ]:
27- """Create OVMS serving runtime for negative tests."""
64+ """Create OVMS serving runtime shared across all negative tests."""
2865 with ServingRuntimeFromTemplate (
2966 client = admin_client ,
3067 name = "negative-test-ovms-runtime" ,
31- namespace = unprivileged_model_namespace .name ,
68+ namespace = negative_test_namespace .name ,
3269 template_name = RuntimeTemplates .OVMS_KSERVE ,
3370 multi_model = False ,
3471 enable_http = True ,
@@ -37,27 +74,26 @@ def ovms_serving_runtime(
3774 yield runtime
3875
3976
40- @pytest .fixture (scope = "class " )
77+ @pytest .fixture (scope = "package " )
4178def negative_test_ovms_isvc (
42- request : FixtureRequest ,
4379 admin_client : DynamicClient ,
44- unprivileged_model_namespace : Namespace ,
80+ negative_test_namespace : Namespace ,
4581 ovms_serving_runtime : ServingRuntime ,
4682 ci_s3_bucket_name : str ,
47- ci_endpoint_s3_secret : Secret ,
83+ negative_test_s3_secret : Secret ,
4884) -> Generator [InferenceService , Any , Any ]:
49- """Create InferenceService with OVMS runtime for negative tests."""
50- storage_uri = f"s3://{ ci_s3_bucket_name } /{ request . param [ 'model -dir' ] } /"
85+ """Create InferenceService with OVMS runtime shared across all negative tests."""
86+ storage_uri = f"s3://{ ci_s3_bucket_name } /test -dir/"
5187 supported_formats = ovms_serving_runtime .instance .spec .supportedModelFormats
5288 if not supported_formats :
5389 raise ValueError (f"ServingRuntime '{ ovms_serving_runtime .name } ' has no supportedModelFormats" )
5490
5591 with create_isvc (
5692 client = admin_client ,
5793 name = "negative-test-ovms-isvc" ,
58- namespace = unprivileged_model_namespace .name ,
94+ namespace = negative_test_namespace .name ,
5995 runtime = ovms_serving_runtime .name ,
60- storage_key = ci_endpoint_s3_secret .name ,
96+ storage_key = negative_test_s3_secret .name ,
6197 storage_path = urlparse (storage_uri ).path ,
6298 model_format = supported_formats [0 ].name ,
6399 deployment_mode = KServeDeploymentType .RAW_DEPLOYMENT ,
0 commit comments