11from tests .model_registry .model_catalog .constants import (
2- CUSTOM_ECOSYSTEM_CATALOG ,
3- CUSTOM_CATALOG_WITH_FILE ,
4- SAMPLE_CATALOG_YAML ,
52 EXPECTED_CUSTOM_CATALOG_VALUES ,
6- EXPECTED_ECHO_CATALOG_VALUES ,
3+ CUSTOM_CATALOG_ID1 ,
4+ SAMPLE_MODEL_NAME1 ,
5+ CUSTOM_CATALOG_ID2 ,
6+ SAMPLE_MODEL_NAME2 ,
7+ MULTIPLE_CUSTOM_CATALOG_VALUES ,
8+ SAMPLE_MODEL_NAME3 ,
79)
810from ocp_resources .config_map import ConfigMap
911import pytest
1012from simple_logger .logger import get_logger
1113from typing import Self
1214
13- from tests .model_registry .model_catalog .utils import execute_get_command
15+ from tests .model_registry .model_catalog .utils import (
16+ execute_get_command ,
17+ get_catalog_str ,
18+ get_sample_yaml_str ,
19+ ResourceNotFoundError ,
20+ )
1421
1522LOGGER = get_logger (name = __name__ )
1623
1724
1825@pytest .mark .parametrize (
1926 "updated_catalog_config_map, expected_catalog_values" ,
2027 [
21- pytest .param ({"sources_yaml" : CUSTOM_ECOSYSTEM_CATALOG }, EXPECTED_ECHO_CATALOG_VALUES , id = "rhec_test_catalog" ),
2228 pytest .param (
23- {"sources_yaml" : CUSTOM_CATALOG_WITH_FILE , "sample_yaml" : SAMPLE_CATALOG_YAML },
29+ {
30+ "sources_yaml" : get_catalog_str (ids = [CUSTOM_CATALOG_ID1 ]),
31+ "sample_yaml" : {"sample-custom-catalog1.yaml" : get_sample_yaml_str (models = [SAMPLE_MODEL_NAME1 ])},
32+ },
2433 EXPECTED_CUSTOM_CATALOG_VALUES ,
2534 id = "file_test_catalog" ,
2635 ),
36+ pytest .param (
37+ {
38+ "sources_yaml" : get_catalog_str (ids = [CUSTOM_CATALOG_ID1 , CUSTOM_CATALOG_ID2 ]),
39+ "sample_yaml" : {
40+ "sample-custom-catalog1.yaml" : get_sample_yaml_str (models = [SAMPLE_MODEL_NAME1 ]),
41+ "sample-custom-catalog2.yaml" : get_sample_yaml_str (models = [SAMPLE_MODEL_NAME2 ]),
42+ },
43+ },
44+ MULTIPLE_CUSTOM_CATALOG_VALUES ,
45+ id = "file_test_catalog" ,
46+ ),
2747 ],
2848 indirect = True ,
2949)
3252 "updated_catalog_config_map" ,
3353)
3454class TestModelCatalogCustom :
35- def test_model_custom_catalog_sources (
55+ def test_model_custom_catalog_list_sources (
3656 self : Self ,
3757 updated_catalog_config_map : tuple [ConfigMap , str , str ],
3858 model_catalog_rest_url : list [str ],
@@ -42,14 +62,19 @@ def test_model_custom_catalog_sources(
4262 """
4363 Validate sources api for model catalog
4464 """
45- result = execute_get_command (
46- url = f"{ model_catalog_rest_url [0 ]} sources" ,
65+ url = f"{ model_catalog_rest_url [0 ]} sources"
66+ results = execute_get_command (
67+ url = url ,
4768 headers = model_registry_rest_headers ,
4869 )["items" ]
49- assert len (result ) == 1
50- assert result [0 ]["id" ] == expected_catalog_values ["id" ]
5170
52- def test_model_custom_catalog_models (
71+ LOGGER .info (f"Results: for uri { url } : { results } " )
72+ assert len (results ) == len (expected_catalog_values )
73+ ids_from_query = [result_entry ["id" ] for result_entry in results ]
74+ ids_expected = [expected_entry ["id" ] for expected_entry in expected_catalog_values ]
75+ assert sorted (ids_from_query ) == sorted (ids_expected ), f"Expected: { expected_catalog_values } . Actual: { results } "
76+
77+ def test_model_custom_catalog_get_models_by_source (
5378 self : Self ,
5479 updated_catalog_config_map : tuple [ConfigMap , str , str ],
5580 model_catalog_rest_url : list [str ],
@@ -59,11 +84,15 @@ def test_model_custom_catalog_models(
5984 """
6085 Validate models api for model catalog associated with a specific source
6186 """
62- result = execute_get_command (
63- url = f"{ model_catalog_rest_url [0 ]} models?source={ expected_catalog_values ['id' ]} " ,
64- headers = model_registry_rest_headers ,
65- )["items" ]
66- assert result , f"Expected custom models to be present. Actual: { result } "
87+ for expected_entry in expected_catalog_values :
88+ LOGGER .info (f"Expected entry: { expected_entry } " )
89+ url = f"{ model_catalog_rest_url [0 ]} models?source={ expected_entry ['id' ]} "
90+ result = execute_get_command (
91+ url = url ,
92+ headers = model_registry_rest_headers ,
93+ )["items" ]
94+ LOGGER .info (f"URL: { url } Result: { result } " )
95+ assert result , f"Expected custom models to be present. Actual: { result } "
6796
6897 def test_model_custom_catalog_get_model_by_name (
6998 self : Self ,
@@ -75,14 +104,18 @@ def test_model_custom_catalog_get_model_by_name(
75104 """
76105 Get Model by name associated with a specific source
77106 """
78- model_name = expected_catalog_values ["model_name" ]
79- result = execute_get_command (
80- url = f"{ model_catalog_rest_url [0 ]} sources/{ expected_catalog_values ['id' ]} /models/{ model_name } " ,
81- headers = model_registry_rest_headers ,
82- )
83- assert result ["name" ] == model_name
107+ for expected_entry in expected_catalog_values :
108+ LOGGER .info (f"Expected entry: { expected_entry } " )
109+ model_name = expected_entry ["model_name" ]
110+ url = f"{ model_catalog_rest_url [0 ]} sources/{ expected_entry ['id' ]} /models/{ model_name } "
111+ result = execute_get_command (
112+ url = url ,
113+ headers = model_registry_rest_headers ,
114+ )
115+ LOGGER .info (f"URL: { url } Result: { result } " )
116+ assert result ["name" ] == model_name
84117
85- def test_model_custom_catalog_get_artifact (
118+ def test_model_custom_catalog_get_model_artifact (
86119 self : Self ,
87120 updated_catalog_config_map : tuple [ConfigMap , str , str ],
88121 model_catalog_rest_url : list [str ],
@@ -92,11 +125,54 @@ def test_model_custom_catalog_get_artifact(
92125 """
93126 Get Model artifacts for model associated with specific source
94127 """
95- model_name = expected_catalog_values ["model_name" ]
96- artifacts = execute_get_command (
97- url = f"{ model_catalog_rest_url [0 ]} sources/{ expected_catalog_values ['id' ]} /models/{ model_name } /artifacts" ,
128+ for expected_entry in expected_catalog_values :
129+ LOGGER .info (f"Expected entry: { expected_entry } " )
130+
131+ model_name = expected_entry ["model_name" ]
132+ url = f"{ model_catalog_rest_url [0 ]} sources/{ expected_entry ['id' ]} /models/{ model_name } /artifacts"
133+
134+ artifacts = execute_get_command (
135+ url = url ,
136+ headers = model_registry_rest_headers ,
137+ )["items" ]
138+ LOGGER .info (f"URL: { url } Result: { artifacts } " )
139+
140+ assert artifacts , f"No artifacts found for { model_name } "
141+ assert artifacts [0 ]["uri" ]
142+
143+ @pytest .mark .dependency (name = "test_model_custom_catalog_add_model" )
144+ def test_model_custom_catalog_add_model (
145+ self : Self ,
146+ model_catalog_rest_url : list [str ],
147+ model_registry_rest_headers : dict [str , str ],
148+ expected_catalog_values : dict [str , str ],
149+ update_configmap_data_add_model : dict [str , str ],
150+ ):
151+ """
152+ Add a model to a source and ensure it is added to the catalog
153+ """
154+ url = f"{ model_catalog_rest_url [0 ]} sources/{ CUSTOM_CATALOG_ID1 } /models/{ SAMPLE_MODEL_NAME3 } "
155+ result = execute_get_command (
156+ url = url ,
98157 headers = model_registry_rest_headers ,
99- )["items" ]
158+ )
159+ LOGGER .info (f"URL: { url } Result: { result } " )
160+ assert result ["name" ] == SAMPLE_MODEL_NAME3
100161
101- assert artifacts , f"No artifacts found for { model_name } "
102- assert artifacts [0 ]["uri" ]
162+ @pytest .mark .dependency (depends = ["test_model_custom_catalog_add_model" ])
163+ def test_model_custom_catalog_remove_model (
164+ self : Self ,
165+ model_catalog_rest_url : list [str ],
166+ model_registry_rest_headers : dict [str , str ],
167+ expected_catalog_values : dict [str , str ],
168+ ):
169+ """
170+ Add a model to a source and ensure it is added to the catalog
171+ """
172+ url = f"{ model_catalog_rest_url [0 ]} sources/{ CUSTOM_CATALOG_ID1 } /models/{ SAMPLE_MODEL_NAME3 } "
173+ with pytest .raises (ResourceNotFoundError ):
174+ result = execute_get_command (
175+ url = url ,
176+ headers = model_registry_rest_headers ,
177+ )
178+ LOGGER .info (f"URL: { url } Result: { result } " )
0 commit comments