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