|
| 1 | +import pytest |
| 2 | + |
| 3 | +from ocp_resources.config_map import ConfigMap |
| 4 | +from simple_logger.logger import get_logger |
| 5 | + |
| 6 | +from tests.model_registry.utils import execute_get_command |
| 7 | +from tests.model_registry.model_catalog.metadata.utils import validate_source_status |
| 8 | + |
| 9 | +pytestmark = [pytest.mark.usefixtures("updated_dsc_component_state_scope_session", "model_registry_namespace")] |
| 10 | + |
| 11 | +LOGGER = get_logger(name=__name__) |
| 12 | + |
| 13 | + |
| 14 | +class TestSourcesEndpoint: |
| 15 | + """Test class for the model catalog sources endpoint.""" |
| 16 | + |
| 17 | + @pytest.mark.smoke |
| 18 | + def test_available_source_status( |
| 19 | + self, |
| 20 | + enabled_model_catalog_config_map: ConfigMap, |
| 21 | + model_catalog_rest_url: list[str], |
| 22 | + model_registry_rest_headers: dict[str, str], |
| 23 | + ): |
| 24 | + """ |
| 25 | + RHOAIENG-41849: Test that the sources endpoint returns no error for available sources. |
| 26 | + """ |
| 27 | + response = execute_get_command(url=f"{model_catalog_rest_url[0]}sources", headers=model_registry_rest_headers) |
| 28 | + items = response.get("items", []) |
| 29 | + assert items, "Sources not found" |
| 30 | + for item in items: |
| 31 | + validate_source_status(catalog=item, expected_status="available") |
| 32 | + error_value = item["error"] |
| 33 | + assert error_value is None or error_value == "", ( |
| 34 | + f"Source '{item.get('id')}' should not have error, got: {error_value}" |
| 35 | + ) |
| 36 | + |
| 37 | + LOGGER.info( |
| 38 | + f"Available catalog verified - ID: {item.get('id')}, Status: {item.get('status')}, Error: {error_value}" |
| 39 | + ) |
| 40 | + |
| 41 | + @pytest.mark.parametrize("disabled_catalog_source", ["redhat_ai_models"], indirect=True) |
| 42 | + def test_disabled_source_status( |
| 43 | + self, |
| 44 | + enabled_model_catalog_config_map: ConfigMap, |
| 45 | + disabled_catalog_source: str, |
| 46 | + model_catalog_rest_url: list[str], |
| 47 | + model_registry_rest_headers: dict[str, str], |
| 48 | + ): |
| 49 | + """ |
| 50 | + RHOAIENG-41849: |
| 51 | + This test disables an existing catalog and verifies: |
| 52 | + - status field is "disabled" |
| 53 | + - error field is null or empty |
| 54 | + """ |
| 55 | + catalog_id = disabled_catalog_source |
| 56 | + |
| 57 | + response = execute_get_command(url=f"{model_catalog_rest_url[0]}sources", headers=model_registry_rest_headers) |
| 58 | + items = response.get("items", []) |
| 59 | + |
| 60 | + # Find the disabled catalog |
| 61 | + disabled_catalog = next((item for item in items if item.get("id") == catalog_id), None) |
| 62 | + assert disabled_catalog is not None, f"Disabled catalog '{catalog_id}' not found in sources" |
| 63 | + |
| 64 | + # Validate status and error fields |
| 65 | + validate_source_status(catalog=disabled_catalog, expected_status="disabled") |
| 66 | + error_value = disabled_catalog["error"] |
| 67 | + assert error_value is None or error_value == "", ( |
| 68 | + f"Source '{disabled_catalog.get('id')}' should not have error, got: {error_value}" |
| 69 | + ) |
| 70 | + |
| 71 | + LOGGER.info( |
| 72 | + "Disabled catalog verified - " |
| 73 | + f"ID: {disabled_catalog.get('id')}, " |
| 74 | + f"Status: {disabled_catalog.get('status')}, " |
| 75 | + f"Error: {error_value}" |
| 76 | + ) |
| 77 | + |
| 78 | + @pytest.mark.parametrize("disabled_catalog_source", ["redhat_ai_models"], indirect=True) |
| 79 | + @pytest.mark.sanity |
| 80 | + def test_sources_endpoint_returns_all_sources_regardless_of_enabled_field( |
| 81 | + self, |
| 82 | + enabled_model_catalog_config_map: ConfigMap, |
| 83 | + disabled_catalog_source: str, |
| 84 | + model_catalog_rest_url: list[str], |
| 85 | + model_registry_rest_headers: dict[str, str], |
| 86 | + ): |
| 87 | + """ |
| 88 | + RHOAIENG-41633: Test that sources endpoint returns ALL sources regardless of enabled field value. |
| 89 | + """ |
| 90 | + response = execute_get_command(url=f"{model_catalog_rest_url[0]}sources", headers=model_registry_rest_headers) |
| 91 | + items = response.get("items", []) |
| 92 | + |
| 93 | + assert len(items) > 1, "Expected multiple sources to be returned" |
| 94 | + |
| 95 | + # Verify we have at least one enabled source |
| 96 | + enabled_sources = [item for item in items if item.get("status") == "available"] |
| 97 | + assert enabled_sources, "Expected at least one enabled source" |
| 98 | + |
| 99 | + # Verify we have at least one disabled source |
| 100 | + disabled_sources = [item for item in items if item.get("status") == "disabled"] |
| 101 | + assert disabled_sources, "Expected at least one disabled source" |
| 102 | + |
| 103 | + assert len(enabled_sources) + len(disabled_sources) == len(items), "Expected all sources to be returned" |
| 104 | + |
| 105 | + LOGGER.info( |
| 106 | + f"Sources endpoint returned {len(items)} total sources: " |
| 107 | + f"{len(enabled_sources)} enabled, {len(disabled_sources)} disabled" |
| 108 | + ) |
0 commit comments