Skip to content

Commit 40beb97

Browse files
Miscellaneous integration test improvements
1 parent 6f60488 commit 40beb97

File tree

4 files changed

+59
-33
lines changed

4 files changed

+59
-33
lines changed

tests/integration/juju_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# libjuju version != juju agent version, but the major version should be identical—which is good
77
# enough to check for secrets
88
_libjuju_version = importlib.metadata.version("juju")
9-
has_secrets = int(_libjuju_version.split(".")[0]) >= 3
9+
is_3_or_higher = int(_libjuju_version.split(".")[0]) >= 3

tests/integration/test_data_integrator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
TEST_DATABASE = "testdatabase"
2222
TEST_TABLE = "testtable"
2323

24-
if juju_.has_secrets:
24+
if juju_.is_3_or_higher:
2525
TLS_APP_NAME = "self-signed-certificates"
2626
TLS_CONFIG = {"ca-common-name": "Test CA"}
2727
else:
@@ -34,7 +34,7 @@ async def get_data_integrator_credentials(ops_test: OpsTest) -> typing.Dict:
3434
data_integrator_unit = ops_test.model.applications[DATA_INTEGRATOR_APP_NAME].units[0]
3535
action = await data_integrator_unit.run_action(action_name="get-credentials")
3636
result = await action.wait()
37-
if juju_.has_secrets:
37+
if juju_.is_3_or_higher:
3838
assert result.results["return-code"] == 0
3939
else:
4040
assert result.results["Code"] == "0"

tests/integration/test_exporter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
GRAFANA_AGENT_APP_NAME = "grafana-agent"
2121
SLOW_TIMEOUT = 25 * 60
2222

23-
if juju_.has_secrets:
23+
if juju_.is_3_or_higher:
2424
TLS_APP_NAME = "self-signed-certificates"
2525
TLS_CONFIG = {"ca-common-name": "Test CA"}
2626
else:
@@ -184,6 +184,7 @@ async def test_exporter_endpoint_with_tls(ops_test: OpsTest) -> None:
184184
application_name=TLS_APP_NAME,
185185
channel="stable",
186186
config=TLS_CONFIG,
187+
series="jammy",
187188
)
188189

189190
await ops_test.model.wait_for_idle([TLS_APP_NAME], status="active", timeout=SLOW_TIMEOUT)

tests/integration/test_tls.py

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
import asyncio
55
import logging
6-
import time
76

87
import pytest
8+
import tenacity
99
from pytest_operator.plugin import OpsTest
1010

1111
from . import juju_
@@ -18,7 +18,7 @@
1818
TEST_APP_NAME = "mysql-test-app"
1919
SLOW_TIMEOUT = 15 * 60
2020

