11import pytest
22import random
3+
4+ import yaml
35from kubernetes .dynamic import DynamicClient
46from dictdiffer import diff
57from ocp_resources .deployment import Deployment
1012from ocp_resources .config_map import ConfigMap
1113from ocp_resources .route import Route
1214from ocp_resources .service import Service
15+
1316from tests .model_registry .constants import DEFAULT_CUSTOM_MODEL_CATALOG , DEFAULT_MODEL_CATALOG_CM
14- from tests .model_registry .model_catalog .constants import REDHAT_AI_CATALOG_ID , CATALOG_CONTAINER
17+ from tests .model_registry .model_catalog .constants import REDHAT_AI_CATALOG_ID , CATALOG_CONTAINER , DEFAULT_CATALOGS
1518from tests .model_registry .model_catalog .utils import (
1619 validate_model_catalog_enabled ,
17- execute_get_command ,
1820 validate_model_catalog_resource ,
1921 get_validate_default_model_catalog_source ,
2022 extract_schema_fields ,
21- get_model_catalog_pod ,
22- validate_model_catalog_configmap_data ,
23+ validate_default_catalog ,
2324)
24- from tests .model_registry .utils import get_rest_headers
25+ from tests .model_registry .utils import get_rest_headers , get_model_catalog_pod , execute_get_command
2526from utilities .user_utils import UserTestSession
2627
2728LOGGER = get_logger (name = __name__ )
3637@pytest .mark .skip_must_gather
3738class TestModelCatalogGeneral :
3839 @pytest .mark .parametrize (
39- "model_catalog_config_map, expected_catalogs" ,
40+ "model_catalog_config_map, expected_catalogs, validate_catalog " ,
4041 [
4142 pytest .param (
4243 {"configmap_name" : DEFAULT_CUSTOM_MODEL_CATALOG },
4344 0 ,
44- id = "test_model_catalog_sources_configmap" ,
45+ False ,
46+ id = "test_model_catalog_sources_configmap_install" ,
47+ marks = pytest .mark .install ,
48+ ),
49+ pytest .param (
50+ {"configmap_name" : DEFAULT_CUSTOM_MODEL_CATALOG },
51+ 1 ,
52+ False ,
53+ id = "test_model_catalog_sources_configmap_upgrade" ,
54+ marks = (pytest .mark .pre_upgrade , pytest .mark .post_upgrade ),
4555 ),
4656 pytest .param (
4757 {"configmap_name" : DEFAULT_MODEL_CATALOG_CM },
4858 2 ,
59+ True ,
4960 id = "test_model_catalog_default_sources_configmap" ,
5061 ),
5162 ],
5263 indirect = ["model_catalog_config_map" ],
5364 )
54- def test_config_map_exists (self : Self , model_catalog_config_map : ConfigMap , expected_catalogs : int ):
55- validate_model_catalog_configmap_data (configmap = model_catalog_config_map , num_catalogs = expected_catalogs )
65+ def test_config_map_exists (
66+ self : Self , model_catalog_config_map : ConfigMap , expected_catalogs : int , validate_catalog : bool
67+ ) -> None :
68+ assert model_catalog_config_map .exists , f"{ model_catalog_config_map .name } does not exist"
69+ catalogs = yaml .safe_load (model_catalog_config_map .instance .data ["sources.yaml" ])["catalogs" ]
70+ assert len (catalogs ) == expected_catalogs , (
71+ f"{ model_catalog_config_map .name } should have { expected_catalogs } catalog"
72+ )
73+ if validate_catalog :
74+ validate_default_catalog (catalogs = catalogs )
5675
5776 @pytest .mark .parametrize (
5877 "resource_name, expected_resource_count" ,
@@ -80,6 +99,7 @@ def test_config_map_exists(self: Self, model_catalog_config_map: ConfigMap, expe
8099 ],
81100 )
82101 @pytest .mark .post_upgrade
102+ @pytest .mark .pre_upgrade
83103 @pytest .mark .install
84104 def test_model_catalog_resources_exists (
85105 self : Self ,
@@ -95,9 +115,15 @@ def test_model_catalog_resources_exists(
95115 expected_resource_count = expected_resource_count ,
96116 )
97117
118+ @pytest .mark .post_upgrade
119+ @pytest .mark .pre_upgrade
120+ @pytest .mark .install
98121 def test_operator_pod_enabled_model_catalog (self : Self , model_registry_operator_pod : Pod ):
99122 assert validate_model_catalog_enabled (pod = model_registry_operator_pod )
100123
124+ @pytest .mark .post_upgrade
125+ @pytest .mark .pre_upgrade
126+ @pytest .mark .install
101127 def test_model_catalog_uses_postgres (self : Self , admin_client : DynamicClient , model_registry_namespace : str ):
102128 """
103129 Validate that model catalog pod is using PostgreSQL database
@@ -119,6 +145,7 @@ def test_model_catalog_uses_postgres(self: Self, admin_client: DynamicClient, mo
119145 pytest .param (
120146 {},
121147 id = "test_model_catalog_source_admin_user" ,
148+ marks = (pytest .mark .pre_upgrade , pytest .mark .post_upgrade , pytest .mark .install ),
122149 ),
123150 pytest .param (
124151 {"user_type" : "test" },
@@ -134,16 +161,29 @@ def test_model_catalog_uses_postgres(self: Self, admin_client: DynamicClient, mo
134161class TestModelCatalogDefault :
135162 def test_model_catalog_default_catalog_sources (
136163 self ,
164+ pytestconfig : pytest .Config ,
137165 test_idp_user : UserTestSession ,
138166 model_catalog_rest_url : list [str ],
139167 user_token_for_api_calls : str ,
140168 ):
141169 """
142170 Validate specific user can access default model catalog source
143171 """
144- get_validate_default_model_catalog_source (
145- token = user_token_for_api_calls , model_catalog_url = f"{ model_catalog_rest_url [0 ]} sources"
146- )
172+ LOGGER .info ("Attempting client connection with token" )
173+ result = execute_get_command (
174+ url = f"{ model_catalog_rest_url [0 ]} sources" ,
175+ headers = get_rest_headers (token = user_token_for_api_calls ),
176+ )["items" ]
177+ assert result
178+ items_to_validate = []
179+ if pytestconfig .option .pre_upgrade or pytestconfig .option .post_upgrade :
180+ for catalog in result :
181+ if catalog ["id" ] in DEFAULT_CATALOGS .keys ():
182+ items_to_validate .append (catalog )
183+ assert len (items_to_validate ) + 1 == len (result )
184+ else :
185+ items_to_validate = result
186+ get_validate_default_model_catalog_source (catalogs = items_to_validate )
147187
148188 def test_model_default_catalog_get_models_by_source (
149189 self : Self ,
@@ -191,6 +231,9 @@ def test_model_default_catalog_get_model_artifact(
191231 assert result [0 ]["uri" ]
192232
193233
234+ @pytest .mark .post_upgrade
235+ @pytest .mark .pre_upgrade
236+ @pytest .mark .install
194237@pytest .mark .skip_must_gather
195238class TestModelCatalogDefaultData :
196239 """Test class for validating default catalog data (not user-specific)"""
0 commit comments