Skip to content

Commit 14e3e96

Browse files
Port test modules to Python 3.10+
1 parent 6ea97e1 commit 14e3e96

File tree

6 files changed

+31
-39
lines changed

6 files changed

+31
-39
lines changed

tests/integration/helpers.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import string
99
import subprocess
1010
import tempfile
11-
from typing import Dict, List, Optional, Set
1211

1312
import juju.unit
1413
import yaml
@@ -133,7 +132,7 @@ async def get_primary_unit(
133132
return primary_unit
134133

135134

136-
async def get_server_config_credentials(unit: Unit) -> Dict:
135+
async def get_server_config_credentials(unit: Unit) -> dict:
137136
"""Helper to run an action to retrieve server config credentials.
138137
139138
Args:
@@ -145,7 +144,7 @@ async def get_server_config_credentials(unit: Unit) -> Dict:
145144
return await juju_.run_action(unit, "get-password", username=SERVER_CONFIG_USERNAME)
146145

147146

148-
async def fetch_credentials(unit: Unit, username: str = None) -> Dict:
147+
async def fetch_credentials(unit: Unit, username: str = None) -> dict:
149148
"""Helper to run an action to fetch credentials.
150149
151150
Args:
@@ -159,7 +158,7 @@ async def fetch_credentials(unit: Unit, username: str = None) -> Dict:
159158
return await juju_.run_action(unit, "get-password", username=username)
160159

161160

162-
async def rotate_credentials(unit: Unit, username: str = None, password: str = None) -> Dict:
161+
async def rotate_credentials(unit: Unit, username: str = None, password: str = None) -> dict:
163162
"""Helper to run an action to rotate credentials.
164163
165164
Args:
@@ -176,7 +175,7 @@ async def rotate_credentials(unit: Unit, username: str = None, password: str = N
176175
return await juju_.run_action(unit, "set-password", username=username, password=password)
177176

178177

179-
async def get_legacy_mysql_credentials(unit: Unit) -> Dict:
178+
async def get_legacy_mysql_credentials(unit: Unit) -> dict:
180179
"""Helper to run an action to retrieve legacy mysql config credentials.
181180
182181
Args:
@@ -189,7 +188,7 @@ async def get_legacy_mysql_credentials(unit: Unit) -> Dict:
189188

190189

191190
@retry(stop=stop_after_attempt(20), wait=wait_fixed(5), reraise=True)
192-
async def get_system_user_password(unit: Unit, user: str) -> Dict:
191+
async def get_system_user_password(unit: Unit, user: str) -> dict:
193192
"""Helper to run an action to retrieve system user password.
194193
195194
Args:
@@ -206,10 +205,10 @@ async def execute_queries_on_unit(
206205
unit_address: str,
207206
username: str,
208207
password: str,
209-
queries: List[str],
208+
queries: list[str],
210209
commit: bool = False,
211210
raw: bool = False,
212-
) -> List:
211+
) -> list:
213212
"""Execute given MySQL queries on a unit.
214213
215214
Args:
@@ -271,7 +270,7 @@ def is_relation_broken(ops_test: OpsTest, endpoint_one: str, endpoint_two: str)
271270

272271
@retry(stop=stop_after_attempt(30), wait=wait_fixed(5), reraise=True)
273272
def is_connection_possible(
274-
credentials: Dict, *, retry_if_not_possible=False, **extra_opts
273+
credentials: dict, *, retry_if_not_possible=False, **extra_opts
275274
) -> bool:
276275
"""Test a connection to a MySQL server.
277276
@@ -544,7 +543,7 @@ async def get_relation_data(
544543
return relation_data
545544

546545

547-
def get_read_only_endpoints(relation_data: list) -> Set[str]:
546+
def get_read_only_endpoints(relation_data: list) -> set[str]:
548547
"""Returns the read-only-endpoints from the relation data.
549548
550549
Args:
@@ -573,8 +572,8 @@ def get_read_only_endpoints(relation_data: list) -> Set[str]:
573572

574573

575574
async def get_leader_unit(
576-
ops_test: Optional[OpsTest], app_name: str, model: Optional[Model] = None
577-
) -> Optional[Unit]:
575+
ops_test: OpsTest | None, app_name: str, model: Model | None = None
576+
) -> Unit | None:
578577
"""Get the leader unit of a given application.
579578
580579
Args:
@@ -593,7 +592,7 @@ async def get_leader_unit(
593592
return leader_unit
594593

595594

596-
def get_read_only_endpoint_ips(relation_data: list) -> List[str]:
595+
def get_read_only_endpoint_ips(relation_data: list) -> list[str]:
597596
"""Returns the read-only-endpoint hostnames from the relation data.
598597
599598
Args:
@@ -640,7 +639,7 @@ async def remove_leader_unit(ops_test: OpsTest, application_name: str):
640639
)
641640

