55import requests
66from kubernetes .dynamic import DynamicClient
77from ocp_resources .llm_inference_service import LLMInferenceService
8+ from ocp_resources .maas_auth_policy import MaaSAuthPolicy
89from ocp_resources .maas_model_ref import MaaSModelRef
10+ from ocp_resources .maas_subscription import MaaSSubscription
911from ocp_resources .namespace import Namespace
1012from ocp_resources .service_account import ServiceAccount
1113from pytest_testconfig import config as py_config
1214from simple_logger .logger import get_logger
1315
1416from tests .model_serving .model_server .maas_billing .maas_subscription .utils import (
17+ MAAS_SUBSCRIPTION_NAMESPACE ,
1518 create_api_key ,
1619 patch_llmisvc_with_maas_router_and_tiers ,
1720)
1821from tests .model_serving .model_server .maas_billing .utils import build_maas_headers
1922from utilities .general import generate_random_name
20- from utilities .infra import create_inference_token , login_with_user_password
23+ from utilities .infra import create_inference_token , create_ns , login_with_user_password
2124from utilities .llmd_constants import ContainerImages , ModelStorage
2225from utilities .llmd_utils import create_llmisvc
2326from utilities .plugins .constant import OpenAIEnpoints
24- from utilities .resources .maa_s_auth_policy import MaaSAuthPolicy
25- from utilities .resources .maa_s_subscription import MaaSSubscription
2627
2728LOGGER = get_logger (name = __name__ )
2829
@@ -90,12 +91,11 @@ def maas_model_tinyllama_free(
9091 admin_client : DynamicClient ,
9192 maas_inference_service_tinyllama_free : LLMInferenceService ,
9293) -> Generator [MaaSModelRef ]:
93- applications_namespace = py_config ["applications_namespace" ]
9494
9595 with MaaSModelRef (
9696 client = admin_client ,
9797 name = maas_inference_service_tinyllama_free .name ,
98- namespace = applications_namespace ,
98+ namespace = maas_inference_service_tinyllama_free . namespace ,
9999 model_ref = {
100100 "name" : maas_inference_service_tinyllama_free .name ,
101101 "namespace" : maas_inference_service_tinyllama_free .namespace ,
@@ -112,12 +112,11 @@ def maas_model_tinyllama_premium(
112112 admin_client : DynamicClient ,
113113 maas_inference_service_tinyllama_premium : LLMInferenceService ,
114114) -> Generator [MaaSModelRef ]:
115- applications_namespace = py_config ["applications_namespace" ]
116115
117116 with MaaSModelRef (
118117 client = admin_client ,
119118 name = maas_inference_service_tinyllama_premium .name ,
120- namespace = applications_namespace ,
119+ namespace = maas_inference_service_tinyllama_premium . namespace ,
121120 model_ref = {
122121 "name" : maas_inference_service_tinyllama_premium .name ,
123122 "namespace" : maas_inference_service_tinyllama_premium .namespace ,
@@ -134,14 +133,19 @@ def maas_auth_policy_tinyllama_free(
134133 admin_client : DynamicClient ,
135134 maas_free_group : str ,
136135 maas_model_tinyllama_free : MaaSModelRef ,
136+ maas_subscription_namespace : Namespace ,
137137) -> Generator [MaaSAuthPolicy ]:
138- applications_namespace = py_config ["applications_namespace" ]
139138
140139 with MaaSAuthPolicy (
141140 client = admin_client ,
142141 name = "tinyllama-free-access" ,
143- namespace = applications_namespace ,
144- model_refs = [maas_model_tinyllama_free .name ],
142+ namespace = maas_subscription_namespace .name ,
143+ model_refs = [
144+ {
145+ "name" : maas_model_tinyllama_free .name ,
146+ "namespace" : maas_model_tinyllama_free .namespace ,
147+ }
148+ ],
145149 subjects = {
146150 "groups" : [
147151 {"name" : "system:authenticated" },
@@ -159,14 +163,19 @@ def maas_auth_policy_tinyllama_premium(
159163 admin_client : DynamicClient ,
160164 maas_premium_group : str ,
161165 maas_model_tinyllama_premium : MaaSModelRef ,
166+ maas_subscription_namespace : Namespace ,
162167) -> Generator [MaaSAuthPolicy ]:
163- applications_namespace = py_config ["applications_namespace" ]
164168
165169 with MaaSAuthPolicy (
166170 client = admin_client ,
167171 name = "tinyllama-premium-access" ,
168- namespace = applications_namespace ,
169- model_refs = [maas_model_tinyllama_premium .name ],
172+ namespace = maas_subscription_namespace .name ,
173+ model_refs = [
174+ {
175+ "name" : maas_model_tinyllama_premium .name ,
176+ "namespace" : maas_model_tinyllama_premium .namespace ,
177+ }
178+ ],
170179 subjects = {
171180 "groups" : [{"name" : maas_premium_group }],
172181 },
@@ -181,19 +190,20 @@ def maas_subscription_tinyllama_free(
181190 admin_client : DynamicClient ,
182191 maas_free_group : str ,
183192 maas_model_tinyllama_free : MaaSModelRef ,
193+ maas_subscription_namespace : Namespace ,
184194) -> Generator [MaaSSubscription ]:
185- applications_namespace = py_config ["applications_namespace" ]
186195
187196 with MaaSSubscription (
188197 client = admin_client ,
189198 name = "tinyllama-free-subscription" ,
190- namespace = applications_namespace ,
199+ namespace = maas_subscription_namespace . name ,
191200 owner = {
192201 "groups" : [{"name" : maas_free_group }],
193202 },
194203 model_refs = [
195204 {
196205 "name" : maas_model_tinyllama_free .name ,
206+ "namespace" : maas_model_tinyllama_free .namespace ,
197207 "tokenRateLimits" : [{"limit" : 100 , "window" : "1m" }],
198208 }
199209 ],
@@ -210,19 +220,20 @@ def maas_subscription_tinyllama_premium(
210220 admin_client : DynamicClient ,
211221 maas_premium_group : str ,
212222 maas_model_tinyllama_premium : MaaSModelRef ,
223+ maas_subscription_namespace : Namespace ,
213224) -> Generator [MaaSSubscription ]:
214- applications_namespace = py_config ["applications_namespace" ]
215225
216226 with MaaSSubscription (
217227 client = admin_client ,
218228 name = "tinyllama-premium-subscription" ,
219- namespace = applications_namespace ,
229+ namespace = maas_subscription_namespace . name ,
220230 owner = {
221231 "groups" : [{"name" : maas_premium_group }],
222232 },
223233 model_refs = [
224234 {
225235 "name" : maas_model_tinyllama_premium .name ,
236+ "namespace" : maas_model_tinyllama_premium .namespace ,
226237 "tokenRateLimits" : [{"limit" : 1000 , "window" : "1m" }],
227238 }
228239 ],
@@ -321,3 +332,13 @@ def maas_wrong_group_service_account_token(
321332@pytest .fixture (scope = "class" )
322333def maas_headers_for_wrong_group_sa (maas_wrong_group_service_account_token : str ) -> dict :
323334 return build_maas_headers (token = maas_wrong_group_service_account_token )
335+
336+
337+ @pytest .fixture (scope = "session" )
338+ def maas_subscription_namespace (unprivileged_client , admin_client ):
339+ with create_ns (
340+ name = MAAS_SUBSCRIPTION_NAMESPACE ,
341+ unprivileged_client = unprivileged_client ,
342+ admin_client = admin_client ,
343+ ) as ns :
344+ yield ns
0 commit comments