|
12 | 12 | MCP_CATALOG_INVALID_SOURCE, |
13 | 13 | MCP_CATALOG_SOURCE, |
14 | 14 | MCP_CATALOG_SOURCE2, |
| 15 | + MCP_CATALOG_SOURCE_ID, |
| 16 | + MCP_CATALOG_SOURCE_NAME, |
15 | 17 | MCP_SERVERS_YAML, |
16 | 18 | MCP_SERVERS_YAML2, |
| 19 | + MCP_SERVERS_YAML_CATALOG_PATH, |
17 | 20 | ) |
18 | 21 | from tests.model_registry.utils import ( |
19 | 22 | wait_for_mcp_catalog_api, |
@@ -106,3 +109,64 @@ def mcp_invalid_yaml_configmap_patch( |
106 | 109 | wait_for_model_catalog_pod_ready_after_deletion( |
107 | 110 | client=admin_client, model_registry_namespace=model_registry_namespace |
108 | 111 | ) |
| 112 | + |
| 113 | + |
| 114 | +@pytest.fixture(scope="class") |
| 115 | +def mcp_included_excluded_configmap_patch( |
| 116 | + request: pytest.FixtureRequest, |
| 117 | + admin_client: DynamicClient, |
| 118 | + model_registry_namespace: str, |
| 119 | + mcp_catalog_rest_urls: list[str], |
| 120 | + model_registry_rest_headers: dict[str, str], |
| 121 | +) -> Generator[None]: |
| 122 | + """ |
| 123 | + Class-scoped fixture that patches the ConfigMap with an MCP source |
| 124 | + including includedServers/excludedServers filters. |
| 125 | +
|
| 126 | + Parametrized via request.param with a dict containing: |
| 127 | + - "includedServers": list[str] (optional) |
| 128 | + - "excludedServers": list[str] (optional) |
| 129 | + """ |
| 130 | + filter_params = request.param |
| 131 | + |
| 132 | + source_config: dict = { |
| 133 | + "name": MCP_CATALOG_SOURCE_NAME, |
| 134 | + "id": MCP_CATALOG_SOURCE_ID, |
| 135 | + "type": "yaml", |
| 136 | + "enabled": True, |
| 137 | + "properties": {"yamlCatalogPath": MCP_SERVERS_YAML_CATALOG_PATH}, |
| 138 | + "labels": [MCP_CATALOG_SOURCE_NAME], |
| 139 | + } |
| 140 | + if "includedServers" in filter_params: |
| 141 | + source_config["includedServers"] = filter_params["includedServers"] |
| 142 | + if "excludedServers" in filter_params: |
| 143 | + source_config["excludedServers"] = filter_params["excludedServers"] |
| 144 | + |
| 145 | + catalog_config_map = ConfigMap( |
| 146 | + name=DEFAULT_CUSTOM_MODEL_CATALOG, |
| 147 | + client=admin_client, |
| 148 | + namespace=model_registry_namespace, |
| 149 | + ) |
| 150 | + |
| 151 | + current_data = yaml.safe_load(catalog_config_map.instance.data.get("sources.yaml", "{}") or "{}") |
| 152 | + if "mcp_catalogs" not in current_data: |
| 153 | + current_data["mcp_catalogs"] = [] |
| 154 | + current_data["mcp_catalogs"].append(source_config) |
| 155 | + |
| 156 | + patches = { |
| 157 | + "data": { |
| 158 | + "sources.yaml": yaml.dump(current_data, default_flow_style=False), |
| 159 | + "mcp-servers.yaml": MCP_SERVERS_YAML, |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + with ResourceEditor(patches={catalog_config_map: patches}): |
| 164 | + wait_for_model_catalog_pod_ready_after_deletion( |
| 165 | + client=admin_client, model_registry_namespace=model_registry_namespace |
| 166 | + ) |
| 167 | + wait_for_mcp_catalog_api(url=mcp_catalog_rest_urls[0], headers=model_registry_rest_headers) |
| 168 | + yield |
| 169 | + |
| 170 | + wait_for_model_catalog_pod_ready_after_deletion( |
| 171 | + client=admin_client, model_registry_namespace=model_registry_namespace |
| 172 | + ) |
0 commit comments