From 6fe3c9f25e233058eac4810447b7f2a4879c9f44 Mon Sep 17 00:00:00 2001 From: josep-tecnativa Date: Wed, 5 Feb 2025 13:16:37 +0100 Subject: [PATCH] [FIX] Test postgres Use a unique Compose project name in tests to avoid volume collisions when running multiple PostgreSQL versions in parallel. --- tests/test_postgres.py | 56 +++++++++++++----------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/tests/test_postgres.py b/tests/test_postgres.py index d54f263d..0bcbe4f1 100644 --- a/tests/test_postgres.py +++ b/tests/test_postgres.py @@ -15,52 +15,24 @@ def _get_db_service_name(dc: DockerClient) -> str: - """ - Use python-on-whales to retrieve the final Compose configuration - and return the DB service name that ends with '-db'. - Fallback to any service containing 'db' or 'postgres'. - Finally, fallback to 'db'. - """ config_data = dc.compose.config() - if ComposeConfig and isinstance(config_data, ComposeConfig): - services_dict = {s.name: s for s in config_data.services} + # (1) In newer versions of python-on-whales: + # config_data is a ComposeConfig => config_data.services is a dict: + # { "service_name": ServiceConfig(...) } + # (2) In older versions: config_data is a "legacy" dict + # => config_data["services"] => { "service_name": {...} } - elif isinstance(config_data, dict): - services_dict = config_data["services"] + if ComposeConfig and isinstance(config_data, ComposeConfig): + services_dict = config_data.services else: - raise TypeError( - f"dc.compose.config() devolvió un tipo inesperado: {type(config_data)}" - ) - for svc_name in services_dict: - if svc_name.lower().endswith("-db"): - return svc_name - for svc_name in services_dict: - lower_svc_name = svc_name.lower() - if "postgres" in lower_svc_name or "db" in lower_svc_name: - return svc_name - return "db" - - -def _get_db_service_name(dc: DockerClient) -> str: - """ - Use python-on-whales to retrieve the final Compose configuration - and return the DB service name that ends with '-db'. Fallback to - any service containing 'db' or 'postgres'. Finally, fallback to 'db'. - """ - config_data = dc.compose.config() # Returns a dict with { "services": {...}, ... } - services_dict = config_data["services"] - # First pass: Look for a service name that exactly ends with '-db' + services_dict = config_data["services"] for svc_name in services_dict: if svc_name.lower().endswith("-db"): return svc_name - - # Second pass: Fallback to any name containing 'db' or 'postgres' for svc_name in services_dict: if "postgres" in svc_name.lower() or "db" in svc_name.lower(): return svc_name - - # Final fallback return "db" @@ -72,18 +44,24 @@ def test_postgresql_client_versions( dbver: str, ): """Test multiple postgresql-client versions in odoo, db and duplicity services""" + unique_project_name = f"test_{uuid.uuid4().hex}" + dc_prod = DockerClient( + compose_files=["prod.yaml"], + compose_project_name=unique_project_name, + ) + dbver_raw = DBVER_PER_ODOO[supported_odoo_version][dbver] dbver_mver = dbver_raw.split(".")[0] - dc_prod = DockerClient(compose_files=["prod.yaml"]) + with local.cwd(tmp_path): print(str(cloned_template)) - assert True + run_copy( str(cloned_template), dst_path=".", data={ "odoo_version": supported_odoo_version, - "project_name": uuid.uuid4().hex, + "project_name": unique_project_name, "odoo_proxy": "", "postgres_version": dbver_raw, "backup_dst": "/tmp/dummy",