|
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 ( |
| 14 | + validate_model_catalog_enabled, |
| 15 | + execute_get_command, |
| 16 | + validate_model_catalog_resource, |
| 17 | + validate_default_catalog, |
| 18 | +) |
11 | 19 |
|
12 | 20 | LOGGER = get_logger(name=__name__) |
13 | 21 |
|
14 | 22 |
|
15 | 23 | @pytest.mark.usefixtures( |
16 | 24 | "updated_dsc_component_state_scope_session", |
17 | 25 | "model_registry_namespace", |
18 | | - "model_registry_metadata_db_resources", |
19 | 26 | ) |
20 | 27 | 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 | | - |
25 | | - @pytest.mark.smoke |
26 | | - def test_config_map_exists(self: Self, model_registry_instance: ModelRegistry, catalog_config_map: ConfigMap): |
27 | | - # Check that the default configmaps is created when model registry is enabled. |
| 28 | + def test_config_map_exists(self: Self, catalog_config_map: ConfigMap): |
| 29 | + # Check that the default configmaps is created when model registry is |
| 30 | + # enabled on data science cluster. |
28 | 31 | assert catalog_config_map.exists, f"{catalog_config_map.name} does not exist" |
29 | | - models = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"] |
30 | | - assert not models, f"Expected no default models to be present. Actual: {models}" |
| 32 | + catalogs = yaml.safe_load(catalog_config_map.instance.data["sources.yaml"])["catalogs"] |
| 33 | + assert catalogs |
| 34 | + assert len(catalogs) == 1, f"{catalog_config_map.name} should have 1 catalog" |
| 35 | + validate_default_catalog(default_catalog=catalogs[0]) |
31 | 36 |
|
32 | | - def test_operator_pod_enabled_model_catalog( |
33 | | - self: Self, model_registry_instance: ModelRegistry, model_registry_operator_pod: Pod |
| 37 | + @pytest.mark.parametrize( |
| 38 | + "resource_name", |
| 39 | + [ |
| 40 | + pytest.param( |
| 41 | + Deployment, |
| 42 | + id="test_model_catalog_deployment_resource", |
| 43 | + ), |
| 44 | + pytest.param( |
| 45 | + Route, |
| 46 | + id="test_model_catalog_route_resource", |
| 47 | + ), |
| 48 | + pytest.param( |
| 49 | + Service, |
| 50 | + id="test_model_catalog_service_resource", |
| 51 | + ), |
| 52 | + pytest.param( |
| 53 | + Pod, |
| 54 | + id="test_model_catalog_pod_resource", |
| 55 | + ), |
| 56 | + ], |
| 57 | + ) |
| 58 | + def test_model_catalog_resources_exists( |
| 59 | + self: Self, admin_client: DynamicClient, model_registry_namespace: str, resource_name: Any |
34 | 60 | ): |
| 61 | + validate_model_catalog_resource( |
| 62 | + kind=resource_name, admin_client=admin_client, namespace=model_registry_namespace |
| 63 | + ) |
| 64 | + |
| 65 | + def test_operator_pod_enabled_model_catalog(self: Self, model_registry_operator_pod: Pod): |
35 | 66 | assert validate_model_catalog_enabled(pod=model_registry_operator_pod) |
36 | 67 |
|
37 | 68 | def test_model_catalog_no_custom_catalog( |
38 | 69 | self, |
39 | | - model_registry_instance: ModelRegistry, |
40 | 70 | model_catalog_rest_url: list[str], |
41 | 71 | model_registry_rest_headers: dict[str, str], |
42 | 72 | ): |
| 73 | + """ |
| 74 | + Validate sources api for model catalog |
| 75 | + """ |
43 | 76 | result = execute_get_command( |
44 | 77 | url=f"{model_catalog_rest_url[0]}sources", |
45 | 78 | headers=model_registry_rest_headers, |
46 | 79 | )["items"] |
47 | | - assert not result, f"Expected no custom models to be present. Actual: {result}" |
| 80 | + assert result |
| 81 | + assert len(result) == 1, f"Expected no custom models to be present. Actual: {result}" |
| 82 | + |
| 83 | + def test_default_config_map_not_present(self: Self, model_registry_namespace: str): |
| 84 | + # RHOAIENG-33246: Introduced a new configmap. It should be removed before 2.25 release |
| 85 | + # This test is temporary. So not parameterizing it. |
| 86 | + cfg_map = ConfigMap(name="default-model-catalog", namespace=model_registry_namespace) |
| 87 | + assert not cfg_map.exists, f"{cfg_map.name} should not exist" |
0 commit comments