From 99d724d6cc1aeaf7de5833644433d5d4f7a992e3 Mon Sep 17 00:00:00 2001 From: Bryan Gurney Date: Fri, 17 Nov 2023 14:29:19 -0500 Subject: [PATCH] stratis_cli_cert: add SysfsMonitor class Signed-off-by: Bryan Gurney --- stratis_cli_cert.py | 57 ++++++++++++++++++++++++++++++++++++++++++++- testlib/infra.py | 17 ++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/stratis_cli_cert.py b/stratis_cli_cert.py index c9bb9a4..887ad8d 100644 --- a/stratis_cli_cert.py +++ b/stratis_cli_cert.py @@ -24,7 +24,7 @@ # isort: LOCAL from testlib.dbus import StratisDbus, fs_n, p_n -from testlib.infra import DbusMonitor, KernelKey, StratisdSystemdStart, SymlinkMonitor +from testlib.infra import DbusMonitor, KernelKey, StratisdSystemdStart, SymlinkMonitor, SysfsMonitor from testlib.utils import ( RandomKeyTmpFile, create_relative_device_path, @@ -182,6 +182,8 @@ def tearDown(self): :return: None """ + SysfsMonitor.tearDown(self) + SymlinkMonitor.tearDown(self) DbusMonitor.tearDown(self) @@ -562,6 +564,54 @@ def test_pool_init_cache_add_data(self): True, ) + @skip(_skip_condition(3)) + def test_pool_add_data_init_cache(self): + """ + Test adding data for a pool, then initializing the cache. + """ + + pool_name = make_test_pool(StratisCliCertify.DISKS[0:1]) + filesystem_name = fs_n() + + self._unittest_command( + [ + _STRATIS_CLI, + "filesystem", + "create", + pool_name, + filesystem_name, + ], + 0, + True, + True, + ) + + self._unittest_command( + [ + _STRATIS_CLI, + "pool", + "add-data", + pool_name, + StratisCliCertify.DISKS[1], + ], + 0, + True, + True, + ) + + self._unittest_command( + [ + _STRATIS_CLI, + "pool", + "init-cache", + pool_name, + StratisCliCertify.DISKS[2], + ], + 0, + True, + True, + ) + @skip(_skip_condition(1)) def test_pool_stop_started(self): """ @@ -1103,6 +1153,10 @@ def main(): help="disks to use, a minimum of 3 in order to run every test", ) + argument_parser.add_argument( + "--verify-sysfs", help="Verify /sys/class/block files", action="store_true" + ) + argument_parser.add_argument( "--monitor-dbus", help="Monitor D-Bus", action="store_true" ) @@ -1125,6 +1179,7 @@ def main(): parsed_args, unittest_args = argument_parser.parse_known_args() StratisCliCertify.DISKS = parsed_args.DISKS + SysfsMonitor.verify_sysfs = parsed_args.verify_sysfs DbusMonitor.monitor_dbus = parsed_args.monitor_dbus SymlinkMonitor.verify_devices = parsed_args.verify_devices StratisCertify.maxDiff = None diff --git a/testlib/infra.py b/testlib/infra.py index 9d17eb6..0682c66 100644 --- a/testlib/infra.py +++ b/testlib/infra.py @@ -169,6 +169,23 @@ def setUp(self): exec_command(["udevadm", "settle"]) +class SysfsMonitor(unittest.TestCase): + """ + Manage verification of sysfs files for devices. + """ + + def tearDown(self): + if SysfsMonitor.verify_sysfs: # pylint: disable=no-member + try: + misaligned_devices = [] + for dev in os.listdir("/sys/class/block"): + if fnmatch.fnmatch(dev, "dm-*"): + misaligned_devices.append(dev) + self.assertEqual(misaligned_devices, []) + except FileNotFoundError: + pass + + class SymlinkMonitor(unittest.TestCase): """ Manage verification of device symlinks.