-
Notifications
You must be signed in to change notification settings - Fork 186
Automate nbdkit data integrity test for NBD request size constraints and NFS truncation risk #6843
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -809,6 +809,68 @@ def test_nbdkit_instance_name(): | |
| # Force kill if it's being stubborn | ||
| p.kill() | ||
|
|
||
| def test_nbd_data_integrity(): | ||
| from subprocess import Popen, PIPE, STDOUT | ||
| import time | ||
| # --- Configuration --- | ||
| SOCKET = "/tmp/test.sock" | ||
| IMG_PATH = os.path.join(data_dir.get_tmp_dir(), "test.img") | ||
| IMAGE_SIZE = "1G" | ||
|
|
||
| LOG.info(f"Prepare {IMAGE_SIZE} image file") | ||
| cmd = f"truncate -s {IMAGE_SIZE} {IMG_PATH}" | ||
| process.run(cmd, shell=True, ignore_status=True) | ||
| if os.path.exists(SOCKET): | ||
| os.remove(SOCKET) | ||
|
|
||
| LOG.info("Starting nbdkit server in background") | ||
| nbd_log_file = os.path.join(data_dir.get_tmp_dir(), "nbd_log_file.log") | ||
| # Start nbdkit with debug flags enabled | ||
| with open(nbd_log_file, "w") as nbd_log_file: | ||
| server_cmd = ["nbdkit", "-f", "-v", "-D", "file.zero=1", "-U", SOCKET, "file", IMG_PATH] | ||
| nbd_server = Popen(server_cmd, stdout=nbd_log_file, stderr=nbd_log_file) | ||
| # Wait for the socket file to appear | ||
| time.sleep(1) | ||
|
ganeshhubale marked this conversation as resolved.
Comment on lines
+816
to
+833
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a per-run UNIX socket and wait for it explicitly. The fixed 🧰 Tools🪛 Ruff (0.15.6)[error] 816-816: Probable insecure usage of temporary file or directory: "/tmp/test.sock" (S108) [error] 822-822: Function call with (S604) [error] 831-831: (S603) 🤖 Prompt for AI Agents |
||
|
|
||
| test_state = params_get(params, "test_state") | ||
| try: | ||
| if test_state == "positive": | ||
| LOG.info("Testing nbdcopy with 32M") | ||
| cmd = f"nbdcopy --request-size=32M /dev/zero nbd+unix:///?socket={SOCKET}" | ||
| result = process.run(cmd, shell=True, ignore_status=True) | ||
| exp_warn = "No space left on device" | ||
| if exp_warn not in result.stderr_text: | ||
| test.fail(f"Expected warning {exp_warn}, got {result.stderr_text}") | ||
|
|
||
| LOG.info("Verification (Compare with /dev/zero)") | ||
| cmd = f"nbdcopy nbd+unix:///?socket={SOCKET} - | cmp -n {IMAGE_SIZE} - /dev/zero" | ||
| result = process.run(cmd, shell=True, ignore_status=True) | ||
|
|
||
| if result.exit_status != 0: | ||
| test.fail(f"Check Failed: Mismatch found! {result.stderr_text}") | ||
|
|
||
| LOG.info("Verification (MD5 Hash Check)") | ||
| # Pipe the output directly into a hash to save memory | ||
| hash_cmd = f"nbdcopy nbd+unix:///?socket={SOCKET} - | head -c {IMAGE_SIZE} | md5sum" | ||
| result = process.run(hash_cmd, shell=True, ignore_status=True) | ||
| actual_md5 = result.stdout_text | ||
| result = process.run("head -c 1G /dev/zero | md5sum", shell=True, ignore_status=True) | ||
| expected_md5 = result.stdout_text | ||
| if actual_md5 != expected_md5: | ||
| test.fail("[FAILURE] Data corruption detected.") | ||
| elif test_state == "negative": | ||
| LOG.info("Testing nbdcopy with 128M (Expected Failure)") | ||
| cmd = f"nbdcopy --request-size=128M /dev/zero nbd+unix:///?socket={SOCKET}" | ||
| result = process.run(cmd, shell=True, ignore_status=True) | ||
| err_msg = "must be a power of 2 within 4096-33554432: 128M" | ||
| if err_msg not in result.stderr_text: | ||
| test.fail(f"Expected warning {err_msg}, got {result.stderr_text}") | ||
| finally: | ||
| LOG.info("Cleaning up") | ||
| nbd_server.terminate() | ||
| nbd_server.wait() | ||
| if os.path.exists(SOCKET): | ||
| os.remove(SOCKET) | ||
|
Comment on lines
+868
to
+873
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -type f -name "nbdkit.py" | head -5Repository: autotest/tp-libvirt Length of output: 95 🏁 Script executed: cd v2v/tests/src/nbdkit && wc -l nbdkit.pyRepository: autotest/tp-libvirt Length of output: 76 🏁 Script executed: cd v2v/tests/src/nbdkit && sed -n '860,880p' nbdkit.pyRepository: autotest/tp-libvirt Length of output: 1065 🏁 Script executed: cd v2v/tests/src/nbdkit && grep -n "test_nbdkit_instance_name" nbdkit.pyRepository: autotest/tp-libvirt Length of output: 199 🏁 Script executed: cd v2v/tests/src/nbdkit && sed -n '742,810p' nbdkit.pyRepository: autotest/tp-libvirt Length of output: 3108 🏁 Script executed: cd v2v/tests/src/nbdkit && sed -n '800,820p' nbdkit.pyRepository: autotest/tp-libvirt Length of output: 846 Bound subprocess shutdown with timeout.
🛠️ Proposed fix- from subprocess import Popen, PIPE, STDOUT
+ from subprocess import Popen, TimeoutExpired
...
finally:
LOG.info("Cleaning up")
- nbd_server.terminate()
- nbd_server.wait()
+ if nbd_server.poll() is None:
+ nbd_server.terminate()
+ try:
+ nbd_server.wait(timeout=5)
+ except TimeoutExpired:
+ nbd_server.kill()
+ nbd_server.wait(timeout=5)
if os.path.exists(SOCKET):
os.remove(SOCKET)🤖 Prompt for AI Agents |
||
| def test_count_filter(): | ||
| # p is our SubProcess object | ||
| p = None | ||
|
|
@@ -969,6 +1031,8 @@ def test_data_plugin_supports_base64_in_format_string(): | |
| check_blocksize_constraints() | ||
| elif checkpoint == 'test_nbdkit_instance_name': | ||
| test_nbdkit_instance_name() | ||
| elif checkpoint == 'check_data_integrity': | ||
| test_nbd_data_integrity() | ||
| elif checkpoint == 'test_count_filter': | ||
| test_count_filter() | ||
| elif checkpoint == 'test_data_plugin_supports_base64_in_format_string': | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.