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
220 lines (197 loc) · 7.66 KB
/
conftest.py
File metadata and controls
220 lines (197 loc) · 7.66 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
from collections.abc import Generator
from typing import Any
from urllib.parse import urlparse
import pytest
from _pytest.fixtures import FixtureRequest
from kubernetes.dynamic import DynamicClient
from ocp_resources.inference_service import InferenceService
from ocp_resources.namespace import Namespace
from ocp_resources.resource import ResourceEditor
from ocp_resources.role import Role
from ocp_resources.role_binding import RoleBinding
from ocp_resources.secret import Secret
from ocp_resources.service_account import ServiceAccount
from ocp_resources.serving_runtime import ServingRuntime
from utilities.constants import (
Annotations,
KServeDeploymentType,
ModelFormat,
ModelName,
Protocols,
RuntimeTemplates,
)
from utilities.inference_utils import create_isvc
from utilities.infra import (
create_inference_token,
create_isvc_view_role,
)
from utilities.logger import RedactedString
from utilities.serving_runtime import ServingRuntimeFromTemplate
# HTTP/REST model serving
@pytest.fixture(scope="class")
def http_raw_view_role(
unprivileged_client: DynamicClient,
http_s3_ovms_raw_inference_service: InferenceService,
) -> Generator[Role, Any, Any]:
with create_isvc_view_role(
client=unprivileged_client,
isvc=http_s3_ovms_raw_inference_service,
name=f"{http_s3_ovms_raw_inference_service.name}-view",
resource_names=[http_s3_ovms_raw_inference_service.name],
) as role:
yield role
@pytest.fixture(scope="class")
def http_raw_role_binding(
unprivileged_client: DynamicClient,
http_raw_view_role: Role,
model_service_account: ServiceAccount,
http_s3_ovms_raw_inference_service: InferenceService,
) -> Generator[RoleBinding, Any, Any]:
with RoleBinding(
client=unprivileged_client,
namespace=model_service_account.namespace,
name=f"{Protocols.HTTP}-{model_service_account.name}-view",
role_ref_name=http_raw_view_role.name,
role_ref_kind=http_raw_view_role.kind,
subjects_kind=model_service_account.kind,
subjects_name=model_service_account.name,
) as rb:
yield rb
@pytest.fixture(scope="class")
def http_raw_inference_token(model_service_account: ServiceAccount, http_raw_role_binding: RoleBinding) -> str:
return RedactedString(value=create_inference_token(model_service_account=model_service_account))
@pytest.fixture()
def patched_remove_raw_authentication_isvc(
unprivileged_client: DynamicClient,
http_s3_ovms_raw_inference_service: InferenceService,
) -> Generator[InferenceService, Any, Any]:
with ResourceEditor(
patches={
http_s3_ovms_raw_inference_service: {
"metadata": {
"annotations": {Annotations.KserveAuth.SECURITY: "false"},
}
}
}
):
yield http_s3_ovms_raw_inference_service
@pytest.fixture(scope="class")
def model_service_account_2(
unprivileged_client: DynamicClient, models_endpoint_s3_secret: Secret
) -> Generator[ServiceAccount, Any, Any]:
with ServiceAccount(
client=unprivileged_client,
namespace=models_endpoint_s3_secret.namespace,
name="models-bucket-sa-2",
secrets=[{"name": models_endpoint_s3_secret.name}],
) as sa:
yield sa
@pytest.fixture(scope="class")
def http_s3_ovms_raw_inference_service(
request: FixtureRequest,
unprivileged_client: DynamicClient,
unprivileged_model_namespace: Namespace,
http_s3_ovms_serving_runtime: ServingRuntime,
ci_s3_bucket_name: str,
ci_endpoint_s3_secret: Secret,
model_service_account: ServiceAccount,
) -> Generator[InferenceService, Any, Any]:
# Construct storage URI from CI bucket
storage_uri = f"s3://{ci_s3_bucket_name}/{request.param['model-dir']}/"
with create_isvc(
client=unprivileged_client,
name=f"{Protocols.HTTP}-{ModelFormat.ONNX}",
namespace=unprivileged_model_namespace.name,
runtime=http_s3_ovms_serving_runtime.name,
storage_key=ci_endpoint_s3_secret.name,
storage_path=urlparse(storage_uri).path,
model_format=http_s3_ovms_serving_runtime.instance.spec.supportedModelFormats[0].name,
deployment_mode=KServeDeploymentType.RAW_DEPLOYMENT,
model_service_account=model_service_account.name,
enable_auth=True,
external_route=True,
) as isvc:
yield isvc
@pytest.fixture(scope="class")
def http_s3_ovms_raw_inference_service_2(
request: FixtureRequest,
unprivileged_client: DynamicClient,
unprivileged_model_namespace: Namespace,
http_s3_ovms_serving_runtime: ServingRuntime,
ci_s3_bucket_name: str,
ci_endpoint_s3_secret: Secret,
model_service_account_2: ServiceAccount,
) -> Generator[InferenceService, Any, Any]:
# Construct storage URI from CI bucket
storage_uri = f"s3://{ci_s3_bucket_name}/{request.param['model-dir']}/"
with create_isvc(
client=unprivileged_client,
name=f"{Protocols.HTTP}-{ModelFormat.ONNX}-2",
namespace=unprivileged_model_namespace.name,
runtime=http_s3_ovms_serving_runtime.name,
storage_key=ci_endpoint_s3_secret.name,
storage_path=urlparse(storage_uri).path,
model_format=http_s3_ovms_serving_runtime.instance.spec.supportedModelFormats[0].name,
deployment_mode=KServeDeploymentType.RAW_DEPLOYMENT,
model_service_account=model_service_account_2.name,
enable_auth=True,
external_route=True,
) as isvc:
yield isvc
@pytest.fixture(scope="class")
def http_s3_ovms_serving_runtime(
request: FixtureRequest,
unprivileged_client: DynamicClient,
unprivileged_model_namespace: Namespace,
) -> Generator[ServingRuntime, Any, Any]:
with ServingRuntimeFromTemplate(
client=unprivileged_client,
name=f"{Protocols.HTTP}-{ModelName.MNIST}-runtime",
namespace=unprivileged_model_namespace.name,
template_name=RuntimeTemplates.OVMS_KSERVE,
multi_model=False,
enable_http=True,
enable_grpc=False,
) as model_runtime:
yield model_runtime
@pytest.fixture(scope="class")
def unprivileged_s3_ovms_raw_inference_service(
request: FixtureRequest,
unprivileged_client: DynamicClient,
unprivileged_model_namespace: Namespace,
http_s3_ovms_serving_runtime: ServingRuntime,
unprivileged_ci_endpoint_s3_secret: Secret,
) -> Generator[InferenceService, Any, Any]:
with create_isvc(
client=unprivileged_client,
name=f"{Protocols.HTTP}-{ModelFormat.ONNX}-raw",
namespace=unprivileged_model_namespace.name,
runtime=http_s3_ovms_serving_runtime.name,
model_format=http_s3_ovms_serving_runtime.instance.spec.supportedModelFormats[0].name,
deployment_mode=KServeDeploymentType.RAW_DEPLOYMENT,
storage_key=unprivileged_ci_endpoint_s3_secret.name,
storage_path=request.param["model-dir"],
) as isvc:
yield isvc
@pytest.fixture(scope="class")
def unprivileged_ci_endpoint_s3_secret(
unprivileged_client: DynamicClient,
unprivileged_model_namespace: Namespace,
aws_access_key_id: str,
aws_secret_access_key: str,
ci_s3_bucket_name: str,
ci_s3_bucket_region: str,
ci_s3_bucket_endpoint: str,
) -> Generator[Secret, Any, Any]:
from utilities.infra import s3_endpoint_secret
with s3_endpoint_secret(
client=unprivileged_client,
name="ci-bucket-unprivileged",
namespace=unprivileged_model_namespace.name,
aws_access_key=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_s3_region=ci_s3_bucket_region,
aws_s3_bucket=ci_s3_bucket_name,
aws_s3_endpoint=ci_s3_bucket_endpoint,
) as secret:
yield secret