-
Notifications
You must be signed in to change notification settings - Fork 186
Automated nbdkit instance name visible in debug logs #6838
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 1 commit
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 |
|---|---|---|
|
|
@@ -739,6 +739,76 @@ def check_blocksize_constraints(): | |
| if field not in cmd_output: | ||
| test.fail('Expected field "%s" not found in export output: %s' % (field, cmd_output)) | ||
|
|
||
| def test_nbdkit_instance_name(): | ||
| from subprocess import Popen, TimeoutExpired | ||
|
|
||
| # Define our ports and a log file path within the test's debug directory | ||
| instances = [ | ||
| {"name": "server-gold", "port": 10809}, | ||
| {"name": "server-silver", "port": 10810} | ||
| ] | ||
| log_path = os.path.join(data_dir.get_tmp_dir(), "nbdkit_debug.log") | ||
|
|
||
| # Store the Popen objects here | ||
| handles = [] | ||
| try: | ||
| with open(log_path, "a") as log_file: | ||
|
ganeshhubale marked this conversation as resolved.
Outdated
|
||
| for inst in instances: | ||
| LOG.info(f"Starting nbdkit instance: {inst['name']}") | ||
|
|
||
| # Construct the command | ||
| # --foreground: Keeps it attached so we can redirect output easily | ||
| # --debug: Required to see the instance name in logs | ||
| cmd = [ | ||
| "nbdkit", "-f", "-v", | ||
| "--name", inst['name'], | ||
| "--port", str(inst['port']), | ||
| "memory", "10M" | ||
| ] | ||
| # Start nbdkit as a background process, piping stderr to our log file | ||
| p = Popen(cmd, stderr=log_file, stdout=log_file) | ||
| handles.append((inst, p)) | ||
|
|
||
| for inst, p in handles: | ||
| if p.poll() is not None: | ||
| test.fail(f"nbdkit {inst['name']} failed to start! Check {log_path}") | ||
|
|
||
| # Allow nbdkit instances time to start listening | ||
| import time | ||
| time.sleep(1) | ||
|
|
||
| # Trigger activity with qemu-io | ||
| for inst in instances: | ||
| LOG.info(f"Writing to {inst['name']} on port {inst['port']}") | ||
| qemu_cmd = f"qemu-io -f raw nbd://localhost:{inst['port']} -c \'write 0 1M\'" | ||
|
|
||
| result = process.run(qemu_cmd, shell=True) | ||
| if result.exit_status != 0: | ||
| test.fail(f"qemu-io failed for {inst['name']}") | ||
|
ganeshhubale marked this conversation as resolved.
ganeshhubale marked this conversation as resolved.
Comment on lines
+785
to
+787
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 -20Repository: autotest/tp-libvirt Length of output: 95 🏁 Script executed: if [ -f "v2v/tests/src/nbdkit/nbdkit.py" ]; then
sed -n '780,795p' "v2v/tests/src/nbdkit/nbdkit.py"
else
echo "File not found at expected path"
find . -name "nbdkit.py" -type f 2>/dev/null | head -5
fiRepository: autotest/tp-libvirt Length of output: 831 🏁 Script executed: if [ -f "v2v/tests/src/nbdkit/nbdkit.py" ]; then
head -50 "v2v/tests/src/nbdkit/nbdkit.py" | grep -E "^import|^from" | head -20
fiRepository: autotest/tp-libvirt Length of output: 465 🏁 Script executed: if [ -f "v2v/tests/src/nbdkit/nbdkit.py" ]; then
rg "process\.run\(" "v2v/tests/src/nbdkit/nbdkit.py" -A 3 -B 1
fiRepository: autotest/tp-libvirt Length of output: 24805 🌐 Web query:
💡 Result: In Source(s): Citations: 🌐 Web query:
💡 Result: In Avocado, This is why Avocado docs commonly show wrapping Sources: [1] [3] [2] [4] Pass
🛠️ Minimal fix- result = process.run(qemu_cmd, shell=True)
+ result = process.run(qemu_cmd, shell=True, ignore_status=True)
if result.exit_status != 0:
- test.fail(f"qemu-io failed for {inst['name']}")
+ test.fail(
+ f"qemu-io failed for {inst['name']}: "
+ f"{result.stderr_text or result.stdout_text}"
+ )🧰 Tools🪛 Ruff (0.15.6)[error] 785-785: Function call with (S604) 🤖 Prompt for AI Agents |
||
|
|
||
| # VALIDATION: Check the log file for the specific instance names | ||
| with open(log_path, 'r') as f: | ||
| log_content = f.read() | ||
|
|
||
| for inst in instances: | ||
| # Look for the debug pattern -> nbdkit[name]: debug: ... | ||
| expected_tag = f"nbdkit[{inst['name']}]: debug:" | ||
| if expected_tag not in log_content: | ||
| test.fail(f"Instance name '{inst['name']}' was not found in debug logs!") | ||
| LOG.info(f"Validated instance {inst['name']} appears in the debug logs") | ||
| finally: | ||
| # Cleanup: Kill the processes | ||
| LOG.info("Cleanup: Kill the processes") | ||
| for _, p in handles: | ||
| if p.poll() is None: | ||
| p.terminate() | ||
| try: | ||
| # Wait up to 5 seconds for it to exit | ||
| p.wait(timeout=5) | ||
| except TimeoutExpired: | ||
| # Force kill if it's being stubborn | ||
| p.kill() | ||
|
|
||
| if version_required and not multiple_versions_compare( | ||
| version_required): | ||
| test.cancel("Testing requires version: %s" % version_required) | ||
|
|
@@ -817,5 +887,7 @@ def check_blocksize_constraints(): | |
| check_blkhash_option() | ||
| elif checkpoint == 'blocksize_constraints': | ||
| check_blocksize_constraints() | ||
| elif checkpoint == 'test_nbdkit_instance_name': | ||
| test_nbdkit_instance_name() | ||
| else: | ||
| test.error('Not found testcase: %s' % checkpoint) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# First, let's examine the file at lines 750, 789-798, and surrounding context wc -l v2v/tests/src/nbdkit/nbdkit.pyRepository: autotest/tp-libvirt
Length of output: 97
🏁 Script executed:
Repository: autotest/tp-libvirt
Length of output: 3219
🏁 Script executed:
Repository: autotest/tp-libvirt
Length of output: 1066
🏁 Script executed:
Repository: autotest/tp-libvirt
Length of output: 914
🏁 Script executed:
# Check Avocado test class and imports in this file head -50 v2v/tests/src/nbdkit/nbdkit.pyRepository: autotest/tp-libvirt
Length of output: 1474
🏁 Script executed:
Repository: autotest/tp-libvirt
Length of output: 45
🏁 Script executed:
Repository: autotest/tp-libvirt
Length of output: 45
🏁 Script executed:
Repository: autotest/tp-libvirt
Length of output: 7430
🏁 Script executed:
Repository: autotest/tp-libvirt
Length of output: 93
🏁 Script executed:
Repository: autotest/tp-libvirt
Length of output: 1061
Move nbdkit debug log to test artifacts directory.
The nbdkit debug output containing instance name validation is written to a temporary directory and discarded after test completion. This prevents passing tests from surfacing the debug information needed for troubleshooting. Store the log file in the test results directory (using
test.logdiror similar Avocado test artifact API) and/or emit the validated instance name lines through the test logger so the information persists in test artifacts.Also applies to: 789-798
🤖 Prompt for AI Agents