diff --git a/tests/client-dbus/tests/udev/_dm.py b/tests/client-dbus/tests/udev/_dm.py index f99d83da77..a71168348c 100644 --- a/tests/client-dbus/tests/udev/_dm.py +++ b/tests/client-dbus/tests/udev/_dm.py @@ -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() diff --git a/tests/client-dbus/tests/udev/_utils.py b/tests/client-dbus/tests/udev/_utils.py index 88a5067f64..529690b9d1 100644 --- a/tests/client-dbus/tests/udev/_utils.py +++ b/tests/client-dbus/tests/udev/_utils.py @@ -16,6 +16,7 @@ """ # isort: STDLIB +import logging import os import random import signal @@ -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"] @@ -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. @@ -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") @@ -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): diff --git a/tests/client-dbus/tests/udev/test_udev.py b/tests/client-dbus/tests/udev/test_udev.py index 0bb3685041..caf8564508 100644 --- a/tests/client-dbus/tests/udev/test_udev.py +++ b/tests/client-dbus/tests/udev/test_udev.py @@ -16,6 +16,7 @@ """ # isort: STDLIB +import logging import random # isort: LOCAL @@ -23,6 +24,7 @@ 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, @@ -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): """ @@ -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 @@ -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) @@ -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. @@ -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) @@ -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. @@ -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( @@ -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. @@ -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, []) @@ -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. @@ -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) @@ -557,8 +552,6 @@ def test_duplicate_pool_name( self.wait_for_pools(num_pools) - remove_stratis_dm_devices() - class UdevTest6(UdevTest): """ @@ -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) @@ -626,7 +619,7 @@ def _simple_stop_test(self): 1, ) - remove_stratis_dm_devices() + remove_stratis_setup() with OptionalKeyServiceContextManager(): self.wait_for_pools(1)