|
1 | 1 | from typing import Generator, Any |
2 | 2 |
|
3 | 3 | import pytest |
4 | | -from _pytest.fixtures import FixtureRequest |
5 | 4 | from kubernetes.dynamic import DynamicClient |
6 | 5 | from ocp_resources.config_map import ConfigMap |
7 | | -from ocp_resources.inference_service import InferenceService |
8 | 6 | from ocp_resources.maria_db import MariaDB |
9 | 7 | from ocp_resources.namespace import Namespace |
10 | | -from ocp_resources.pod import Pod |
11 | | -from ocp_resources.role import Role |
12 | | -from ocp_resources.role_binding import RoleBinding |
13 | 8 | from ocp_resources.secret import Secret |
14 | | -from ocp_resources.service import Service |
15 | | -from ocp_resources.service_account import ServiceAccount |
16 | | -from ocp_resources.serving_runtime import ServingRuntime |
17 | 9 | from ocp_resources.trustyai_service import TrustyAIService |
18 | 10 |
|
19 | 11 |
|
20 | 12 | from tests.model_explainability.trustyai_service.constants import ( |
21 | 13 | TAI_METRICS_CONFIG, |
22 | | - TAI_DATA_CONFIG, |
23 | | - TAI_PVC_STORAGE_CONFIG, |
24 | | - GAUSSIAN_CREDIT_MODEL, |
25 | | - GAUSSIAN_CREDIT_MODEL_STORAGE_PATH, |
26 | | - GAUSSIAN_CREDIT_MODEL_RESOURCES, |
27 | | - KSERVE_MLSERVER, |
28 | | - KSERVE_MLSERVER_CONTAINERS, |
29 | | - KSERVE_MLSERVER_SUPPORTED_MODEL_FORMATS, |
30 | | - KSERVE_MLSERVER_ANNOTATIONS, |
31 | | - XGBOOST, |
32 | 14 | TAI_DB_STORAGE_CONFIG, |
33 | | - ISVC_GETTER, |
34 | 15 | ) |
35 | 16 | from tests.model_explainability.trustyai_service.trustyai_service_utils import ( |
36 | 17 | TRUSTYAI_SERVICE_NAME, |
37 | | - wait_for_isvc_deployment_registered_by_trustyai_service, |
38 | 18 | ) |
39 | 19 | from tests.model_explainability.trustyai_service.utils import ( |
40 | 20 | create_trustyai_service, |
41 | | - create_isvc_getter_service_account, |
42 | | - create_isvc_getter_role, |
43 | | - create_isvc_getter_role_binding, |
44 | | - create_isvc_getter_token_secret, |
45 | 21 | ) |
46 | | -from utilities.constants import KServeDeploymentType, Labels |
47 | | -from utilities.inference_utils import create_isvc |
48 | | -from utilities.infra import create_ns, create_inference_token |
49 | | -from utilities.minio import create_minio_data_connection_secret |
50 | 22 |
|
51 | 23 |
|
52 | 24 | INVALID_TLS_CERTIFICATE: str = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJnRENDQVNlZ0F3SUJBZ0lRRGtTcXVuUWRzRmZwdi8zSm\ |
|
58 | 30 | RmcvTXlNWW9CZUNrUVRWdS9rUkIwK2N2Qy9RMDB4NExvVGpJaQpGdCtKMGc9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0t\ |
59 | 31 | LS0t" # pragma: allowlist secret |
60 | 32 |
|
61 | | - |
62 | | -@pytest.fixture(scope="class") |
63 | | -def model_namespace_2( |
64 | | - request: FixtureRequest, |
65 | | - pytestconfig: pytest.Config, |
66 | | - admin_client: DynamicClient, |
67 | | - teardown_resources: bool, |
68 | | -) -> Generator[Namespace, Any, Any]: |
69 | | - if request.param.get("modelmesh-enabled"): |
70 | | - request.getfixturevalue(argname="enabled_modelmesh_in_dsc") |
71 | | - |
72 | | - if pytestconfig.option.post_upgrade: |
73 | | - ns = Namespace(client=admin_client, name=request.param["name"]) |
74 | | - yield ns |
75 | | - ns.clean_up() |
76 | | - else: |
77 | | - with create_ns( |
78 | | - client=admin_client, |
79 | | - pytest_request=request, |
80 | | - teardown=teardown_resources, |
81 | | - ) as ns: |
82 | | - yield ns |
83 | | - |
84 | | - |
85 | | -@pytest.fixture(scope="class") |
86 | | -def minio_data_connection_2( |
87 | | - request: FixtureRequest, |
88 | | - admin_client: DynamicClient, |
89 | | - model_namespace_2: Namespace, |
90 | | - minio_service: Service, |
91 | | -) -> Generator[Secret, Any, Any]: |
92 | | - with create_minio_data_connection_secret( |
93 | | - minio_service=minio_service, |
94 | | - model_namespace=model_namespace_2.name, |
95 | | - aws_s3_bucket=request.param["bucket"], |
96 | | - client=admin_client, |
97 | | - ) as secret: |
98 | | - yield secret |
99 | | - |
100 | | - |
101 | | -@pytest.fixture(scope="class") |
102 | | -def trustyai_service_with_pvc_storage_2( |
103 | | - pytestconfig: pytest.Config, |
104 | | - admin_client: DynamicClient, |
105 | | - model_namespace_2: Namespace, |
106 | | - cluster_monitoring_config: ConfigMap, |
107 | | - user_workload_monitoring_config: ConfigMap, |
108 | | - teardown_resources: bool, |
109 | | -) -> Generator[TrustyAIService, Any, Any]: |
110 | | - trustyai_service_kwargs = { |
111 | | - "client": admin_client, |
112 | | - "namespace": model_namespace_2.name, |
113 | | - "name": TRUSTYAI_SERVICE_NAME, |
114 | | - } |
115 | | - |
116 | | - if pytestconfig.option.post_upgrade: |
117 | | - trustyai_service = TrustyAIService(**trustyai_service_kwargs) |
118 | | - yield trustyai_service |
119 | | - trustyai_service.clean_up() |
120 | | - |
121 | | - else: |
122 | | - yield from create_trustyai_service( |
123 | | - **trustyai_service_kwargs, |
124 | | - storage=TAI_PVC_STORAGE_CONFIG, |
125 | | - metrics=TAI_METRICS_CONFIG, |
126 | | - data=TAI_DATA_CONFIG, |
127 | | - wait_for_replicas=True, |
128 | | - teardown=teardown_resources, |
129 | | - ) |
130 | | - |
131 | | - |
132 | | -@pytest.fixture(scope="class") |
133 | | -def gaussian_credit_model_2( |
134 | | - pytestconfig: pytest.Config, |
135 | | - admin_client: DynamicClient, |
136 | | - model_namespace_2: Namespace, |
137 | | - minio_pod: Pod, |
138 | | - minio_service: Service, |
139 | | - minio_data_connection_2: Secret, |
140 | | - mlserver_runtime_2: ServingRuntime, |
141 | | - trustyai_service_with_pvc_storage_2: TrustyAIService, |
142 | | - teardown_resources: bool, |
143 | | -) -> Generator[InferenceService, Any, Any]: |
144 | | - gaussian_credit_model_kwargs = { |
145 | | - "client": admin_client, |
146 | | - "namespace": model_namespace_2.name, |
147 | | - "name": GAUSSIAN_CREDIT_MODEL, |
148 | | - } |
149 | | - |
150 | | - if pytestconfig.option.post_upgrade: |
151 | | - isvc = InferenceService(**gaussian_credit_model_kwargs) |
152 | | - yield isvc |
153 | | - isvc.clean_up() |
154 | | - else: |
155 | | - with create_isvc( |
156 | | - deployment_mode=KServeDeploymentType.SERVERLESS, |
157 | | - model_format=XGBOOST, |
158 | | - runtime=mlserver_runtime_2.name, |
159 | | - storage_key=minio_data_connection_2.name, |
160 | | - storage_path=GAUSSIAN_CREDIT_MODEL_STORAGE_PATH, |
161 | | - enable_auth=True, |
162 | | - wait_for_predictor_pods=False, |
163 | | - resources=GAUSSIAN_CREDIT_MODEL_RESOURCES, |
164 | | - teardown=teardown_resources, |
165 | | - **gaussian_credit_model_kwargs, |
166 | | - ) as isvc: |
167 | | - wait_for_isvc_deployment_registered_by_trustyai_service( |
168 | | - client=admin_client, |
169 | | - isvc=isvc, |
170 | | - runtime_name=mlserver_runtime_2.name, |
171 | | - ) |
172 | | - yield isvc |
173 | | - |
174 | | - |
175 | | -@pytest.fixture(scope="class") |
176 | | -def mlserver_runtime_2( |
177 | | - pytestconfig: pytest.Config, |
178 | | - admin_client: DynamicClient, |
179 | | - minio_data_connection: Secret, |
180 | | - model_namespace_2: Namespace, |
181 | | - teardown_resources: bool, |
182 | | -) -> Generator[ServingRuntime, Any, Any]: |
183 | | - mlserver_runtime_kwargs = { |
184 | | - "client": admin_client, |
185 | | - "namespace": model_namespace_2.name, |
186 | | - "name": KSERVE_MLSERVER, |
187 | | - } |
188 | | - |
189 | | - if pytestconfig.option.post_upgrade: |
190 | | - serving_runtime = ServingRuntime(**mlserver_runtime_kwargs) |
191 | | - yield serving_runtime |
192 | | - serving_runtime.clean_up() |
193 | | - else: |
194 | | - with ServingRuntime( |
195 | | - containers=KSERVE_MLSERVER_CONTAINERS, |
196 | | - supported_model_formats=KSERVE_MLSERVER_SUPPORTED_MODEL_FORMATS, |
197 | | - protocol_versions=["v2"], |
198 | | - annotations=KSERVE_MLSERVER_ANNOTATIONS, |
199 | | - label={Labels.OpenDataHub.DASHBOARD: "true"}, |
200 | | - teardown=teardown_resources, |
201 | | - **mlserver_runtime_kwargs, |
202 | | - ) as mlserver: |
203 | | - yield mlserver |
204 | | - |
205 | | - |
206 | 33 | @pytest.fixture(scope="class") |
207 | 34 | def trustyai_service_with_invalid_db_cert( |
208 | 35 | admin_client: DynamicClient, |
@@ -237,50 +64,3 @@ def trustyai_invalid_db_ca_secret( |
237 | 64 | ) as secret: |
238 | 65 | yield secret |
239 | 66 |
|
240 | | - |
241 | | -@pytest.fixture(scope="class") |
242 | | -def isvc_getter_service_account_2( |
243 | | - admin_client: DynamicClient, model_namespace_2: Namespace |
244 | | -) -> Generator[ServiceAccount, Any, Any]: |
245 | | - yield from create_isvc_getter_service_account(client=admin_client, namespace=model_namespace_2, name=ISVC_GETTER) |
246 | | - |
247 | | - |
248 | | -@pytest.fixture(scope="class") |
249 | | -def isvc_getter_role_2(admin_client: DynamicClient, model_namespace_2: Namespace) -> Generator[Role, Any, Any]: |
250 | | - yield from create_isvc_getter_role(client=admin_client, namespace=model_namespace_2, name=ISVC_GETTER) |
251 | | - |
252 | | - |
253 | | -@pytest.fixture(scope="class") |
254 | | -def isvc_getter_role_binding_2( |
255 | | - admin_client: DynamicClient, |
256 | | - model_namespace_2: Namespace, |
257 | | - isvc_getter_role_2: Role, |
258 | | - isvc_getter_service_account_2: ServiceAccount, |
259 | | -) -> Generator[RoleBinding, Any, Any]: |
260 | | - yield from create_isvc_getter_role_binding( |
261 | | - client=admin_client, |
262 | | - namespace=model_namespace_2, |
263 | | - role=isvc_getter_role_2, |
264 | | - service_account=isvc_getter_service_account_2, |
265 | | - name=ISVC_GETTER, |
266 | | - ) |
267 | | - |
268 | | - |
269 | | -@pytest.fixture(scope="class") |
270 | | -def isvc_getter_token_secret_2( |
271 | | - admin_client: DynamicClient, |
272 | | - model_namespace_2: Namespace, |
273 | | - isvc_getter_service_account_2: ServiceAccount, |
274 | | - isvc_getter_role_binding_2: RoleBinding, |
275 | | -) -> Generator[Secret, Any, Any]: |
276 | | - yield from create_isvc_getter_token_secret( |
277 | | - client=admin_client, |
278 | | - name="sa-token", |
279 | | - namespace=model_namespace_2, |
280 | | - service_account=isvc_getter_service_account_2, |
281 | | - ) |
282 | | - |
283 | | - |
284 | | -@pytest.fixture(scope="class") |
285 | | -def isvc_getter_token_2(isvc_getter_service_account_2: ServiceAccount, isvc_getter_token_secret_2: Secret) -> str: |
286 | | - return create_inference_token(model_service_account=isvc_getter_service_account_2) |
0 commit comments