66from typing import Any , Generator
77
88import pytest
9+ import shortuuid
910import yaml
1011from _pytest .tmpdir import TempPathFactory
1112from ocp_resources .config_map import ConfigMap
13+ from ocp_resources .pod import Pod
1214from ocp_resources .secret import Secret
15+ from ocp_resources .service import Service
1316from pyhelper_utils .shell import run_command
1417from pytest import FixtureRequest , Config
1518from kubernetes .dynamic import DynamicClient
2124from simple_logger .logger import get_logger
2225
2326from utilities .data_science_cluster_utils import update_components_in_dsc
27+ from utilities .general import get_s3_secret_dict
2428from utilities .infra import (
2529 create_ns ,
2630 get_dsci_applications_namespace ,
2731 get_operator_distribution ,
2832 login_with_user_password ,
2933 get_openshift_token ,
3034)
31- from utilities .constants import AcceleratorType , DscComponents
35+ from utilities .constants import (
36+ AcceleratorType ,
37+ ApiGroups ,
38+ DscComponents ,
39+ Labels ,
40+ MinIo ,
41+ Protocols ,
42+ )
3243from utilities .infra import update_configmap_data
3344
3445
@@ -285,7 +296,9 @@ def updated_dsc_component_state(
285296
286297
287298@pytest .fixture (scope = "package" )
288- def enabled_modelmesh_in_dsc (dsc_resource : DataScienceCluster ) -> Generator [DataScienceCluster , Any , Any ]:
299+ def enabled_modelmesh_in_dsc (
300+ dsc_resource : DataScienceCluster ,
301+ ) -> Generator [DataScienceCluster , Any , Any ]:
289302 with update_components_in_dsc (
290303 dsc = dsc_resource ,
291304 components = {DscComponents .MODELMESHSERVING : DscComponents .ManagementState .MANAGED },
@@ -305,7 +318,9 @@ def enabled_kserve_in_dsc(
305318
306319
307320@pytest .fixture (scope = "session" )
308- def cluster_monitoring_config (admin_client : DynamicClient ) -> Generator [ConfigMap , Any , Any ]:
321+ def cluster_monitoring_config (
322+ admin_client : DynamicClient ,
323+ ) -> Generator [ConfigMap , Any , Any ]:
309324 data = {"config.yaml" : yaml .dump ({"enableUserWorkload" : True })}
310325
311326 with update_configmap_data (
@@ -326,3 +341,104 @@ def unprivileged_model_namespace(
326341
327342 with create_ns (unprivileged_client = unprivileged_client , pytest_request = request ) as ns :
328343 yield ns
344+
345+
346+ # MinIo
347+ @pytest .fixture (scope = "class" )
348+ def minio_namespace (admin_client : DynamicClient ) -> Generator [Namespace , Any , Any ]:
349+ with create_ns (
350+ name = f"{ MinIo .Metadata .NAME } -{ shortuuid .uuid ().lower ()} " ,
351+ admin_client = admin_client ,
352+ ) as ns :
353+ yield ns
354+
355+
356+ @pytest .fixture (scope = "class" )
357+ def minio_pod (
358+ request : FixtureRequest ,
359+ admin_client : DynamicClient ,
360+ minio_namespace : Namespace ,
361+ ) -> Generator [Pod , Any , Any ]:
362+ pod_labels = {Labels .Openshift .APP : MinIo .Metadata .NAME }
363+
364+ if labels := request .param .get ("labels" ):
365+ pod_labels .update (labels )
366+
367+ with Pod (
368+ client = admin_client ,
369+ name = MinIo .Metadata .NAME ,
370+ namespace = minio_namespace .name ,
371+ containers = [
372+ {
373+ "args" : request .param .get ("args" ),
374+ "env" : [
375+ {
376+ "name" : MinIo .Credentials .ACCESS_KEY_NAME ,
377+ "value" : MinIo .Credentials .ACCESS_KEY_VALUE ,
378+ },
379+ {
380+ "name" : MinIo .Credentials .SECRET_KEY_NAME ,
381+ "value" : MinIo .Credentials .SECRET_KEY_VALUE ,
382+ },
383+ ],
384+ "image" : request .param .get ("image" ),
385+ "name" : MinIo .Metadata .NAME ,
386+ }
387+ ],
388+ label = pod_labels ,
389+ annotations = request .param .get ("annotations" ),
390+ ) as minio_pod :
391+ yield minio_pod
392+
393+
394+ @pytest .fixture (scope = "class" )
395+ def minio_service (admin_client : DynamicClient , minio_namespace : Namespace ) -> Generator [Service , Any , Any ]:
396+ with Service (
397+ client = admin_client ,
398+ name = MinIo .Metadata .NAME ,
399+ namespace = minio_namespace .name ,
400+ ports = [
401+ {
402+ "name" : f"{ MinIo .Metadata .NAME } -client-port" ,
403+ "port" : MinIo .Metadata .DEFAULT_PORT ,
404+ "protocol" : Protocols .TCP ,
405+ "targetPort" : MinIo .Metadata .DEFAULT_PORT ,
406+ }
407+ ],
408+ selector = {
409+ Labels .Openshift .APP : MinIo .Metadata .NAME ,
410+ },
411+ ) as minio_service :
412+ yield minio_service
413+
414+
415+ @pytest .fixture (scope = "class" )
416+ def minio_data_connection (
417+ request : FixtureRequest ,
418+ admin_client : DynamicClient ,
419+ model_namespace : Namespace ,
420+ minio_service : Service ,
421+ ) -> Generator [Secret , Any , Any ]:
422+ data_dict = get_s3_secret_dict (
423+ aws_access_key = MinIo .Credentials .ACCESS_KEY_VALUE ,
424+ aws_secret_access_key = MinIo .Credentials .SECRET_KEY_VALUE , # pragma: allowlist secret
425+ aws_s3_bucket = request .param ["bucket" ],
426+ aws_s3_endpoint = f"{ Protocols .HTTP } ://{ minio_service .instance .spec .clusterIP } :{ str (MinIo .Metadata .DEFAULT_PORT )} " , # noqa: E501
427+ aws_s3_region = "us-south" ,
428+ )
429+
430+ with Secret (
431+ client = admin_client ,
432+ name = "aws-connection-minio-data-connection" ,
433+ namespace = model_namespace .name ,
434+ data_dict = data_dict ,
435+ label = {
436+ Labels .OpenDataHub .DASHBOARD : "true" ,
437+ Labels .OpenDataHubIo .MANAGED : "true" ,
438+ },
439+ annotations = {
440+ f"{ ApiGroups .OPENDATAHUB_IO } /connection-type" : "s3" ,
441+ "openshift.io/display-name" : "Minio Data Connection" ,
442+ },
443+ ) as minio_secret :
444+ yield minio_secret
0 commit comments