forked from opendatahub-io/opendatahub-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_model_registry_rest_api.py
More file actions
327 lines (313 loc) · 11.7 KB
/
test_model_registry_rest_api.py
File metadata and controls
327 lines (313 loc) · 11.7 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
from typing import Self, Any
import pytest
from kubernetes.dynamic import DynamicClient
from ocp_resources.deployment import Deployment
from utilities.resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
from ocp_resources.pod import Pod
from ocp_resources.secret import Secret
from ocp_resources.service import Service
from tests.model_registry.rest_api.constants import (
MODEL_REGISTER,
MODEL_ARTIFACT,
MODEL_VERSION,
MODEL_REGISTER_DATA,
MODEL_ARTIFACT_DESCRIPTION,
MODEL_FORMAT_NAME,
MODEL_FORMAT_VERSION,
MODEL_VERSION_DESCRIPTION,
STATE_ARCHIVED,
STATE_LIVE,
CUSTOM_PROPERTY,
REGISTERED_MODEL_DESCRIPTION,
)
from tests.model_registry.constants import MR_POSTGRES_DB_OBJECT
from tests.model_registry.rest_api.utils import validate_resource_attributes
from simple_logger.logger import get_logger
LOGGER = get_logger(name=__name__)
CONNECTION_STRING: str = "/var/run/postgresql:5432 - accepting connections"
@pytest.mark.parametrize(
"model_registry_metadata_db_resources, model_registry_instance, registered_model_rest_api",
[
pytest.param(
{},
{},
MODEL_REGISTER_DATA,
marks=(pytest.mark.smoke),
),
pytest.param(
{"db_name": "mariadb"},
{"db_name": "mariadb"},
MODEL_REGISTER_DATA,
marks=(pytest.mark.sanity),
),
pytest.param(
{"db_name": "default"},
{"db_name": "default"},
MODEL_REGISTER_DATA,
),
],
indirect=True,
)
@pytest.mark.usefixtures(
"updated_dsc_component_state_scope_session",
"model_registry_namespace",
"model_registry_metadata_db_resources",
"model_registry_instance",
"registered_model_rest_api",
)
@pytest.mark.custom_namespace
class TestModelRegistryCreationRest:
"""
Tests the creation of a model registry. If the component is set to 'Removed' it will be switched to 'Managed'
for the duration of this test module.
"""
@pytest.mark.parametrize(
"expected_params, data_key",
[
pytest.param(
MODEL_REGISTER,
"register_model",
id="test_validate_registered_model",
),
pytest.param(
MODEL_VERSION,
"model_version",
id="test_validate_model_version",
),
pytest.param(
MODEL_ARTIFACT,
"model_artifact",
id="test_validate_model_artifact",
),
],
)
def test_validate_model_registry_resource(
self: Self,
registered_model_rest_api: dict[str, Any],
expected_params: dict[str, str],
data_key: str,
):
validate_resource_attributes(
expected_params=expected_params,
actual_resource_data=registered_model_rest_api[data_key],
resource_name=data_key,
)
@pytest.mark.parametrize(
"kind, resource_name",
[
pytest.param(
Secret,
MR_POSTGRES_DB_OBJECT[Secret],
id="test_secret_default_db_exists",
),
pytest.param(
Deployment,
MR_POSTGRES_DB_OBJECT[Deployment],
id="test_deployment_default_db_exists",
),
pytest.param(
Service,
MR_POSTGRES_DB_OBJECT[Service],
id="test_service_default_db_exists",
),
pytest.param(
PersistentVolumeClaim,
MR_POSTGRES_DB_OBJECT[PersistentVolumeClaim],
id="test_pvc_default_db_exists",
),
],
)
def test_default_postgres_db_resource_exists(
self: Self,
skip_if_not_default_db: None,
kind: Any,
resource_name: str,
model_registry_instance: list[ModelRegistry],
model_registry_namespace: str,
) -> None:
"""
Check resources created for default postgres database
"""
model_registry = model_registry_instance[0]
resource = kind(name=resource_name, namespace=model_registry_namespace)
if not resource.exists:
pytest.fail(f"Resource: {resource_name} is not created, in {model_registry_namespace}")
owner_reference = resource.instance.metadata.ownerReferences
assert owner_reference, f"Owner reference not found for resource: {resource_name}"
assert owner_reference[0].kind == model_registry.kind
assert owner_reference[0].name == model_registry.name
for field in ["controller", "blockOwnerDeletion"]:
assert owner_reference[0][field] is True
def test_default_postgres_db_pod_log(
self: Self,
skip_if_not_default_db: None,
admin_client: DynamicClient,
model_registry_namespace: str,
model_registry_default_postgres_deployment_match_label: dict[str, str],
):
label_selector = ",".join([
f"{k}={v}" for k, v in model_registry_default_postgres_deployment_match_label.items()
])
LOGGER.info(label_selector)
pods = list(Pod.get(dyn_client=admin_client, namespace=model_registry_namespace, label_selector=label_selector))
assert pods, (
"No pods found for default postgres deployment with "
f"label: {model_registry_default_postgres_deployment_match_label}"
)
postgres_pod_log = pods[0].log(container="postgres")
assert CONNECTION_STRING in postgres_pod_log
def test_model_registry_validate_api_version(
self: Self,
model_registry_instance,
):
api_version = ModelRegistry(
name=model_registry_instance[0].name,
namespace=model_registry_instance[0].namespace,
ensure_exists=True,
).instance.apiVersion
LOGGER.info(f"Validating apiversion {api_version} for model registry")
expected_version = f"{ModelRegistry.ApiGroup.MODELREGISTRY_OPENDATAHUB_IO}/{ModelRegistry.ApiVersion.V1BETA1}"
assert api_version == expected_version
def test_model_registry_validate_kuberbacproxy_enabled(
self: Self,
model_registry_instance,
):
model_registry_instance_spec = model_registry_instance[0].instance.spec
LOGGER.info(f"Validating that MR is using kubeRBAC proxy {model_registry_instance_spec}")
assert not model_registry_instance_spec.istio
assert model_registry_instance_spec.kubeRBACProxy.serviceRoute == "enabled"
@pytest.mark.parametrize(
"updated_model_registry_resource, expected_param",
[
pytest.param(
{
"resource_name": "model_artifact",
"api_name": "model_artifacts",
"data": MODEL_ARTIFACT_DESCRIPTION,
},
MODEL_ARTIFACT_DESCRIPTION,
id="test_validate_updated_artifact_description",
),
pytest.param(
{
"resource_name": "model_artifact",
"api_name": "model_artifacts",
"data": MODEL_FORMAT_NAME,
},
MODEL_FORMAT_NAME,
id="test_validate_updated_artifact_model_format_name",
),
pytest.param(
{
"resource_name": "model_artifact",
"api_name": "model_artifacts",
"data": MODEL_FORMAT_VERSION,
},
MODEL_FORMAT_VERSION,
id="test_validate_updated_artifact_model_format_version",
),
],
indirect=["updated_model_registry_resource"],
)
def test_create_update_model_artifact(
self,
updated_model_registry_resource: dict[str, Any],
expected_param: dict[str, Any],
):
"""
Update model artifacts and ensure the updated values are reflected on the artifact
"""
validate_resource_attributes(
expected_params=expected_param,
actual_resource_data=updated_model_registry_resource,
resource_name="model artifact",
)
@pytest.mark.parametrize(
"updated_model_registry_resource, expected_param",
[
pytest.param(
{
"resource_name": "model_version",
"api_name": "model_versions",
"data": MODEL_VERSION_DESCRIPTION,
},
MODEL_VERSION_DESCRIPTION,
id="test_validate_updated_version_description",
),
pytest.param(
{"resource_name": "model_version", "api_name": "model_versions", "data": STATE_ARCHIVED},
STATE_ARCHIVED,
id="test_validate_updated_version_state_archived",
),
pytest.param(
{"resource_name": "model_version", "api_name": "model_versions", "data": STATE_LIVE},
STATE_LIVE,
id="test_validate_updated_version_state_unarchived",
),
pytest.param(
{"resource_name": "model_version", "api_name": "model_versions", "data": CUSTOM_PROPERTY},
CUSTOM_PROPERTY,
id="test_validate_updated_version_custom_properties",
),
],
indirect=["updated_model_registry_resource"],
)
def test_updated_model_version(
self,
updated_model_registry_resource: dict[str, Any],
expected_param: dict[str, Any],
):
"""
Update, [RHOAIENG-24371] archive, unarchive model versions and ensure the updated values
are reflected on the model version
"""
validate_resource_attributes(
expected_params=expected_param,
actual_resource_data=updated_model_registry_resource,
resource_name="model version",
)
@pytest.mark.parametrize(
"updated_model_registry_resource, expected_param",
[
pytest.param(
{
"resource_name": "register_model",
"api_name": "registered_models",
"data": REGISTERED_MODEL_DESCRIPTION,
},
REGISTERED_MODEL_DESCRIPTION,
id="test_validate_updated_model_description",
),
pytest.param(
{"resource_name": "register_model", "api_name": "registered_models", "data": STATE_ARCHIVED},
STATE_ARCHIVED,
id="test_validate_updated_model_state_archived",
),
pytest.param(
{"resource_name": "register_model", "api_name": "registered_models", "data": STATE_LIVE},
STATE_LIVE,
id="test_validate_updated_model_state_unarchived",
),
pytest.param(
{"resource_name": "register_model", "api_name": "registered_models", "data": CUSTOM_PROPERTY},
CUSTOM_PROPERTY,
id="test_validate_updated_registered_model_custom_properties",
),
],
indirect=["updated_model_registry_resource"],
)
def test_updated_registered_model(
self,
updated_model_registry_resource: dict[str, Any],
expected_param: dict[str, Any],
):
"""
Update, [RHOAIENG-24371] archive, unarchive registered models and ensure the updated values
are reflected on the registered model
"""
validate_resource_attributes(
expected_params=expected_param,
actual_resource_data=updated_model_registry_resource,
resource_name="registered model",
)