642641

643-
async def get_units_ip_addresses(ops_test: OpsTest, app_name: str) -> List[str]:
642+
async def get_units_ip_addresses(ops_test: OpsTest, app_name: str) -> list[str]:
644643
"""Retrieves hostnames of given application units.
645644
646645
Args:
@@ -810,12 +809,12 @@ async def unit_file_md5(ops_test: OpsTest, unit_name: str, file_path: str) -> st
810809
return None
811810

812811

813-
async def get_cluster_status(unit: Unit, cluster_set: Optional[bool] = False) -> Dict:
812+
async def get_cluster_status(unit: Unit, cluster_set: bool | None = False) -> dict:
814813
"""Get the cluster status by running the get-cluster-status action.
815814
816815
Args:
817-
ops_test: The ops test framework
818816
unit: The unit on which to execute the action on
817+
cluster_set: Whether to get the cluster-set instead
819818
820819
Returns:
821820
A dictionary representing the cluster status
@@ -978,9 +977,7 @@ def get_unit_by_index(app_name: str, units: list, index: int):
978977
return unit
979978

980979

981-
async def get_status_log(
982-
ops_test: OpsTest, unit_name: str, num_logs: Optional[int] = None
983-
) -> list:
980+
async def get_status_log(ops_test: OpsTest, unit_name: str, num_logs: int | None = None) -> list:
984981
"""Get the status log for a unit.
985982
986983
Args:

tests/integration/high_availability/high_availability_helpers.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import logging
55
from pathlib import Path
6-
from typing import List, Optional
76

87
import yaml
98
from juju.unit import Unit
@@ -76,7 +75,7 @@ def get_application_name(ops_test: OpsTest, application_name_substring: str) ->
7675

7776

7877
async def ensure_n_online_mysql_members(
79-
ops_test: OpsTest, number_online_members: int, mysql_units: Optional[List[Unit]] = None
78+
ops_test: OpsTest, number_online_members: int, mysql_units: list[Unit] | None = None
8079
) -> bool:
8180
"""Waits until N mysql cluster members are online.
8281
@@ -241,8 +240,8 @@ async def insert_data_into_mysql_and_validate_replication(
241240
ops_test: OpsTest,
242241
database_name: str,
243242
table_name: str,
244-
mysql_application_substring: Optional[str] = "mysql",
245-
mysql_units: Optional[List[Unit]] = None,
243+
mysql_application_substring: str | None = "mysql",
244+
mysql_units: list[Unit] | None = None,
246245
) -> str:
247246
"""Inserts data into the mysql cluster and validates its replication.
248247
@@ -332,7 +331,7 @@ async def clean_up_database_and_table(
332331

333332

334333
async def ensure_all_units_continuous_writes_incrementing(
335-
ops_test: OpsTest, mysql_units: Optional[List[Unit]] = None
334+
ops_test: OpsTest, mysql_units: list[Unit] | None = None
336335
) -> None:
337336
"""Ensure that continuous writes is incrementing on all units.
338337

