Skip to content

libvirt_mem: Add vhost configuration for SLES#6886

Open
sneh-3 wants to merge 1 commit into
autotest:masterfrom
sneh-3:fix_vhost_backend
Open

libvirt_mem: Add vhost configuration for SLES#6886
sneh-3 wants to merge 1 commit into
autotest:masterfrom
sneh-3:fix_vhost_backend

Conversation

@sneh-3

@sneh-3 sneh-3 commented Jun 15, 2026

Copy link
Copy Markdown
  1. Enhanced memory hotplug testing with conditional vhost parameter configuration for SLES systems.
  2. Added automatic kernel module management and configuration verification for improved test reliability on SLES environments.

1. check the running dostro and vm state
2. configures vhost max_mem_regions

Signed-off-by: Sneh Shikha Yadav <syadav@linux.ibm.com>
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

A new inner helper function setup_vhost_max_mem_regions is added inside run() in libvirt_mem.py. It detects SLES by reading /etc/os-release, skips execution if any libvirt domains are currently running, unloads vhost-related kernel modules, loads the vhost module with max_mem_regions=512, and attempts to verify the configured value by reading /sys/module/vhost/parameters/max_mem_regions. Exceptions are caught and logged as warnings. The helper is invoked immediately after vm.destroy() and before the domain XML modification and memory hotplug setup continues.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'libvirt_mem: Add vhost configuration for SLES' directly and accurately describes the main change—adding vhost configuration support for SLES hosts in the libvirt_mem test component.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@libvirt/tests/src/libvirt_mem.py`:
- Around line 148-166: The verification failure for vhost max_mem_regions
configuration and the exception handler are downgrading setup errors to
warnings, allowing the test to continue in an invalid state. When verification
confirms the value is not set to "512" (around line 155-156), raise an exception
instead of just logging a warning. In the exception handler (around line
165-166), re-raise the caught exception instead of logging a warning and
continuing, so that SLES-targeted setup failures properly fail or cancel the
test path rather than silently proceeding.
- Around line 135-137: The current pipeline in the vm_check assignment combines
virsh and grep in a single command, which means the exit_status will reflect
grep's result rather than virsh's failure. If virsh list fails but grep runs
against empty output without error, the condition will incorrectly assess the
situation as safe to proceed. Split the command execution into two separate
steps: first run virsh list --state-running independently and check its exit
status, then only proceed to parse the output with grep if virsh succeeds. This
ensures virsh failures are explicitly caught before attempting to process
output.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 246a485b-d09a-43c6-957c-b8ee9d1ddada

📥 Commits

Reviewing files that changed from the base of the PR and between c96ab65 and 4f34ef4.

📒 Files selected for processing (1)
  • libvirt/tests/src/libvirt_mem.py

Comment on lines +135 to +137
vm_check = process.run("virsh list --state-running | grep -v 'Id\\|^$\\|^-'",
shell=True, ignore_status=True)
if vm_check.exit_status == 0 and vm_check.stdout_text.strip():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard command can misclassify virsh failures as “safe to proceed.”

At Line 135, the pipeline status reflects grep, not virsh. If virsh list fails, this branch can still fall through and proceed with module reload. Please split command execution so virsh failure is handled explicitly before parsing output.

Suggested fix
-                vm_check = process.run("virsh list --state-running | grep -v 'Id\\|^$\\|^-'",
-                                      shell=True, ignore_status=True)
-                if vm_check.exit_status == 0 and vm_check.stdout_text.strip():
+                vm_check = process.run("virsh list --state-running --name",
+                                       shell=True, ignore_status=True)
+                if vm_check.exit_status != 0:
+                    logging.warning("Unable to determine running VMs; skipping vhost configuration")
+                    return
+                running_vms = [name for name in vm_check.stdout_text.splitlines() if name.strip()]
+                if running_vms:
                     logging.warning("Running VMs detected, skipping vhost configuration for safety:")
-                    logging.warning("%s", vm_check.stdout_text.strip())
+                    logging.warning("%s", "\n".join(running_vms))
                     return
🧰 Tools
🪛 Ruff (0.15.15)

[error] 135-135: Function call with shell=True parameter identified, security issue

(S604)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libvirt/tests/src/libvirt_mem.py` around lines 135 - 137, The current
pipeline in the vm_check assignment combines virsh and grep in a single command,
which means the exit_status will reflect grep's result rather than virsh's
failure. If virsh list fails but grep runs against empty output without error,
the condition will incorrectly assess the situation as safe to proceed. Split
the command execution into two separate steps: first run virsh list
--state-running independently and check its exit status, then only proceed to
parse the output with grep if virsh succeeds. This ensures virsh failures are
explicitly caught before attempting to process output.

