|
4 | 4 | from kubernetes.dynamic import DynamicClient |
5 | 5 | from simple_logger.logger import get_logger |
6 | 6 |
|
7 | | -from tests.model_registry.model_catalog.constants import VALIDATED_CATALOG_ID |
| 7 | +from tests.model_registry.model_catalog.constants import VALIDATED_CATALOG_ID, REDHAT_AI_CATALOG_ID |
8 | 8 | from tests.model_registry.model_catalog.metadata.utils import ( |
9 | 9 | extract_custom_property_values, |
10 | 10 | validate_custom_properties_structure, |
11 | 11 | validate_custom_properties_match_metadata, |
12 | 12 | get_metadata_from_catalog_pod, |
13 | 13 | ) |
14 | | -from tests.model_registry.utils import get_model_catalog_pod |
| 14 | +from tests.model_registry.utils import get_model_catalog_pod, execute_get_command |
15 | 15 |
|
16 | 16 | LOGGER = get_logger(name=__name__) |
17 | 17 |
|
@@ -68,3 +68,45 @@ def test_custom_properties_match_metadata( |
68 | 68 | metadata = get_metadata_from_catalog_pod(model_catalog_pod=model_catalog_pods[0], model_name=model_name) |
69 | 69 |
|
70 | 70 | assert validate_custom_properties_match_metadata(api_props, metadata) |
| 71 | + |
| 72 | + @pytest.mark.parametrize("catalog_id", [REDHAT_AI_CATALOG_ID, VALIDATED_CATALOG_ID]) |
| 73 | + def test_model_type_field_in_custom_properties( |
| 74 | + self, |
| 75 | + catalog_id: str, |
| 76 | + model_catalog_rest_url: list[str], |
| 77 | + model_registry_rest_headers: dict[str, str], |
| 78 | + ): |
| 79 | + """ |
| 80 | + RHOAIENG-41720: Test that all models have model_type with valid values: "generative", "predictive", "unknown". |
| 81 | + """ |
| 82 | + valid_model_types = {"generative", "predictive", "unknown"} |
| 83 | + |
| 84 | + response = execute_get_command( |
| 85 | + url=f"{model_catalog_rest_url[0]}models?source={catalog_id}&pageSize=100", |
| 86 | + headers=model_registry_rest_headers, |
| 87 | + ) |
| 88 | + models = response["items"] |
| 89 | + |
| 90 | + LOGGER.info(f"Validating model_type field for {len(models)} models from catalog '{catalog_id}'") |
| 91 | + |
| 92 | + validation_errors = [] |
| 93 | + |
| 94 | + for model in models: |
| 95 | + custom_properties = model.get("customProperties", {}) |
| 96 | + |
| 97 | + if "model_type" not in custom_properties: |
| 98 | + validation_errors.append(f"Model '{model.get('name')}' missing model_type in customProperties") |
| 99 | + continue |
| 100 | + |
| 101 | + model_type_value = custom_properties["model_type"]["string_value"] |
| 102 | + if model_type_value not in valid_model_types: |
| 103 | + validation_errors.append( |
| 104 | + f"Model '{model.get('name')}' has invalid model_type: '{model_type_value}'. " |
| 105 | + f"Expected one of: {valid_model_types}" |
| 106 | + ) |
| 107 | + |
| 108 | + assert not validation_errors, ( |
| 109 | + f"model_type validation failed for {len(validation_errors)} models:\n" + "\n".join(validation_errors) |
| 110 | + ) |
| 111 | + |
| 112 | + LOGGER.info(f"All {len(models)} models in catalog '{catalog_id}' have valid model_type values") |
0 commit comments