|
1 | 1 | import pytest |
2 | 2 | import yaml |
| 3 | +from kubernetes.dynamic import DynamicClient |
3 | 4 |
|
4 | | -from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry |
| 5 | +from ocp_resources.deployment import Deployment |
5 | 6 | from simple_logger.logger import get_logger |
6 | | -from typing import Self |
| 7 | +from typing import Self, Any |
7 | 8 |
|
8 | 9 | from ocp_resources.pod import Pod |
9 | 10 | from ocp_resources.config_map import ConfigMap |
10 | | -from tests.model_registry.model_catalog.utils import validate_model_catalog_enabled, execute_get_command |
| 11 | +from ocp_resources.route import Route |
| 12 | +from ocp_resources.service import Service |
| 13 | +from tests.model_registry.model_catalog.utils import validate_model_catalog_enabled, execute_get_command, \ |
| 14 | + validate_model_catalog_resource, validate_default_catalog |
11 | 15 |
|
12 | 16 | LOGGER = get_logger(name=__name__) |
13 | 17 |
|
14 | 18 |
|
15 | 19 | @pytest.mark.usefixtures( |
16 | 20 | "updated_dsc_component_state_scope_session", |
17 | 21 | "model_registry_namespace", |
18 | | - "model_registry_metadata_db_resources", |
19 | 22 | ) |
20 | 23 | class TestModelCatalog: |
21 | | - def test_config_map_not_created(self: Self, catalog_config_map: ConfigMap): |
22 | | - # Check that the default configmaps does not exist, when model registry is not created |
23 | | - assert not catalog_config_map.exists |
24 | 24 |
|
25 | | - def test_config_map_exists(self: Self, model_registry_instance: ModelRegistry, catalog_config_map: ConfigMap): |
26 | | - # Check that the default configmaps is created when model registry is enabled. |
| 25 | + def test_config_map_exists(self: Self, catalog_config_map: ConfigMap): |
| 26 | + # Check that the default configmaps is created when model registry is |
| 27 | + # enabled on data science cluster. |
27 | 28 | assert catalog_config_map.exists, f"{catalog_config_map.name} does not exist" |
28 | | - models = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"] |
29 | | - assert not models, f"Expected no default models to be present. Actual: {models}" |
| 29 | + catalogs = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"] |
| 30 | + assert catalogs |
| 31 | + assert len(catalogs) == 1, f"{catalog_config_map.name} should have 1 catalog" |
| 32 | + validate_default_catalog(default_catalog=catalogs[0]) |
| 33 | + |
| 34 | + @pytest.mark.parametrize( |
| 35 | + "resource_name", |
| 36 | + [ |
| 37 | + pytest.param( |
| 38 | + Deployment, |
| 39 | + id="test_model_catalog_deployment_resource", |
| 40 | + ), |
| 41 | + pytest.param( |
| 42 | + Route, |
| 43 | + id="test_model_catalog_route_resource", |
| 44 | + ), |
| 45 | + pytest.param( |
| 46 | + Service, |
| 47 | + id="test_model_catalog_service_resource", |
| 48 | + ), |
| 49 | + pytest.param( |
| 50 | + Pod, |
| 51 | + id="test_model_catalog_pod_resource", |
| 52 | + ), |
| 53 | + ], |
| 54 | + ) |
| 55 | + def test_model_catalog_resources_exists(self: Self, admin_client: DynamicClient, model_registry_namespace: str, |
| 56 | + resource_name: Any): |
| 57 | + validate_model_catalog_resource(kind=resource_name, admin_client=admin_client, |
| 58 | + namespace=model_registry_namespace) |
30 | 59 |
|
31 | 60 | def test_operator_pod_enabled_model_catalog( |
32 | | - self: Self, model_registry_instance: ModelRegistry, model_registry_operator_pod: Pod |
| 61 | + self: Self, model_registry_operator_pod: Pod |
33 | 62 | ): |
34 | 63 | assert validate_model_catalog_enabled(pod=model_registry_operator_pod) |
35 | 64 |
|
36 | 65 | def test_model_catalog_no_custom_catalog( |
37 | 66 | self, |
38 | | - model_registry_instance: ModelRegistry, |
39 | 67 | model_catalog_rest_url: list[str], |
40 | 68 | model_registry_rest_headers: dict[str, str], |
41 | 69 | ): |
| 70 | + """ |
| 71 | + Validate sources api for model catalog |
| 72 | + """ |
42 | 73 | result = execute_get_command( |
43 | 74 | url=f"{model_catalog_rest_url[0]}sources", |
44 | 75 | headers=model_registry_rest_headers, |
45 | 76 | )["items"] |
46 | | - assert not result, f"Expected no custom models to be present. Actual: {result}" |
| 77 | + assert result |
| 78 | + assert len(result) == 1, f"Expected no custom models to be present. Actual: {result}" |
0 commit comments