|
| 1 | +import pytest |
| 2 | +from kubernetes.dynamic import DynamicClient |
| 3 | +from simple_logger.logger import get_logger |
| 4 | + |
| 5 | +from tests.model_registry.model_catalog.utils import get_postgres_pod_in_namespace |
| 6 | +from tests.model_registry.utils import ( |
| 7 | + wait_for_model_catalog_pod_ready_after_deletion, |
| 8 | +) |
| 9 | + |
| 10 | +LOGGER = get_logger(name=__name__) |
| 11 | + |
| 12 | + |
| 13 | +def test_model_catalog_postgres_secret_exists(model_catalog_postgres_secret_values): |
| 14 | + """Test that model-catalog-postgres secret exists and is accessible""" |
| 15 | + secret_values = model_catalog_postgres_secret_values |
| 16 | + assert secret_values, "model-catalog-postgres secret should exist and be accessible" |
| 17 | + |
| 18 | + # Log the keys (not values) for debugging |
| 19 | + LOGGER.info(f"Secret contains keys: {list(secret_values.keys())}") |
| 20 | + |
| 21 | + |
| 22 | +@pytest.mark.dependency(name="test_model_catalog_postgres_password_recreation") |
| 23 | +def test_model_catalog_postgres_password_recreation( |
| 24 | + model_catalog_postgres_secret_values, recreated_model_catalog_postgres_secret |
| 25 | +): |
| 26 | + """Test that secret recreation generates new password but preserves user/database name""" |
| 27 | + # Verify database-name and database-user did NOT change |
| 28 | + unchanged_keys = ["database-name", "database-user"] |
| 29 | + for key in unchanged_keys: |
| 30 | + assert model_catalog_postgres_secret_values[key] == recreated_model_catalog_postgres_secret[key], ( |
| 31 | + f"{key} should remain the same after secret recreation" |
| 32 | + ) |
| 33 | + |
| 34 | + # Verify database-password DID change (randomization working) |
| 35 | + assert ( |
| 36 | + model_catalog_postgres_secret_values["database-password"] |
| 37 | + != recreated_model_catalog_postgres_secret["database-password"] |
| 38 | + ), "database-password should be different after secret recreation (randomized)" |
| 39 | + |
| 40 | + LOGGER.info("Password randomization verified - new password generated on recreation") |
| 41 | + |
| 42 | + |
| 43 | +@pytest.mark.dependency(depends=["test_model_catalog_postgres_password_recreation"]) |
| 44 | +def test_model_catalog_pod_ready_after_secret_recreation(admin_client: DynamicClient, model_registry_namespace: str): |
| 45 | + """Test that model catalog pod becomes ready after secret recreation""" |
| 46 | + # delete the postgres pod first |
| 47 | + get_postgres_pod_in_namespace(admin_client=admin_client).delete() |
| 48 | + # Wait for model catalog pod to be ready after the secret deletion/recreation |
| 49 | + wait_for_model_catalog_pod_ready_after_deletion( |
| 50 | + client=admin_client, model_registry_namespace=model_registry_namespace |
| 51 | + ) |
| 52 | + LOGGER.info("Model catalog pod is ready after secret recreation") |
0 commit comments