Skip to content

boot_from_cdrom_device: avoid os/boot plus cdrom boot conflict#6865

Open
BulaYoungR wants to merge 1 commit into
autotest:masterfrom
BulaYoungR:fix/boot-from-cdrom-strip-device-boot-with-os-boots
Open

boot_from_cdrom_device: avoid os/boot plus cdrom boot conflict#6865
BulaYoungR wants to merge 1 commit into
autotest:masterfrom
BulaYoungR:fix/boot-from-cdrom-strip-device-boot-with-os-boots

Conversation

@BulaYoungR
Copy link
Copy Markdown

@BulaYoungR BulaYoungR commented May 11, 2026

When os_attrs_boots is set, call remove_all_boots() before setup_attrs, and drop boot/loadparm from cdrom attr dicts so libvirt does not see per-device boot together with /boot.

Committer: Bolatbek Issakh bissakh@redhat.com

Summary by CodeRabbit

  • Bug Fixes
    • Improved boot order handling for CDROM devices to ensure operating system-level boot settings take precedence over device-level boot attributes, preventing configuration conflicts.

Review Change Stack

When os_attrs_boots is set, call remove_all_boots() before setup_attrs,
and drop boot/loadparm from cdrom attr dicts so libvirt does not see
per-device boot together with <os>/boot.

Committer: Bolatbek Issakh <bissakh@redhat.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Walkthrough

The change updates a test utility function to enforce OS-level boot configuration precedence over device-level boot settings. When os_attrs_boots is provided to update_vm_xml, the function now clears all existing boot configuration via remove_all_boots() before applying OS attributes. Additionally, it strips boot and loadparm keys from each cdrom device attribute dictionary, ensuring device-level boot settings do not conflict with OS-level boot configuration.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: preventing conflicts between OS-level boot configuration and CD-ROM device boot attributes by stripping the latter when OS boots are configured.
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.

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

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
libvirt/tests/src/guest_os_booting/boot_order/boot_from_cdrom_device.py (1)

52-52: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Replace all eval() calls with ast.literal_eval() for secure parameter parsing.

The file contains four unsafe eval() calls (lines 25, 26, 52, and 92) that can execute arbitrary code. Replace each with ast.literal_eval() to safely parse only Python literals:

Proposed fix
+import ast
 import os
 import platform
@@
-    cdrom1_attrs = eval(params.get('cdrom1_attrs', '{}'))
-    cdrom2_attrs = eval(params.get('cdrom2_attrs', '{}'))
+    try:
+        cdrom1_attrs = ast.literal_eval(params.get('cdrom1_attrs', '{}'))
+        cdrom2_attrs = ast.literal_eval(params.get('cdrom2_attrs', '{}'))
+    except (ValueError, SyntaxError) as detail:
+        test.fail(f"Invalid cdrom attrs format: {detail}")
@@
-    os_attrs_boots = eval(params.get('os_attrs_boots', '[]'))
+    try:
+        os_attrs_boots = ast.literal_eval(params.get('os_attrs_boots', '[]'))
+    except (ValueError, SyntaxError) as detail:
+        test.fail(f"Invalid os_attrs_boots format: {detail}")
@@
-    bootable_patterns = eval(params.get('bootable_patterns', '[]'))
+    try:
+        bootable_patterns = ast.literal_eval(params.get('bootable_patterns', '[]'))
+    except (ValueError, SyntaxError) as detail:
+        test.fail(f"Invalid bootable_patterns format: {detail}")
🤖 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/guest_os_booting/boot_order/boot_from_cdrom_device.py` at
line 52, Replace all unsafe eval() usages used to parse params with
ast.literal_eval to prevent arbitrary code execution: import ast at the top if
missing, then change expressions like os_attrs_boots =
eval(params.get('os_attrs_boots', '[]')) to os_attrs_boots =
ast.literal_eval(params.get('os_attrs_boots', '[]')) (and do the same for the
other three eval(params.get(...)) occurrences); ensure default strings remain
valid Python literals (e.g., '[]' or '{}' as appropriate) so ast.literal_eval
can parse them.
🤖 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.

Outside diff comments:
In `@libvirt/tests/src/guest_os_booting/boot_order/boot_from_cdrom_device.py`:
- Line 52: Replace all unsafe eval() usages used to parse params with
ast.literal_eval to prevent arbitrary code execution: import ast at the top if
missing, then change expressions like os_attrs_boots =
eval(params.get('os_attrs_boots', '[]')) to os_attrs_boots =
ast.literal_eval(params.get('os_attrs_boots', '[]')) (and do the same for the
other three eval(params.get(...)) occurrences); ensure default strings remain
valid Python literals (e.g., '[]' or '{}' as appropriate) so ast.literal_eval
can parse them.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 41516faf-e896-4580-b7c9-02595e120f8b

📥 Commits

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

📒 Files selected for processing (1)
  • libvirt/tests/src/guest_os_booting/boot_order/boot_from_cdrom_device.py

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