Skip to content

Commit

Permalink
use tenacity for wait_for_udev
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Sep 19, 2024
1 parent f70efb6 commit 24b5722
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions tests/client-dbus/tests/udev/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,29 +256,31 @@ def wait_for_udev_count(expected_num):
:return: None
:raises RuntimeError: if unexpected number of device nodes is found
"""
found_num = None

context = pyudev.Context()
end_time = time.time() + 10.0

while time.time() < end_time and not expected_num == found_num:
found_num = len(
frozenset(
[
x.device_node
for x in context.list_devices(
subsystem="block", ID_FS_TYPE=STRATIS_FS_TYPE
try:
for attempt in Retrying(
retry=retry_if_not_result(lambda found_num: found_num == expected_num),
stop=stop_after_delay(10),
wait=wait_fixed(1),
):
with attempt:
found_num = len(
frozenset(
[
x.device_node
for x in context.list_devices(
subsystem="block", ID_FS_TYPE=STRATIS_FS_TYPE
)
]
)
]
)
)
time.sleep(1)

if expected_num != found_num:
)
attempt.retry_state.set_result(found_num)
except RetryError as err:
raise RuntimeError(
f"Found unexpected number of devnodes: "
f"expected number: {expected_num} != found number: {found_num}"
)
"Found unexpected number of devnodes: expected number: "
f"{expected_num} != found number: {err.last_attempt.result()}"
) from err


def wait_for_udev(fs_type, expected_paths):
Expand Down

0 comments on commit 24b5722

Please sign in to comment.