1212from timeout_sampler import TimeoutSampler
1313from utilities .llmd_utils import create_llmisvc
1414from utilities .llmd_constants import ModelStorage , ContainerImages
15+ from ocp_resources .gateway_gateway_networking_k8s_io import Gateway
16+ from ocp_resources .data_science_cluster import DataScienceCluster
1517from utilities .constants import (
1618 MAAS_GATEWAY_NAMESPACE ,
1719 MAAS_RATE_LIMIT_POLICY_NAME ,
1820 MAAS_TOKEN_RATE_LIMIT_POLICY_NAME ,
19- Timeout ,
2021)
2122
2223from ocp_resources .infrastructure import Infrastructure
2829from utilities .general import wait_for_oauth_openshift_deployment
2930from ocp_resources .secret import Secret
3031from tests .model_serving .model_server .maas_billing .utils import get_total_tokens
31- from utilities .infra import get_data_science_cluster
32- from utilities .constants import DscComponents
32+ from utilities .constants import DscComponents , MAAS_GATEWAY_NAME
3333from utilities .resources .rate_limit_policy import RateLimitPolicy
3434from utilities .resources .token_rate_limit_policy import TokenRateLimitPolicy
3535from tests .model_serving .model_server .maas_billing .utils import (
4444 maas_gateway_rate_limits_patched ,
4545 detect_maas_control_plane_namespace ,
4646 get_tier_mapping_configmap ,
47- ensure_maas_gateway_api ,
48- ensure_maas_usage_policies ,
4947 endpoints_have_ready_addresses ,
5048 gateway_probe_reaches_maas_api ,
49+ maas_gateway_listeners ,
5150)
5251
5352LOGGER = get_logger (name = __name__ )
@@ -577,7 +576,7 @@ def maas_inference_service_tinyllama(
577576 },
578577 service_account = model_service_account .name ,
579578 wait = False ,
580- timeout = Timeout . TIMEOUT_15MIN ,
579+ timeout = 900 ,
581580 ) as llm_service :
582581 with patch_llmisvc_with_maas_router (
583582 llm_service = llm_service ,
@@ -589,7 +588,7 @@ def maas_inference_service_tinyllama(
589588 llm_service .wait_for_condition (
590589 condition = "Ready" ,
591590 status = "True" ,
592- timeout = Timeout . TIMEOUT_15MIN ,
591+ timeout = 900 ,
593592 )
594593
595594 LOGGER .info (
@@ -637,47 +636,40 @@ def maas_gateway_api_hostname(admin_client: DynamicClient) -> str:
637636
638637@pytest .fixture (scope = "session" )
639638def maas_gateway_and_policies (
640- admin_client : DynamicClient ,
641- maas_gateway_api_hostname : str ,
642- ) -> Generator [None , None , None ]:
643- """
644- Ensure MaaS Gateway + Kuadrant policies exist once per test session.
645- """
646- with (
647- ensure_maas_gateway_api (
648- admin_client = admin_client ,
649- hostname = maas_gateway_api_hostname ,
650- ),
651- ensure_maas_usage_policies (
652- admin_client = admin_client ,
653- ),
654- ):
655- yield
639+ maas_gateway_api : None ,
640+ maas_usage_policies : None ,
641+ ) -> None :
642+ yield
656643
657644
658645@pytest .fixture (scope = "session" )
659646def maas_controller_enabled_latest (
660- admin_client : DynamicClient ,
647+ dsc_resource : DataScienceCluster ,
661648 maas_gateway_and_policies : None ,
662- ):
663- dsc_resource = get_data_science_cluster (client = admin_client )
664- dsc_resource .get ()
665-
666- original_components = dsc_resource .instance .spec .components
667-
668- kserve = original_components [DscComponents .KSERVE ]
669- maas = kserve ["modelsAsService" ]
670- if maas ["managementState" ] == "Managed" :
671- dsc_resource .wait_for_condition (condition = "ModelsAsServiceReady" , status = "True" , timeout = Timeout .TIMEOUT_15MIN )
649+ ) -> Generator [DataScienceCluster , None , None ]:
650+ original_components = dsc_resource .instance .spec .components or {}
651+ kserve = original_components .get (DscComponents .KSERVE , {}) or {}
652+ maas = kserve .get ("modelsAsService" , {}) or {}
653+
654+ if maas .get ("managementState" ) == DscComponents .ManagementState .MANAGED :
655+ dsc_resource .wait_for_condition (
656+ condition = "ModelsAsServiceReady" ,
657+ status = "True" ,
658+ timeout = 300 ,
659+ )
672660 yield dsc_resource
661+ return
673662
674- component_patch = {DscComponents .KSERVE : {"modelsAsService" : {"managementState" : "Managed" }}}
663+ component_patch = {
664+ DscComponents .KSERVE : {"modelsAsService" : {"managementState" : DscComponents .ManagementState .MANAGED }}
665+ }
675666
676667 with ResourceEditor (patches = {dsc_resource : {"spec" : {"components" : component_patch }}}):
677- dsc_resource .wait_for_condition (condition = "ModelsAsServiceReady" , status = "True" , timeout = Timeout . TIMEOUT_15MIN )
678- dsc_resource .wait_for_condition (condition = "Ready" , status = "True" , timeout = Timeout . TIMEOUT_15MIN )
668+ dsc_resource .wait_for_condition (condition = "ModelsAsServiceReady" , status = "True" , timeout = 900 )
669+ dsc_resource .wait_for_condition (condition = "Ready" , status = "True" , timeout = 600 )
679670 yield dsc_resource
680- dsc_resource .wait_for_condition (condition = "Ready" , status = "True" , timeout = Timeout .TIMEOUT_15MIN )
671+
672+ dsc_resource .wait_for_condition (condition = "Ready" , status = "True" , timeout = 600 )
681673
682674
683675@pytest .fixture (scope = "session" )
@@ -719,16 +711,17 @@ def maas_api_ready(
719711 client = admin_client ,
720712 name = "maas-api" ,
721713 namespace = "opendatahub" ,
714+ ensure_exists = True ,
722715 )
723716 maas_api_deployment .wait_for_condition (
724717 condition = "Available" ,
725718 status = "True" ,
726- timeout = Timeout . TIMEOUT_10MIN ,
719+ timeout = 600 ,
727720 )
728721
729722 endpoints_ready = False
730723 for endpoints_ready_sample in TimeoutSampler (
731- wait_timeout = Timeout . TIMEOUT_5MIN ,
724+ wait_timeout = 300 ,
732725 sleep = 5 ,
733726 func = endpoints_have_ready_addresses ,
734727 admin_client = admin_client ,
@@ -748,7 +741,7 @@ def maas_api_ready(
748741 last_response_body : str | None = None
749742
750743 for gateway_probe_sample in TimeoutSampler (
751- wait_timeout = Timeout . TIMEOUT_5MIN ,
744+ wait_timeout = 300 ,
752745 sleep = 5 ,
753746 func = gateway_probe_reaches_maas_api ,
754747 http_session = request_session_http ,
@@ -795,3 +788,83 @@ def maas_token_ratelimit_policy(
795788 namespace = MAAS_GATEWAY_NAMESPACE ,
796789 ensure_exists = True ,
797790 )
791+
792+
793+ @pytest .fixture (scope = "session" )
794+ def maas_gateway_api (
795+ admin_client : DynamicClient ,
796+ maas_gateway_api_hostname : str ,
797+ ) -> Generator [None , None , None ]:
798+ """
799+ Ensure MaaS Gateway exists once per test session.
800+ """
801+ gateway = Gateway (
802+ client = admin_client ,
803+ name = MAAS_GATEWAY_NAME ,
804+ namespace = MAAS_GATEWAY_NAMESPACE ,
805+ gateway_class_name = "openshift-default" ,
806+ listeners = maas_gateway_listeners (hostname = maas_gateway_api_hostname ),
807+ annotations = {"opendatahub.io/managed" : "false" },
808+ label = {
809+ "app.kubernetes.io/name" : "maas" ,
810+ "app.kubernetes.io/instance" : MAAS_GATEWAY_NAME ,
811+ "app.kubernetes.io/component" : "gateway" ,
812+ "opendatahub.io/managed" : "false" ,
813+ },
814+ ensure_exists = False ,
815+ wait_for_resource = True ,
816+ teardown = True ,
817+ )
818+
819+ with gateway :
820+ yield
821+
822+
823+ @pytest .fixture (scope = "session" )
824+ def maas_usage_policies (
825+ admin_client : DynamicClient ,
826+ maas_gateway_api : None ,
827+ ) -> Generator [None , None , None ]:
828+ """
829+ Ensure MaaS Kuadrant policies exist once per test session.
830+ """
831+ target_ref = {
832+ "group" : "gateway.networking.k8s.io" ,
833+ "kind" : "Gateway" ,
834+ "name" : MAAS_GATEWAY_NAME ,
835+ }
836+
837+ request_policy = RateLimitPolicy (
838+ client = admin_client ,
839+ name = MAAS_RATE_LIMIT_POLICY_NAME ,
840+ namespace = MAAS_GATEWAY_NAMESPACE ,
841+ target_ref = target_ref ,
842+ limits = {
843+ "bootstrap" : {
844+ "counters" : [{"expression" : "auth.identity.userid" }],
845+ "rates" : [{"limit" : 1000 , "window" : "1m" }],
846+ }
847+ },
848+ ensure_exists = False ,
849+ wait_for_resource = True ,
850+ teardown = True ,
851+ )
852+
853+ token_policy = TokenRateLimitPolicy (
854+ client = admin_client ,
855+ name = MAAS_TOKEN_RATE_LIMIT_POLICY_NAME ,
856+ namespace = MAAS_GATEWAY_NAMESPACE ,
857+ target_ref = target_ref ,
858+ limits = {
859+ "bootstrap" : {
860+ "counters" : [{"expression" : "auth.identity.userid" }],
861+ "rates" : [{"limit" : 1000000 , "window" : "1m" }],
862+ }
863+ },
864+ ensure_exists = False ,
865+ wait_for_resource = True ,
866+ teardown = True ,
867+ )
868+
869+ with request_policy , token_policy :
870+ yield
0 commit comments