21-
if juju_.has_secrets:
21+
if juju_.is_3_or_higher:
2222
TLS_APP_NAME = "self-signed-certificates"
2323
TLS_CONFIG = {"ca-common-name": "Test CA"}
2424
else:
@@ -34,7 +34,11 @@ async def test_build_deploy_and_relate(ops_test: OpsTest, mysql_router_charm_ser
3434
async with ops_test.fast_forward():
3535
# deploy mysql first
3636
await ops_test.model.deploy(
37-
MYSQL_APP_NAME, channel="8.0/edge", config={"profile": "testing"}, num_units=1
37+
MYSQL_APP_NAME,
38+
channel="8.0/edge",
39+
application_name=MYSQL_APP_NAME,
40+
config={"profile": "testing"},
41+
num_units=1,
3842
)
3943

4044
# ROUTER
@@ -49,7 +53,11 @@ async def test_build_deploy_and_relate(ops_test: OpsTest, mysql_router_charm_ser
4953
series=mysql_router_charm_series,
5054
),
5155
ops_test.model.deploy(
52-
TLS_APP_NAME, application_name=TLS_APP_NAME, channel="stable", config=TLS_CONFIG
56+
TLS_APP_NAME,
57+
application_name=TLS_APP_NAME,
58+
channel="stable",
59+
config=TLS_CONFIG,
60+
series="jammy",
5361
),
5462
ops_test.model.deploy(
5563
TEST_APP_NAME,
@@ -78,39 +86,56 @@ async def test_connected_encryption(ops_test: OpsTest) -> None:
7886
"""Test encryption when backend database is using TLS."""
7987
mysqlrouter_unit = ops_test.model.applications[MYSQL_ROUTER_APP_NAME].units[0]
8088

81-
issuer = await get_tls_certificate_issuer(
82-
ops_test,
83-
mysqlrouter_unit.name,
84-
socket="/var/snap/charmed-mysql/common/run/mysqlrouter/mysql.sock",
85-
)
86-
assert (
87-
"Issuer: CN = MySQL_Router_Auto_Generated_CA_Certificate" in issuer
88-
), "Expected mysqlrouter autogenerated certificate"
89+
for attempt in tenacity.Retrying(
90+
reraise=True,
91+
stop=tenacity.stop_after_delay(60),
92+
wait=tenacity.wait_fixed(10),
93+
):
94+
with attempt:
95+
issuer = await get_tls_certificate_issuer(
96+
ops_test,
97+
mysqlrouter_unit.name,
98+
socket="/var/snap/charmed-mysql/common/run/mysqlrouter/mysql.sock",
99+
)
100+
assert (
101+
"Issuer: CN = MySQL_Router_Auto_Generated_CA_Certificate" in issuer
102+
), "Expected mysqlrouter autogenerated certificate"
89103

90104
logger.info("Relating TLS with mysqlrouter")
91105
await ops_test.model.relate(TLS_APP_NAME, MYSQL_ROUTER_APP_NAME)
92106

93-
time.sleep(30)
94-
95107
logger.info("Getting certificate issuer after relating with tls operator")
96-
issuer = await get_tls_certificate_issuer(
97-
ops_test,
98-
mysqlrouter_unit.name,
99-
socket="/var/snap/charmed-mysql/common/run/mysqlrouter/mysql.sock",
100-
)
101-
assert "CN = Test CA" in issuer, f"Expected mysqlrouter certificate from {TLS_APP_NAME}"
108+
for attempt in tenacity.Retrying(
109+
reraise=True,
110+
stop=tenacity.stop_after_delay(60),
111+
wait=tenacity.wait_fixed(10),
112+
):
113+
with attempt:
114+
issuer = await get_tls_certificate_issuer(
115+
ops_test,
116+
mysqlrouter_unit.name,
117+
socket="/var/snap/charmed-mysql/common/run/mysqlrouter/mysql.sock",
118+
)
119+
assert (
120+
"CN = Test CA" in issuer
121+
), f"Expected mysqlrouter certificate from {TLS_APP_NAME}"
102122

103123
logger.info("Removing relation TLS with mysqlrouter")
104124
await ops_test.model.applications[MYSQL_ROUTER_APP_NAME].remove_relation(
105125
f"{TLS_APP_NAME}:certificates", f"{MYSQL_ROUTER_APP_NAME}:certificates"
106126
)
107127

108-
time.sleep(30)
109-
issuer = await get_tls_certificate_issuer(
110-
ops_test,
111-
mysqlrouter_unit.name,
112-
socket="/var/snap/charmed-mysql/common/run/mysqlrouter/mysql.sock",
113-
)
114-
assert (
115-
"Issuer: CN = MySQL_Router_Auto_Generated_CA_Certificate" in issuer
116-
), "Expected mysqlrouter autogenerated CA certificate"
128+
for attempt in tenacity.Retrying(
129+
reraise=True,
130+
stop=tenacity.stop_after_delay(60),
131+
wait=tenacity.wait_fixed(10),
132+
):
133+
with attempt:
134+
issuer = await get_tls_certificate_issuer(
135+
ops_test,
136+
mysqlrouter_unit.name,
137+
socket="/var/snap/charmed-mysql/common/run/mysqlrouter/mysql.sock",
138+
)
139+
assert (
140+
"Issuer: CN = MySQL_Router_Auto_Generated_CA_Certificate" in issuer
141+
), "Expected mysqlrouter autogenerated CA certificate"

0 commit comments

Comments
 (0)