|
3 | 3 | # See LICENSE file for licensing details.
|
4 | 4 | import asyncio
|
5 | 5 | import logging
|
6 |
| -import secrets |
7 |
| -import string |
8 |
| -from pathlib import Path |
9 |
| -from time import sleep |
10 | 6 |
|
11 | 7 | import psycopg2
|
12 | 8 | import pytest
|
13 |
| -import yaml |
14 |
| -from pytest_operator.plugin import OpsTest, FileResource |
| 9 | +from pytest_operator.plugin import OpsTest |
15 | 10 | from tenacity import Retrying, stop_after_delay, wait_fixed
|
16 | 11 |
|
17 | 12 | from ..helpers import CHARM_SERIES, DATABASE_APP_NAME, METADATA
|
18 |
| -from ..new_relations.test_new_relations import APPLICATION_APP_NAME |
19 |
| -from ..new_relations.test_new_relations import build_connection_string |
| 13 | +from ..new_relations.test_new_relations import APPLICATION_APP_NAME, build_connection_string |
20 | 14 | from ..relations.helpers import get_legacy_db_connection_str
|
21 | 15 |
|
22 | 16 | logger = logging.getLogger(__name__)
|
@@ -61,80 +55,81 @@ async def test_deploy_charms(ops_test: OpsTest, charm):
|
61 | 55 |
|
62 | 56 | await ops_test.model.wait_for_idle(apps=APP_NAMES, status="active", timeout=3000)
|
63 | 57 |
|
64 |
| -# @pytest.mark.group(1) |
65 |
| -# async def test_legacy_modern_endpoints(ops_test: OpsTest): |
66 |
| -# await ops_test.model.relate(MAILMAN3_CORE_APP_NAME, f"{APP_NAME}:{DB_RELATION}") |
67 |
| -# await ops_test.model.relate(APP_NAME, f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}") |
68 |
| -# |
69 |
| -# app = ops_test.model.applications[APP_NAME] |
70 |
| -# await ops_test.model.block_until( |
71 |
| -# lambda: "blocked" in {unit.workload_status for unit in app.units}, |
72 |
| -# timeout=1500, |
73 |
| -# ) |
74 |
| -# |
75 |
| -# logger.info(f" remove relation with modern endpoints") |
76 |
| -# await ops_test.model.applications[APP_NAME].remove_relation( |
77 |
| -# f"{APP_NAME}:{DATABASE_RELATION}", f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}" |
78 |
| -# ) |
79 |
| -# async with ops_test.fast_forward(): |
80 |
| -# await ops_test.model.wait_for_idle( |
81 |
| -# status="active", |
82 |
| -# timeout=1500, |
83 |
| -# raise_on_error=False, |
84 |
| -# ) |
85 |
| -# |
86 |
| -# legacy_interface_connect = await get_legacy_db_connection_str(ops_test, MAILMAN3_CORE_APP_NAME, DB_RELATION, |
87 |
| -# remote_unit_name=f"{APP_NAME}/0") |
88 |
| -# logger.info(f" check connect to = {legacy_interface_connect}") |
89 |
| -# for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(10)): |
90 |
| -# with attempt: |
91 |
| -# with psycopg2.connect(legacy_interface_connect) as connection: |
92 |
| -# assert connection.status == psycopg2.extensions.STATUS_READY |
93 |
| -# |
94 |
| -# logger.info(f"==== remove relation mailman3-core") |
95 |
| -# async with ops_test.fast_forward(): |
96 |
| -# await ops_test.model.applications[APP_NAME].remove_relation( |
97 |
| -# f"{APP_NAME}:db", f"mailman3-core:db" |
98 |
| -# ) |
99 |
| -# await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000) |
100 |
| -# with pytest.raises(psycopg2.OperationalError): |
101 |
| -# psycopg2.connect(legacy_interface_connect) |
102 |
| -# |
103 |
| -# async def test_legacy_modern_endpoints_a(ops_test: OpsTest): |
104 |
| -# await ops_test.model.relate(MAILMAN3_CORE_APP_NAME, f"{APP_NAME}:{DB_RELATION}") |
105 |
| -# await ops_test.model.relate(APP_NAME, f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}") |
106 |
| -# |
107 |
| -# app = ops_test.model.applications[APP_NAME] |
108 |
| -# await ops_test.model.block_until( |
109 |
| -# lambda: "blocked" in {unit.workload_status for unit in app.units}, |
110 |
| -# timeout=1500, |
111 |
| -# ) |
112 |
| -# |
113 |
| -# logger.info(f" remove relation with legacy endpoints") |
114 |
| -# await ops_test.model.applications[APP_NAME].remove_relation( |
115 |
| -# f"{MAILMAN3_CORE_APP_NAME}:{DB_RELATION}", f"{APP_NAME}:{DB_RELATION}" |
116 |
| -# ) |
117 |
| -# async with ops_test.fast_forward(): |
118 |
| -# await ops_test.model.wait_for_idle( |
119 |
| -# status="active", |
120 |
| -# timeout=3000, |
121 |
| -# raise_on_error=False |
122 |
| -# ) |
123 |
| -# |
124 |
| -# modern_interface_connect = await build_connection_string(ops_test, APPLICATION_APP_NAME, FIRST_DATABASE_RELATION) |
125 |
| -# logger.info(f" ==================== modern database_unit_name ={modern_interface_connect}") |
126 |
| -# for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(10)): |
127 |
| -# with attempt: |
128 |
| -# with psycopg2.connect(modern_interface_connect) as connection: |
129 |
| -# assert connection.status == psycopg2.extensions.STATUS_READY |
130 |
| -# |
131 |
| -# logger.info(f"==== modern remove relation {APPLICATION_APP_NAME}") |
132 |
| -# async with ops_test.fast_forward(): |
133 |
| -# await ops_test.model.applications[APP_NAME].remove_relation( |
134 |
| -# f"{APP_NAME}:{DATABASE_RELATION}", f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}" |
135 |
| -# ) |
136 |
| -# await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000) |
137 |
| -# for attempt in Retrying(stop=stop_after_delay(60 * 5), wait=wait_fixed(10)): |
138 |
| -# with attempt: |
139 |
| -# with pytest.raises(psycopg2.OperationalError): |
140 |
| -# psycopg2.connect(modern_interface_connect) |
| 58 | + |
| 59 | +@pytest.mark.group(1) |
| 60 | +async def test_legacy_endpoint_with_multiple_related_endpoints(ops_test: OpsTest): |
| 61 | + await ops_test.model.relate(MAILMAN3_CORE_APP_NAME, f"{APP_NAME}:{DB_RELATION}") |
| 62 | + await ops_test.model.relate(APP_NAME, f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}") |
| 63 | + |
| 64 | + app = ops_test.model.applications[APP_NAME] |
| 65 | + await ops_test.model.block_until( |
| 66 | + lambda: "blocked" in {unit.workload_status for unit in app.units}, |
| 67 | + timeout=1500, |
| 68 | + ) |
| 69 | + |
| 70 | + logger.info(" remove relation with modern endpoints") |
| 71 | + await ops_test.model.applications[APP_NAME].remove_relation( |
| 72 | + f"{APP_NAME}:{DATABASE_RELATION}", f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}" |
| 73 | + ) |
| 74 | + async with ops_test.fast_forward(): |
| 75 | + await ops_test.model.wait_for_idle( |
| 76 | + status="active", |
| 77 | + timeout=1500, |
| 78 | + raise_on_error=False, |
| 79 | + ) |
| 80 | + |
| 81 | + legacy_interface_connect = await get_legacy_db_connection_str( |
| 82 | + ops_test, MAILMAN3_CORE_APP_NAME, DB_RELATION, remote_unit_name=f"{APP_NAME}/0" |
| 83 | + ) |
| 84 | + logger.info(f" check connect to = {legacy_interface_connect}") |
| 85 | + for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(10)): |
| 86 | + with attempt: |
| 87 | + with psycopg2.connect(legacy_interface_connect) as connection: |
| 88 | + assert connection.status == psycopg2.extensions.STATUS_READY |
| 89 | + |
| 90 | + logger.info(" remove relation mailman3-core") |
| 91 | + async with ops_test.fast_forward(): |
| 92 | + await ops_test.model.applications[APP_NAME].remove_relation( |
| 93 | + f"{APP_NAME}:{DB_RELATION}", f"{MAILMAN3_CORE_APP_NAME}:{DB_RELATION}" |
| 94 | + ) |
| 95 | + await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000) |
| 96 | + with pytest.raises(psycopg2.OperationalError): |
| 97 | + psycopg2.connect(legacy_interface_connect) |
| 98 | + |
| 99 | + |
| 100 | +async def test_modern_endpoint_with_multiple_related_endpoints(ops_test: OpsTest): |
| 101 | + await ops_test.model.relate(MAILMAN3_CORE_APP_NAME, f"{APP_NAME}:{DB_RELATION}") |
| 102 | + await ops_test.model.relate(APP_NAME, f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}") |
| 103 | + |
| 104 | + app = ops_test.model.applications[APP_NAME] |
| 105 | + await ops_test.model.block_until( |
| 106 | + lambda: "blocked" in {unit.workload_status for unit in app.units}, |
| 107 | + timeout=1500, |
| 108 | + ) |
| 109 | + |
| 110 | + logger.info(" remove relation with legacy endpoints") |
| 111 | + await ops_test.model.applications[APP_NAME].remove_relation( |
| 112 | + f"{MAILMAN3_CORE_APP_NAME}:{DB_RELATION}", f"{APP_NAME}:{DB_RELATION}" |
| 113 | + ) |
| 114 | + async with ops_test.fast_forward(): |
| 115 | + await ops_test.model.wait_for_idle(status="active", timeout=3000, raise_on_error=False) |
| 116 | + |
| 117 | + modern_interface_connect = await build_connection_string( |
| 118 | + ops_test, APPLICATION_APP_NAME, FIRST_DATABASE_RELATION |
| 119 | + ) |
| 120 | + logger.info(f" check connect to = {modern_interface_connect}") |
| 121 | + for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(10)): |
| 122 | + with attempt: |
| 123 | + with psycopg2.connect(modern_interface_connect) as connection: |
| 124 | + assert connection.status == psycopg2.extensions.STATUS_READY |
| 125 | + |
| 126 | + logger.info(f" remove relation {APPLICATION_APP_NAME}") |
| 127 | + async with ops_test.fast_forward(): |
| 128 | + await ops_test.model.applications[APP_NAME].remove_relation( |
| 129 | + f"{APP_NAME}:{DATABASE_RELATION}", f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}" |
| 130 | + ) |
| 131 | + await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000) |
| 132 | + for attempt in Retrying(stop=stop_after_delay(60 * 5), wait=wait_fixed(10)): |
| 133 | + with attempt: |
| 134 | + with pytest.raises(psycopg2.OperationalError): |
| 135 | + psycopg2.connect(modern_interface_connect) |
0 commit comments