1- from collections .abc import Generator
2-
31import pytest
4- import yaml
5- from kubernetes .dynamic import DynamicClient
6- from ocp_resources .config_map import ConfigMap
7- from ocp_resources .resource import ResourceEditor
82from simple_logger .logger import get_logger
93
10- from tests .model_registry .constants import DEFAULT_CUSTOM_MODEL_CATALOG
11- from tests .model_registry .mcp_servers .constants import (
12- MCP_CATALOG_INVALID_SOURCE ,
13- MCP_CATALOG_SOURCE ,
14- MCP_CATALOG_SOURCE2 ,
15- MCP_SERVERS_YAML ,
16- MCP_SERVERS_YAML2 ,
17- )
18- from tests .model_registry .utils import (
19- execute_get_command ,
20- wait_for_mcp_catalog_api ,
21- wait_for_model_catalog_pod_ready_after_deletion ,
22- )
4+ from tests .model_registry .utils import execute_get_command
235
246LOGGER = get_logger (name = __name__ )
257
@@ -34,88 +16,3 @@ def mcp_servers_response(
3416 url = f"{ mcp_catalog_rest_urls [0 ]} mcp_servers" ,
3517 headers = model_registry_rest_headers ,
3618 )
37-
38-
39- @pytest .fixture (scope = "class" )
40- def mcp_multi_source_configmap_patch (
41- admin_client : DynamicClient ,
42- model_registry_namespace : str ,
43- mcp_catalog_rest_urls : list [str ],
44- model_registry_rest_headers : dict [str , str ],
45- ) -> Generator [None ]:
46- """
47- Class-scoped fixture that patches the model-catalog-sources ConfigMap
48- with two MCP catalog sources pointing to two different YAML files.
49- """
50- catalog_config_map = ConfigMap (
51- name = DEFAULT_CUSTOM_MODEL_CATALOG ,
52- client = admin_client ,
53- namespace = model_registry_namespace ,
54- )
55-
56- current_data = yaml .safe_load (catalog_config_map .instance .data .get ("sources.yaml" , "{}" ) or "{}" )
57- if "mcp_catalogs" not in current_data :
58- current_data ["mcp_catalogs" ] = []
59- current_data ["mcp_catalogs" ].extend ([MCP_CATALOG_SOURCE , MCP_CATALOG_SOURCE2 ])
60-
61- patches = {
62- "data" : {
63- "sources.yaml" : yaml .dump (current_data , default_flow_style = False ),
64- "mcp-servers.yaml" : MCP_SERVERS_YAML ,
65- "mcp-servers-2.yaml" : MCP_SERVERS_YAML2 ,
66- }
67- }
68-
69- with ResourceEditor (patches = {catalog_config_map : patches }):
70- wait_for_model_catalog_pod_ready_after_deletion (
71- client = admin_client , model_registry_namespace = model_registry_namespace
72- )
73- wait_for_mcp_catalog_api (url = mcp_catalog_rest_urls [0 ], headers = model_registry_rest_headers )
74- yield
75-
76- wait_for_model_catalog_pod_ready_after_deletion (
77- client = admin_client , model_registry_namespace = model_registry_namespace
78- )
79-
80-
81- @pytest .fixture (scope = "class" )
82- def mcp_invalid_yaml_configmap_patch (
83- request : pytest .FixtureRequest ,
84- admin_client : DynamicClient ,
85- model_registry_namespace : str ,
86- mcp_catalog_rest_urls : list [str ],
87- model_registry_rest_headers : dict [str , str ],
88- ) -> Generator [None ]:
89- """
90- Class-scoped fixture that patches the ConfigMap with a valid MCP source
91- plus an invalid one (parameterized via request.param as the invalid YAML content).
92- """
93- catalog_config_map = ConfigMap (
94- name = DEFAULT_CUSTOM_MODEL_CATALOG ,
95- client = admin_client ,
96- namespace = model_registry_namespace ,
97- )
98-
99- current_data = yaml .safe_load (catalog_config_map .instance .data .get ("sources.yaml" , "{}" ) or "{}" )
100- if "mcp_catalogs" not in current_data :
101- current_data ["mcp_catalogs" ] = []
102- current_data ["mcp_catalogs" ].extend ([MCP_CATALOG_SOURCE , MCP_CATALOG_INVALID_SOURCE ])
103-
104- patches = {
105- "data" : {
106- "sources.yaml" : yaml .dump (current_data , default_flow_style = False ),
107- "mcp-servers.yaml" : MCP_SERVERS_YAML ,
108- "mcp-servers-invalid.yaml" : request .param ,
109- }
110- }
111-
112- with ResourceEditor (patches = {catalog_config_map : patches }):
113- wait_for_model_catalog_pod_ready_after_deletion (
114- client = admin_client , model_registry_namespace = model_registry_namespace
115- )
116- wait_for_mcp_catalog_api (url = mcp_catalog_rest_urls [0 ], headers = model_registry_rest_headers )
117- yield
118-
119- wait_for_model_catalog_pod_ready_after_deletion (
120- client = admin_client , model_registry_namespace = model_registry_namespace
121- )
0 commit comments