Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stratis_cli_cert: add SysfsMonitor class #230

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion stratis_cli_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@

# 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,
Expand Down Expand Up @@ -182,6 +188,8 @@ def tearDown(self):

:return: None
"""
SysfsMonitor.tearDown(self)

SymlinkMonitor.tearDown(self)

DbusMonitor.tearDown(self)
Expand Down Expand Up @@ -562,6 +570,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):
"""
Expand Down Expand Up @@ -1103,6 +1159,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"
)
Expand All @@ -1125,6 +1185,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
Expand Down
40 changes: 39 additions & 1 deletion stratisd_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@

# 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 (
create_relative_device_path,
exec_command,
Expand Down Expand Up @@ -213,6 +219,8 @@ def tearDown(self):

:return: None
"""
SysfsMonitor.tearDown(self)

SymlinkMonitor.tearDown(self)

DbusMonitor.tearDown(self)
Expand Down Expand Up @@ -623,6 +631,29 @@ def test_pool_add_different_data_after_cache(self):
dbus.UInt16(0),
)

@skip(_skip_condition(3))
def test_pool_add_data_init_cache(self):
"""
Test adding data for a pool, then initializing the cache.
"""
pool_name = p_n()
pool_path, _ = make_test_pool(pool_name, StratisCertify.DISKS[0:1])
fs_name = fs_n()

self._unittest_command(
StratisDbus.fs_create(pool_path, fs_name), dbus.UInt16(0)
)

self._unittest_command(
StratisDbus.pool_add_data(pool_path, StratisCertify.DISKS[1:2]),
dbus.UInt16(0),
)

self._unittest_command(
StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[2:3]),
dbus.UInt16(0),
)

@skip(_skip_condition(2))
def test_pool_create_with_cache(self):
"""
Expand Down Expand Up @@ -1259,9 +1290,15 @@ def main():
default=[],
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"
)

argument_parser.add_argument(
"--verify-devices", help="Verify /dev/disk/by-id devices", action="store_true"
)
Expand All @@ -1280,6 +1317,7 @@ def main():

parsed_args, unittest_args = argument_parser.parse_known_args()
StratisCertify.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
Expand Down
36 changes: 36 additions & 0 deletions testlib/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,42 @@ 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
dev_mapper = "/dev/mapper"
dm_devices = {
os.path.basename(
os.path.realpath(os.path.join(dev_mapper, dmdev))
): dmdev
for dmdev in os.listdir(dev_mapper)
}

try:
misaligned_devices = []
for dev in os.listdir("/sys/class/block"):
if fnmatch.fnmatch(dev, "dm-*"):
dev_sysfspath = os.path.join(
"/sys/class/block", dev, "alignment_offset"
)
with open(dev_sysfspath, "r", encoding="utf-8") as dev_sysfs:
dev_align = dev_sysfs.read().rstrip()
if int(dev_align) != 0:
misaligned_devices.append(
f"Stratis Name: {dm_devices[dev]}, "
f" DM name: {dev}, "
f" Alignment offset: {dev_align}"
)

self.assertEqual(misaligned_devices, [])
except FileNotFoundError:
pass


class SymlinkMonitor(unittest.TestCase):
"""
Manage verification of device symlinks.
Expand Down