|
7 | 7 | from ocp_resources.cluster_service_version import ClusterServiceVersion |
8 | 8 | from ocp_resources.config_map import ConfigMap |
9 | 9 | from ocp_resources.deployment import Deployment |
| 10 | +from ocp_resources.inference_service import InferenceService |
10 | 11 | from ocp_resources.maria_db import MariaDB |
11 | 12 | from ocp_resources.mariadb_operator import MariadbOperator |
12 | 13 | from ocp_resources.namespace import Namespace |
| 14 | +from ocp_resources.pod import Pod |
13 | 15 | from ocp_resources.secret import Secret |
| 16 | +from ocp_resources.service import Service |
| 17 | +from ocp_resources.serving_runtime import ServingRuntime |
14 | 18 | from ocp_resources.subscription import Subscription |
15 | 19 | from ocp_resources.trustyai_service import TrustyAIService |
16 | 20 | from ocp_utilities.operators import install_operator, uninstall_operator |
17 | 21 |
|
18 | | -from tests.model_explainability.trustyai_service.trustyai_service_utils import TRUSTYAI_SERVICE_NAME |
| 22 | +from tests.model_explainability.trustyai_service.trustyai_service_utils import ( |
| 23 | + TRUSTYAI_SERVICE_NAME, |
| 24 | + wait_for_isvc_deployment_registered_by_trustyai_service, |
| 25 | +) |
19 | 26 | from tests.model_explainability.trustyai_service.utils import ( |
20 | 27 | get_cluster_service_version, |
21 | 28 | wait_for_mariadb_operator_deployments, |
22 | 29 | wait_for_mariadb_pods, |
23 | 30 | ) |
24 | 31 |
|
25 | | -from utilities.constants import Timeout |
| 32 | +from utilities.constants import Timeout, KServeDeploymentType, ApiGroups, Labels, Ports |
| 33 | +from utilities.inference_utils import create_isvc |
26 | 34 | from utilities.infra import update_configmap_data |
27 | 35 |
|
28 | 36 | OPENSHIFT_OPERATORS: str = "openshift-operators" |
|
32 | 40 | DB_NAME: str = "trustyai_db" |
33 | 41 | DB_USERNAME: str = "trustyai_user" |
34 | 42 | DB_PASSWORD: str = "trustyai_password" |
| 43 | +MLSERVER: str = "mlserver" |
| 44 | +MLSERVER_RUNTIME_NAME: str = f"{MLSERVER}-1.x" |
| 45 | +XGBOOST: str = "xgboost" |
| 46 | +SKLEARN: str = "sklearn" |
| 47 | +LIGHTGBM: str = "lightgbm" |
| 48 | +MLFLOW: str = "mlflow" |
| 49 | +TIMEOUT_20MIN: int = 20 * Timeout.TIMEOUT_1MIN |
35 | 50 |
|
36 | 51 |
|
37 | 52 | @pytest.fixture(scope="class") |
38 | 53 | def trustyai_service_with_pvc_storage( |
| 54 | + pytestconfig: pytest.Config, |
39 | 55 | admin_client: DynamicClient, |
40 | 56 | model_namespace: Namespace, |
41 | 57 | cluster_monitoring_config: ConfigMap, |
42 | 58 | user_workload_monitoring_config: ConfigMap, |
| 59 | + teardown_resources: bool, |
43 | 60 | ) -> Generator[TrustyAIService, Any, Any]: |
44 | | - with TrustyAIService( |
45 | | - client=admin_client, |
46 | | - name=TRUSTYAI_SERVICE_NAME, |
47 | | - namespace=model_namespace.name, |
48 | | - storage={"format": "PVC", "folder": "/inputs", "size": "1Gi"}, |
49 | | - data={"filename": "data.csv", "format": "CSV"}, |
50 | | - metrics={"schedule": "5s"}, |
51 | | - ) as trustyai_service: |
52 | | - trustyai_deployment = Deployment( |
53 | | - namespace=model_namespace.name, name=TRUSTYAI_SERVICE_NAME, wait_for_resource=True |
54 | | - ) |
55 | | - trustyai_deployment.wait_for_replicas() |
| 61 | + trustyai_service_kwargs = {"client": admin_client, "namespace": model_namespace.name, "name": TRUSTYAI_SERVICE_NAME} |
| 62 | + trustyai_service = TrustyAIService(**trustyai_service_kwargs) |
| 63 | + |
| 64 | + if pytestconfig.option.post_upgrade: |
56 | 65 | yield trustyai_service |
| 66 | + trustyai_service.clean_up() |
| 67 | + |
| 68 | + else: |
| 69 | + with TrustyAIService( |
| 70 | + **trustyai_service_kwargs, |
| 71 | + storage={"format": "PVC", "folder": "/inputs", "size": "1Gi"}, |
| 72 | + data={"filename": "data.csv", "format": "CSV"}, |
| 73 | + metrics={"schedule": "5s"}, |
| 74 | + teardown=teardown_resources, |
| 75 | + ) as trustyai_service: |
| 76 | + trustyai_deployment = Deployment( |
| 77 | + namespace=model_namespace.name, name=TRUSTYAI_SERVICE_NAME, wait_for_resource=True |
| 78 | + ) |
| 79 | + trustyai_deployment.wait_for_replicas() |
| 80 | + yield trustyai_service |
57 | 81 |
|
58 | 82 |
|
59 | 83 | @pytest.fixture(scope="class") |
@@ -216,3 +240,110 @@ def trustyai_db_ca_secret( |
216 | 240 | data_dict={"ca.crt": mariadb_ca_secret.instance.data["ca.crt"]}, |
217 | 241 | ): |
218 | 242 | yield |
| 243 | + |
| 244 | + |
| 245 | +@pytest.fixture(scope="class") |
| 246 | +def mlserver_runtime( |
| 247 | + pytestconfig: pytest.Config, |
| 248 | + admin_client: DynamicClient, |
| 249 | + minio_data_connection: Secret, |
| 250 | + model_namespace: Namespace, |
| 251 | + teardown_resources: bool, |
| 252 | +) -> Generator[ServingRuntime, Any, Any]: |
| 253 | + mlserver_runtime_kwargs = { |
| 254 | + "client": admin_client, |
| 255 | + "namespace": model_namespace.name, |
| 256 | + "name": "kserve-mlserver", |
| 257 | + } |
| 258 | + |
| 259 | + serving_runtime = ServingRuntime(**mlserver_runtime_kwargs) |
| 260 | + |
| 261 | + if pytestconfig.option.post_upgrade: |
| 262 | + yield serving_runtime |
| 263 | + serving_runtime.clean_up() |
| 264 | + |
| 265 | + supported_model_formats = [ |
| 266 | + {"name": SKLEARN, "version": "0", "autoSelect": True, "priority": 2}, |
| 267 | + {"name": SKLEARN, "version": "1", "autoSelect": True, "priority": 2}, |
| 268 | + {"name": XGBOOST, "version": "1", "autoSelect": True, "priority": 2}, |
| 269 | + {"name": XGBOOST, "version": "2", "autoSelect": True, "priority": 2}, |
| 270 | + {"name": LIGHTGBM, "version": "3", "autoSelect": True, "priority": 2}, |
| 271 | + {"name": LIGHTGBM, "version": "4", "autoSelect": True, "priority": 2}, |
| 272 | + {"name": MLFLOW, "version": "1", "autoSelect": True, "priority": 1}, |
| 273 | + {"name": MLFLOW, "version": "2", "autoSelect": True, "priority": 1}, |
| 274 | + ] |
| 275 | + containers = [ |
| 276 | + { |
| 277 | + "name": "kserve-container", |
| 278 | + "image": "quay.io/trustyai_testing/mlserver" |
| 279 | + "@sha256:68a4cd74fff40a3c4f29caddbdbdc9e54888aba54bf3c5f78c8ffd577c3a1c89", |
| 280 | + "env": [ |
| 281 | + {"name": "MLSERVER_MODEL_IMPLEMENTATION", "value": "{{.Labels.modelClass}}"}, |
| 282 | + {"name": "MLSERVER_HTTP_PORT", "value": str(Ports.REST_PORT)}, |
| 283 | + {"name": "MLSERVER_GRPC_PORT", "value": "9000"}, |
| 284 | + {"name": "MODELS_DIR", "value": "/mnt/models/"}, |
| 285 | + ], |
| 286 | + "resources": {"requests": {"cpu": "1", "memory": "2Gi"}, "limits": {"cpu": "1", "memory": "2Gi"}}, |
| 287 | + } |
| 288 | + ] |
| 289 | + |
| 290 | + with ServingRuntime( |
| 291 | + containers=containers, |
| 292 | + supported_model_formats=supported_model_formats, |
| 293 | + protocol_versions=["v2"], |
| 294 | + annotations={ |
| 295 | + f"{ApiGroups.OPENDATAHUB_IO}/accelerator-name": "", |
| 296 | + f"{ApiGroups.OPENDATAHUB_IO}/template-display-name": "KServe MLServer", |
| 297 | + "prometheus.kserve.io/path": "/metrics", |
| 298 | + "prometheus.io/port": str(Ports.REST_PORT), |
| 299 | + "openshift.io/display-name": "mlserver-1.x", |
| 300 | + }, |
| 301 | + label={Labels.OpenDataHub.DASHBOARD: "true"}, |
| 302 | + teardown=teardown_resources, |
| 303 | + **mlserver_runtime_kwargs, |
| 304 | + ) as mlserver: |
| 305 | + yield mlserver |
| 306 | + |
| 307 | + |
| 308 | +@pytest.fixture(scope="class") |
| 309 | +def gaussian_credit_model( |
| 310 | + pytestconfig: pytest.Config, |
| 311 | + admin_client: DynamicClient, |
| 312 | + model_namespace: Namespace, |
| 313 | + minio_pod: Pod, |
| 314 | + minio_service: Service, |
| 315 | + minio_data_connection: Secret, |
| 316 | + mlserver_runtime: ServingRuntime, |
| 317 | + trustyai_service_with_pvc_storage: TrustyAIService, |
| 318 | + teardown_resources: bool, |
| 319 | +) -> Generator[InferenceService, Any, Any]: |
| 320 | + gaussian_credit_model_kwargs = { |
| 321 | + "client": admin_client, |
| 322 | + "namespace": model_namespace.name, |
| 323 | + "name": "gaussian-credit-model", |
| 324 | + } |
| 325 | + |
| 326 | + isvc = InferenceService(**gaussian_credit_model_kwargs) |
| 327 | + |
| 328 | + if pytestconfig.option.post_upgrade: |
| 329 | + yield isvc |
| 330 | + isvc.clean_up() |
| 331 | + else: |
| 332 | + with create_isvc( |
| 333 | + deployment_mode=KServeDeploymentType.SERVERLESS, |
| 334 | + model_format=XGBOOST, |
| 335 | + runtime=mlserver_runtime.name, |
| 336 | + storage_key=minio_data_connection.name, |
| 337 | + storage_path="sklearn/gaussian_credit_model/1", |
| 338 | + enable_auth=True, |
| 339 | + wait_for_predictor_pods=False, |
| 340 | + resources={"requests": {"cpu": "1", "memory": "2Gi"}, "limits": {"cpu": "1", "memory": "2Gi"}}, |
| 341 | + teardown=teardown_resources, |
| 342 | + **gaussian_credit_model_kwargs, |
| 343 | + ) as isvc: |
| 344 | + wait_for_isvc_deployment_registered_by_trustyai_service( |
| 345 | + client=admin_client, |
| 346 | + isvc=isvc, |
| 347 | + runtime_name=mlserver_runtime.name, |
| 348 | + ) |
| 349 | + yield isvc |
0 commit comments