Skip to content

Commit 927c0a3

Browse files
committed
Automated nbdkit count filter reports number of bytes read, write, zeroed, trimmed in debug log
Signed-off-by: Ganesh Hubale <ghubale@redhat.com>
1 parent a857564 commit 927c0a3

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

v2v/tests/cfg/nbdkit/nbdkit.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
option_tar_limit = '0 100K 100G'
8282
option_tar_entry = '0 latest-rhel9.img fake-entry'
8383
checkpoint = 'test_tar_filter'
84+
- count:
85+
version_required = "[nbdkit-1.46,)"
86+
checkpoint = 'test_count_filter'
8487
- plugin:
8588
variants:
8689
- file:

v2v/tests/src/nbdkit/nbdkit.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,56 @@ def check_blocksize_constraints():
739739
if field not in cmd_output:
740740
test.fail('Expected field "%s" not found in export output: %s' % (field, cmd_output))
741741

742+
def test_count_filter():
743+
from subprocess import Popen, TimeoutExpired
744+
745+
log_path = os.path.join(data_dir.get_tmp_dir(), "nbdkit_debug.log")
746+
747+
try:
748+
with open(log_path, "a") as log_file:
749+
LOG.info(f"Starting nbdkit")
750+
cmd = ["nbdkit", "-f", "-v", "memory", "10M", "--filter=count"]
751+
# Start nbdkit as a background process, piping stderr to log file
752+
p = Popen(cmd, stderr=log_file, stdout=log_file)
753+
754+
if p.poll() is not None:
755+
test.fail(f"nbdkit failed to start! Check {log_path}")
756+
757+
# Allow nbdkit instances time to start listening
758+
import time
759+
time.sleep(1)
760+
761+
# Trigger activity with qemu-io
762+
LOG.info("Writing to nbdkit")
763+
qemu_cmd = f"qemu-io -f raw nbd://localhost -c \'write 0 1M\' -c \'read 0 1M\' -c \'discard 0 1M\'"
764+
765+
result = process.run(qemu_cmd, shell=True)
766+
if result.exit_status != 0:
767+
test.fail(f"qemu-io failed")
768+
769+
# VALIDATION: Check the log file for the read, written, zeroed, trimmed reports
770+
with open(log_path, 'r') as f:
771+
log_content = f.read()
772+
LOG.info(f"logging info ----> {log_content}")
773+
# Look for the expected pattern
774+
expected_patterns = ["count: pwrite count=1048576", "count: pread count=1048576", "count: trim count=1048576"]
775+
776+
for pattern in expected_patterns:
777+
if pattern not in log_content:
778+
test.fail(f"'{pattern}' was not found in debug logs!")
779+
LOG.info(f"Pattern {pattern} appears in the debug logs")
780+
finally:
781+
# Cleanup: Kill the processes
782+
LOG.info("Cleanup: Kill the processes")
783+
if p.poll() is None:
784+
p.terminate()
785+
try:
786+
# Wait up to 5 seconds for it to exit
787+
p.wait(timeout=5)
788+
except TimeoutExpired:
789+
# Force kill if it's being stubborn
790+
p.kill()
791+
742792
if version_required and not multiple_versions_compare(
743793
version_required):
744794
test.cancel("Testing requires version: %s" % version_required)
@@ -817,5 +867,7 @@ def check_blocksize_constraints():
817867
check_blkhash_option()
818868
elif checkpoint == 'blocksize_constraints':
819869
check_blocksize_constraints()
870+
elif checkpoint == 'test_count_filter':
871+
test_count_filter()
820872
else:
821873
test.error('Not found testcase: %s' % checkpoint)

0 commit comments

Comments
 (0)