Comment on lines +148 to +166
if result.exit_status == 0:
logging.info("Successfully configured vhost max_mem_regions=512 at runtime")
verify_cmd = "cat /sys/module/vhost/parameters/max_mem_regions"
verify_result = process.run(verify_cmd, shell=True, ignore_status=True)
if verify_result.exit_status == 0:
current_value = verify_result.stdout_text.strip()
logging.info("Verified vhost max_mem_regions is set to: %s", current_value)
if current_value != "512":
logging.warning("Expected 512 but got %s", current_value)
else:
logging.debug("Could not verify vhost max_mem_regions setting")
else:
logging.warning("Failed to configure vhost at runtime: %s",
result.stderr_text)
else:
logging.debug("Non-SLES system detected, skipping vhost configuration")

except Exception as e:
logging.warning("Error setting up vhost max_mem_regions: %s", str(e))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Setup precondition failures are downgraded to warnings, so the test can continue in invalid state.

At Line 155-156 and Line 165-166, failed verification and unexpected exceptions only log warnings. For SLES-targeted setup, this should fail/cancel the test path instead of silently continuing.

Suggested fix
-                        if current_value != "512":
-                            logging.warning("Expected 512 but got %s", current_value)
+                        if current_value != "512":
+                            test.cancel("vhost max_mem_regions verification failed: expected 512, got %s"
+                                        % current_value)
...
-                else:
-                    logging.warning("Failed to configure vhost at runtime: %s",
-                                  result.stderr_text)
+                else:
+                    test.cancel("Failed to configure vhost at runtime: %s" % result.stderr_text)
...
-        except Exception as e:
-            logging.warning("Error setting up vhost max_mem_regions: %s", str(e))
+        except Exception as e:
+            test.cancel("Error setting up vhost max_mem_regions: %s" % str(e))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if result.exit_status == 0:
logging.info("Successfully configured vhost max_mem_regions=512 at runtime")
verify_cmd = "cat /sys/module/vhost/parameters/max_mem_regions"
verify_result = process.run(verify_cmd, shell=True, ignore_status=True)
if verify_result.exit_status == 0:
current_value = verify_result.stdout_text.strip()
logging.info("Verified vhost max_mem_regions is set to: %s", current_value)
if current_value != "512":
logging.warning("Expected 512 but got %s", current_value)
else:
logging.debug("Could not verify vhost max_mem_regions setting")
else:
logging.warning("Failed to configure vhost at runtime: %s",
result.stderr_text)
else:
logging.debug("Non-SLES system detected, skipping vhost configuration")
except Exception as e:
logging.warning("Error setting up vhost max_mem_regions: %s", str(e))
if result.exit_status == 0:
logging.info("Successfully configured vhost max_mem_regions=512 at runtime")
verify_cmd = "cat /sys/module/vhost/parameters/max_mem_regions"
verify_result = process.run(verify_cmd, shell=True, ignore_status=True)
if verify_result.exit_status == 0:
current_value = verify_result.stdout_text.strip()
logging.info("Verified vhost max_mem_regions is set to: %s", current_value)
if current_value != "512":
test.cancel("vhost max_mem_regions verification failed: expected 512, got %s"
% current_value)
else:
logging.debug("Could not verify vhost max_mem_regions setting")
else:
test.cancel("Failed to configure vhost at runtime: %s" % result.stderr_text)
else:
logging.debug("Non-SLES system detected, skipping vhost configuration")
except Exception as e:
test.cancel("Error setting up vhost max_mem_regions: %s" % str(e))
🧰 Tools
🪛 Ruff (0.15.15)

[error] 151-151: Function call with shell=True parameter identified, security issue

(S604)


[warning] 165-165: Do not catch blind exception: Exception

(BLE001)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libvirt/tests/src/libvirt_mem.py` around lines 148 - 166, The verification
failure for vhost max_mem_regions configuration and the exception handler are
downgrading setup errors to warnings, allowing the test to continue in an
invalid state. When verification confirms the value is not set to "512" (around
line 155-156), raise an exception instead of just logging a warning. In the
exception handler (around line 165-166), re-raise the caught exception instead
of logging a warning and continuing, so that SLES-targeted setup failures
properly fail or cancel the test path rather than silently proceeding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant