Skip to content

Commit

Permalink
Merge pull request #3542 from mulkieran/packit-duration
Browse files Browse the repository at this point in the history
Tidy up udev tests
  • Loading branch information
mulkieran authored Feb 7, 2024
2 parents e7cb920 + 4db2c99 commit 7909471
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 35 deletions.
3 changes: 3 additions & 0 deletions tests/client-dbus/tests/udev/_dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def remove_stratis_setup():
if _remove_device(dev):
devices.remove(dev)

if _get_stratis_devices() != []:
raise RuntimeError("Some devices were not removed")


if __name__ == "__main__":
remove_stratis_setup()
27 changes: 12 additions & 15 deletions tests/client-dbus/tests/udev/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

# isort: STDLIB
import logging
import os
import random
import signal
Expand Down Expand Up @@ -43,7 +44,7 @@
)
from stratisd_client_dbus._constants import TOP_OBJECT

from ._dm import _get_stratis_devices, remove_stratis_setup
from ._dm import remove_stratis_setup
from ._loopback import LoopBackDevices

_STRATISD = os.environ["STRATISD"]
Expand Down Expand Up @@ -232,17 +233,6 @@ def processes(name):
pass


def remove_stratis_dm_devices():
"""
Remove Stratis device mapper devices, fail with a runtime error if
some have been missed.
:raises RuntimeError: if some devices are remaining
"""
remove_stratis_setup()
if _get_stratis_devices() != []:
raise RuntimeError("Some devices were not removed")


class _Service:
"""
Start and stop stratisd.
Expand Down Expand Up @@ -297,7 +287,7 @@ def stop_service(self):
:return: None
"""
self._service.send_signal(signal.SIGINT)
self._service.wait()
self._service.wait(timeout=30)
if next(processes("stratisd"), None) is not None:
raise RuntimeError("Failed to stop stratisd service")

Expand Down Expand Up @@ -426,10 +416,17 @@ def _clean_up(self):
"""
stratisds = list(processes("stratisd"))
for process in stratisds:
logging.warning("stratisd process %s still running, terminating", process)
process.terminate()
psutil.wait_procs(stratisds)
(_, alive) = psutil.wait_procs(stratisds, timeout=10)
for process in alive:
logging.warning(
"stratisd process %s did not respond to terminate signal, killing",
process,
)
process.kill()

remove_stratis_dm_devices()
remove_stratis_setup()
self._lb_mgr.destroy_all()

def wait_for_pools(self, expected_num, *, name=None):
Expand Down
33 changes: 13 additions & 20 deletions tests/client-dbus/tests/udev/test_udev.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"""

# isort: STDLIB
import logging
import random

# isort: LOCAL
from stratisd_client_dbus import Manager, Pool, StratisdErrors, get_object
from stratisd_client_dbus._constants import TOP_OBJECT
from stratisd_client_dbus._stratisd_constants import EncryptionMethod

from ._dm import remove_stratis_setup
from ._loopback import UDEV_ADD_EVENT, UDEV_REMOVE_EVENT
from ._utils import (
CRYPTO_LUKS_FS_TYPE,
Expand All @@ -33,12 +35,13 @@
create_pool,
get_devnodes,
random_string,
remove_stratis_dm_devices,
settle,
wait_for_udev,
wait_for_udev_count,
)

logging.basicConfig(level=logging.INFO)


class UdevTest1(UdevTest):
"""
Expand Down Expand Up @@ -79,7 +82,7 @@ def _test_driver(self, number_of_pools, dev_count_pool):
create_pool(pool_name, self._lb_mgr.device_files(device_tokens))
pool_data[pool_name] = device_tokens

remove_stratis_dm_devices()
remove_stratis_setup()

all_tokens = [
dev for device_tokens in pool_data.values() for dev in device_tokens
Expand All @@ -91,7 +94,7 @@ def _test_driver(self, number_of_pools, dev_count_pool):
with ServiceContextManager():
self.wait_for_pools(number_of_pools)

remove_stratis_dm_devices()
remove_stratis_setup()

self._lb_mgr.unplug(all_tokens)

Expand Down Expand Up @@ -124,8 +127,6 @@ def _test_driver(self, number_of_pools, dev_count_pool):
for name in pool_data:
self.wait_for_pools(1, name=name)

remove_stratis_dm_devices()

def test_generic(self):
"""
See _test_driver for description.
Expand Down Expand Up @@ -170,12 +171,12 @@ def _single_pool(self, num_devices, *, num_hotplugs=0):
self.assertEqual(len(device_object_paths), len(devnodes))
wait_for_udev(STRATIS_FS_TYPE, get_devnodes(device_object_paths))

remove_stratis_dm_devices()
remove_stratis_setup()

with ServiceContextManager():
self.wait_for_pools(1)

remove_stratis_dm_devices()
remove_stratis_setup()

self._lb_mgr.unplug(device_tokens)

Expand All @@ -199,8 +200,6 @@ def _single_pool(self, num_devices, *, num_hotplugs=0):

self.wait_for_pools(1)

remove_stratis_dm_devices()

def test_simultaneous(self):
"""
See documentation for _single_pool.
Expand Down Expand Up @@ -259,7 +258,7 @@ def _simple_initial_discovery_test(
pool_uuid = Pool.Properties.Uuid.Get(get_object(pool_object_path))

if take_down_dm:
remove_stratis_dm_devices()
remove_stratis_setup()

with OptionalKeyServiceContextManager(key_spec=key_spec):
((changed, _), exit_code, _) = Manager.Methods.StartPool(
Expand All @@ -281,8 +280,6 @@ def _simple_initial_discovery_test(

self.wait_for_pools(1)

remove_stratis_dm_devices()

def test_encryption_simple_initial_discovery(self):
"""
See documentation for _simple_initial_discovery_test.
Expand Down Expand Up @@ -346,7 +343,7 @@ def _simple_event_test(self, *, key_spec=None): # pylint: disable=too-many-loca
self.wait_for_pools(1)
pool_uuid = Pool.Properties.Uuid.Get(get_object(pool_object_path))

remove_stratis_dm_devices()
remove_stratis_setup()

self._lb_mgr.unplug(device_tokens)
wait_for_udev(udev_wait_type, [])
Expand Down Expand Up @@ -404,8 +401,6 @@ def _simple_event_test(self, *, key_spec=None): # pylint: disable=too-many-loca

self.wait_for_pools(1)

remove_stratis_dm_devices()

def test_simple_event(self):
"""
See documentation for _simple_event_test.
Expand Down Expand Up @@ -474,7 +469,7 @@ def test_duplicate_pool_name(

pool_tokens.append(this_pool)

remove_stratis_dm_devices()
remove_stratis_setup()

self._lb_mgr.unplug(this_pool)

Expand Down Expand Up @@ -557,8 +552,6 @@ def test_duplicate_pool_name(

self.wait_for_pools(num_pools)

remove_stratis_dm_devices()


class UdevTest6(UdevTest):
"""
Expand Down Expand Up @@ -602,7 +595,7 @@ def _simple_stop_test(self):

self.wait_for_pools(2)

remove_stratis_dm_devices()
remove_stratis_setup()

with OptionalKeyServiceContextManager():
self.wait_for_pools(2)
Expand All @@ -626,7 +619,7 @@ def _simple_stop_test(self):
1,
)

remove_stratis_dm_devices()
remove_stratis_setup()

with OptionalKeyServiceContextManager():
self.wait_for_pools(1)
Expand Down

0 comments on commit 7909471

Please sign in to comment.