|
| 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 get_model_catalog_pod, wait_for_model_catalog_pod_created |
| 7 | +from utilities.general import wait_for_pods_running |
| 8 | + |
| 9 | +LOGGER = get_logger(name=__name__) |
| 10 | + |
| 11 | + |
| 12 | +def test_model_catalog_postgres_secret_exists(model_catalog_postgres_secret_values): |
| 13 | + """Test that model-catalog-postgres secret exists and is accessible""" |
| 14 | + secret_values = model_catalog_postgres_secret_values |
| 15 | + assert secret_values, "model-catalog-postgres secret should exist and be accessible" |
| 16 | + |
| 17 | + # Log the keys (not values) for debugging |
| 18 | + LOGGER.info(f"Secret contains keys: {list(secret_values.keys())}") |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.dependency(name="test_model_catalog_postgres_password_recreation") |
| 22 | +def test_model_catalog_postgres_password_recreation( |
| 23 | + model_catalog_postgres_secret_values, recreated_model_catalog_postgres_secret |
| 24 | +): |
| 25 | + """Test that secret recreation generates new password but preserves user/database name""" |
| 26 | + # Verify database-name and database-user did NOT change |
| 27 | + unchanged_keys = ["database-name", "database-user"] |
| 28 | + for key in unchanged_keys: |
| 29 | + assert model_catalog_postgres_secret_values[key] == recreated_model_catalog_postgres_secret[key], ( |
| 30 | + f"{key} should remain the same after secret recreation" |
| 31 | + ) |
| 32 | + |
| 33 | + # Verify database-password DID change (randomization working) |
| 34 | + assert ( |
| 35 | + model_catalog_postgres_secret_values["database-password"] |
| 36 | + != recreated_model_catalog_postgres_secret["database-password"] |
| 37 | + ), "database-password should be different after secret recreation (randomized)" |
| 38 | + |
| 39 | + LOGGER.info("Password randomization verified - new password generated on recreation") |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.dependency(depends=["test_model_catalog_postgres_password_recreation"]) |
| 43 | +def test_model_catalog_pod_ready_after_secret_recreation(admin_client: DynamicClient, model_registry_namespace: str): |
| 44 | + """Test that model catalog pod becomes ready after secret recreation""" |
| 45 | + # Wait for model catalog pod to be ready after the secret deletion/recreation |
| 46 | + postgres_pod = get_postgres_pod_in_namespace(admin_client=admin_client) |
| 47 | + postgres_pod.delete() |
| 48 | + model_catalog_pods = get_model_catalog_pod( |
| 49 | + client=admin_client, |
| 50 | + model_registry_namespace=model_registry_namespace, |
| 51 | + ) |
| 52 | + # We can wait for the pods to reflect updated catalog, however, deleting them ensures the updated config is |
| 53 | + # applied immediately. |
| 54 | + for pod in model_catalog_pods: |
| 55 | + pod.delete() |
| 56 | + # After the deletion, we need to wait for the pod to be spinned up and get to ready state. |
| 57 | + assert wait_for_model_catalog_pod_created(client=admin_client, model_registry_namespace=model_registry_namespace) |
| 58 | + wait_for_pods_running( |
| 59 | + admin_client=admin_client, namespace_name=model_registry_namespace, number_of_consecutive_checks=6 |
| 60 | + ) |
| 61 | + LOGGER.info("Model catalog pod is ready after secret recreation") |
0 commit comments