Skip to content

Commit

Permalink
Add new way of specifying post-test-checks
Browse files Browse the repository at this point in the history
As the number of post-test checks that we can usefully do proliferate,
specifying each one via a separate option is going to become more and
more inconvenient.

Leave the old way in place. It can be dropped after the next release.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Feb 26, 2024
1 parent 7563d53 commit c651579
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
25 changes: 22 additions & 3 deletions stratis_cli_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import argparse
import os
import sys
import time
import unittest

# isort: LOCAL
from testlib.dbus import StratisDbus, fs_n, p_n
from testlib.infra import (
DbusMonitor,
KernelKey,
PostTestCheck,
StratisdSystemdStart,
SymlinkMonitor,
SysfsMonitor,
Expand Down Expand Up @@ -1195,6 +1197,15 @@ def main():
help="disks to use, a minimum of 3 in order to run every test",
)

argument_parser.add_argument(
"--post-test-check",
action="extend",
choices=list(PostTestCheck),
default=[],
nargs="*",
type=PostTestCheck,
)

argument_parser.add_argument(
"--verify-sysfs", help="Verify /sys/class/block files", action="store_true"
)
Expand All @@ -1221,9 +1232,17 @@ 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
SysfsMonitor.verify_sysfs = (
PostTestCheck.SYSFS in parsed_args.post_test_check or parsed_args.verify_sysfs
)
DbusMonitor.monitor_dbus = (
PostTestCheck.DBUS_MONITOR in parsed_args.post_test_check
or parsed_args.monitor_dbus
)
SymlinkMonitor.verify_devices = (
PostTestCheck.PRIVATE_SYMLINKS in parsed_args.post_test_check
or parsed_args.verify_devices
)
StratisCertify.maxDiff = None
DbusMonitor.highest_revision_number = parsed_args.highest_revision_number

Expand Down
24 changes: 21 additions & 3 deletions stratisd_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from testlib.infra import (
DbusMonitor,
KernelKey,
PostTestCheck,
StratisdSystemdStart,
SymlinkMonitor,
SysfsMonitor,
Expand Down Expand Up @@ -1315,6 +1316,15 @@ def main():
help="disks to use, a minimum of 3 in order to run every test",
)

argument_parser.add_argument(
"--post-test-check",
action="extend",
choices=list(PostTestCheck),
default=[],
nargs="*",
type=PostTestCheck,
)

argument_parser.add_argument(
"--verify-sysfs", help="Verify /sys/class/block files", action="store_true"
)
Expand All @@ -1341,9 +1351,17 @@ 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
SysfsMonitor.verify_sysfs = (
PostTestCheck.SYSFS in parsed_args.post_test_check or parsed_args.verify_sysfs
)
DbusMonitor.monitor_dbus = (
PostTestCheck.DBUS_MONITOR in parsed_args.post_test_check
or parsed_args.monitor_dbus
)
SymlinkMonitor.verify_devices = (
PostTestCheck.PRIVATE_SYMLINKS in parsed_args.post_test_check
or parsed_args.verify_devices
)
StratisCertify.maxDiff = None
DbusMonitor.highest_revision_number = parsed_args.highest_revision_number
print(f"Using block device(s) for tests: {StratisCertify.DISKS}")
Expand Down
17 changes: 14 additions & 3 deletions test_harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import subprocess
import tempfile

# isort: LOCAL
from testlib.infra import PostTestCheck

_LOSETUP_BIN = "/usr/sbin/losetup"
_SIZE_OF_DEVICE = 1024**4 # 1 TiB

Expand Down Expand Up @@ -92,9 +95,7 @@ def _run_command(num_devices, command):
def _run_stratisd_cert(namespace, unittest_args):
command = (
["python3", "stratisd_cert.py"]
+ (["--monitor-dbus"] if namespace.monitor_dbus else [])
+ (["--verify-devices"] if namespace.verify_devices else [])
+ (["--verify-sysfs"] if namespace.verify_sysfs else [])
+ [f"--post-test-check={val}" for val in namespace.post_test_check]
+ (
[]
if namespace.highest_revision_number is None
Expand Down Expand Up @@ -131,6 +132,16 @@ def _gen_parser():
"stratisd_cert", help="Run stratisd_cert.py"
)
stratisd_cert_parser.set_defaults(func=_run_stratisd_cert)

stratisd_cert_parser.add_argument(
"--post-test-check",
action="extend",
choices=list(PostTestCheck),
default=[],
nargs="*",
type=PostTestCheck,
)

stratisd_cert_parser.add_argument(
"--monitor-dbus", help="Monitor D-Bus", action="store_true"
)
Expand Down
14 changes: 14 additions & 0 deletions testlib/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import subprocess
import time
import unittest
from enum import Enum
from tempfile import NamedTemporaryFile

# isort: THIRDPARTY
Expand Down Expand Up @@ -361,3 +362,16 @@ def __exit__(self, exception_type, exception_value, traceback):
if exception_value is None:
raise rexc
raise rexc from exception_value


class PostTestCheck(Enum):
"""
What PostTestChecks to run.
"""

DBUS_MONITOR = "monitor-dbus"
SYSFS = "verify-sysfs"
PRIVATE_SYMLINKS = "verify-private-symlinks"

def __str__(self):
return self.value

0 comments on commit c651579

Please sign in to comment.