tests/integration/high_availability/test_async_replication.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from asyncio import gather
99
from pathlib import Path
1010
from time import sleep
11-
from typing import Optional
1211

1312
import pytest
1413
import yaml
@@ -34,7 +33,7 @@
3433

3534

3635
@pytest.fixture(scope="module")
37-
def first_model(ops_test: OpsTest) -> Optional[Model]:
36+
def first_model(ops_test: OpsTest) -> Model | None:
3837
"""Return the first model."""
3938
first_model = ops_test.model
4039
return first_model

tests/integration/high_availability/test_primary_switchover.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import logging
55
from subprocess import run
6-
from typing import Optional
76

87
import pytest
98
from jubilant import Juju, all_active
@@ -75,7 +74,7 @@ def test_cluster_failover_after_majority_loss(juju: Juju, highly_available_clust
7574
assert get_primary_unit_name(juju, primary_unit) == unit_to_promote, "Failover failed"
7675

7776

78-
def get_primary_unit_name(juju: Juju, mysql_unit) -> Optional[str]:
77+
def get_primary_unit_name(juju: Juju, mysql_unit) -> str | None:
7978
"""Get the current primary node of the cluster."""
8079
cluster_status_task = juju.run(mysql_unit, "get-cluster-status")
8180
assert cluster_status_task.status == "completed", "Failed to retrieve cluster status"
@@ -86,7 +85,7 @@ def get_primary_unit_name(juju: Juju, mysql_unit) -> Optional[str]:
8685
return label.replace("-", "/")
8786

8887

89-
def get_app_name(juju: Juju, charm_name: str) -> Optional[str]:
88+
def get_app_name(juju: Juju, charm_name: str) -> str | None:
9089
"""Get the application name for the given charm."""
9190
status = juju.status()
9291
for app, value in status.apps.items():

tests/integration/relations/test_db_router.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import asyncio
66
import logging
77
from pathlib import Path
8-
from typing import Dict, List
98

109
import pytest
1110
import yaml
@@ -27,7 +26,7 @@
2726

2827

2928
async def check_successful_keystone_migration(
30-
ops_test: OpsTest, server_config_credentials: Dict
29+
ops_test: OpsTest, server_config_credentials: dict
3130
) -> None:
3231
"""Checks that the keystone application is successfully migrated in mysql.
3332
@@ -66,9 +65,9 @@ async def check_successful_keystone_migration(
6665

6766
async def check_keystone_users_existence(
6867
ops_test: OpsTest,
69-
server_config_credentials: Dict[str, str],
70-
users_that_should_exist: List[str],
71-
users_that_should_not_exist: List[str],
68+
server_config_credentials: dict[str, str],
69+
users_that_should_exist: list[str],
70+
users_that_should_not_exist: list[str],
7271
) -> None:
7372
"""Checks that keystone users exist in the database.
7473

tests/integration/relations/test_shared_db.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import logging
66
from pathlib import Path
7-
from typing import Dict, List
87

98
import pytest
109
import yaml
@@ -66,7 +65,7 @@ async def deploy_and_relate_keystone_with_mysql(
6665

6766

6867
async def check_successful_keystone_migration(
69-
ops_test: OpsTest, server_config_credentials: Dict
68+
ops_test: OpsTest, server_config_credentials: dict
7069
) -> None:
7170
"""Checks that the keystone application is successfully migrated in mysql.
7271
@@ -106,9 +105,9 @@ async def check_successful_keystone_migration(
106105

107106
async def check_keystone_users_existence(
108107
ops_test: OpsTest,
109-
server_config_credentials: Dict[str, str],
110-
users_that_should_exist: List[str],
111-
users_that_should_not_exist: List[str],
108+
server_config_credentials: dict[str, str],
109+
users_that_should_exist: list[str],
110+
users_that_should_not_exist: list[str],
112111
) -> None:
113112
"""Checks that keystone users exist in the database.
114113

0 commit comments

Comments
 (0)