Skip to content

Conversation

@liang-cong-red-hat
Copy link
Contributor

@liang-cong-red-hat liang-cong-red-hat commented Dec 23, 2025

  1. Add _parse_version function to convert 'x.x.x' to integer tuple;
  2. Enhance version comparison logic for machine type pc-q35-rhel9.6.0+;

Before fix: test case may fail for "Test failed as the q35_max_vcpus_num for machine type:pc-q35-rhel9.8.0 in virsh_capa is wrong. Expected: 710, Actual: 4096."

After fix:
(1/1) type_specific.io-github-autotest-libvirt.max_vcpus.virsh_capabilities: STARTED
(1/1) type_specific.io-github-autotest-libvirt.max_vcpus.virsh_capabilities: PASS (6.28 s)

Summary by CodeRabbit

  • Tests
    • Improved CPU vCPU detection tests with robust parsing of pc-q35-rhel version strings and stricter validation for malformed versions.
    • Generalized handling for newer pc-q35-rhel releases (≥ 9.6.0) while preserving special-case behavior for known older versions.
    • Added clearer test reporting and minimal error handling/logging for version-related decisions.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 23, 2025

Walkthrough

The change modifies a single test file to add regex-based version parsing and handling for QEMU machine-type keys. It introduces helper _parse_version(version_str) that converts x.y.z into an integer tuple and enforces three components. In the virsh_capabilities path, keys beginning with pc-q35-rhel are parsed and compared against version (9,6,0) to select expected values while preserving the special-case for pc-q35-rhel7.3.0; a separate q35 key path remains. Minor inline logging and test-error reporting were added for parsing failures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly reflects the main change: adding version parsing and conditional logic for pc-q35-rhel machine types, which matches the PR objectives and file modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
libvirt/tests/src/cpu/max_vcpus.py (1)

125-135: Consider simplifying version validation logic.

The control flow is correct, but there's a minor redundancy: if you add proper error handling to _parse_version() (as suggested in the earlier comment), the len(version) != 3 check on lines 128-129 becomes unreachable for invalid versions, since _parse_version() would raise an exception first.

You can either:

  1. Remove lines 128-129 entirely and rely on _parse_version() to validate the format, or
  2. Keep it as a defensive assertion for future safety
Option 1: Remove redundant check (preferred if _parse_version has error handling)
                 if key.startswith('pc-q35-rhel'):
                     version_str = key.replace('pc-q35-rhel', '')
                     version = _parse_version(version_str)
-                    if len(version) != 3:
-                        test.error('version of machine type is not expected as x.x.x but %s' % version_str)
                 if key == "pc-q35-rhel7.3.0":
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 838e067 and 8c359b0.

📒 Files selected for processing (1)
  • libvirt/tests/src/cpu/max_vcpus.py
🧰 Additional context used
🪛 Gitleaks (8.30.0)
libvirt/tests/src/cpu/max_vcpus.py

[high] 130-130: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.8
  • GitHub Check: Python 3.9
🔇 Additional comments (1)
libvirt/tests/src/cpu/max_vcpus.py (1)

2-2: LGTM!

The regex module import is appropriate for the version parsing functionality added in this PR.

@liang-cong-red-hat liang-cong-red-hat force-pushed the max_vcpus_add_adaption_for_higher_q35_machine branch from 8c359b0 to f1a6e85 Compare December 23, 2025 03:32
Copy link

@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.

Actionable comments posted: 1

♻️ Duplicate comments (1)
libvirt/tests/src/cpu/max_vcpus.py (1)

64-73: Missing error handling for regex match failure (previously flagged).

This issue was already identified in a previous review: if re.search returns None (when the version string doesn't match the expected pattern, such as "9.6", "9", or non-numeric versions), the code will raise AttributeError when calling matches.groups(). Please add a check after re.search to handle this case.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c359b0 and f1a6e85.

📒 Files selected for processing (1)
  • libvirt/tests/src/cpu/max_vcpus.py
🧰 Additional context used
🪛 Gitleaks (8.30.0)
libvirt/tests/src/cpu/max_vcpus.py

[high] 130-130: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Python 3.9
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.8
🔇 Additional comments (1)
libvirt/tests/src/cpu/max_vcpus.py (1)

125-146: Version comparison logic is sound.

The implementation correctly handles different pc-q35-rhel machine type versions:

  • Version parsing is only attempted for keys starting with 'pc-q35-rhel' (line 125)
  • Special case for pc-q35-rhel7.3.0 is preserved (line 130)
  • New generalized comparison for version >= 9.6.0 addresses the issue described in the PR objectives (line 134)
  • Short-circuit evaluation at line 134 prevents NameError by only accessing version when it's guaranteed to be defined
  • Fallback to libvirt version comparisons handles older machine types appropriately

The approach aligns well with the stated goal of fixing incorrect q35_max_vcpus_num reporting for newer RHEL versions.

…achine types

1. Add _parse_version function to convert 'x.x.x' to integer tuple;
2. Enhance version comparison logic for machine type pc-q35-rhel9.6.0+;

Signed-off-by: Liang Cong <lcong@redhat.com>
@liang-cong-red-hat liang-cong-red-hat force-pushed the max_vcpus_add_adaption_for_higher_q35_machine branch from f1a6e85 to bf0cac8 Compare December 23, 2025 03:49
Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
libvirt/tests/src/cpu/max_vcpus.py (1)

127-135: Consider checking special case before parsing version.

The code is functionally correct, but for the special case "pc-q35-rhel7.3.0" (line 130), the version is parsed on line 129 but never used. While this doesn't affect correctness, checking the special case before parsing would avoid unnecessary work.

💡 Optional refactor to improve efficiency
                if key.startswith('pc-q35') or key == 'q35':
                    exp_val = report_num_q35_7_8
-                    if key.startswith('pc-q35-rhel'):
-                        version_str = key.replace('pc-q35-rhel', '')
-                        version = _parse_version(version_str)
                    if key == "pc-q35-rhel7.3.0":
                        exp_val = report_num_q35_73
                    elif key == 'q35':
                        exp_val = report_num_q35_9_6
                    elif key.startswith('pc-q35-rhel'):
+                        version_str = key.replace('pc-q35-rhel', '')
+                        version = _parse_version(version_str)
-                    elif key.startswith('pc-q35-rhel') and version >= (9, 6, 0):
+                        if version >= (9, 6, 0):
-                        exp_val = report_num_q35_9_6
+                            exp_val = report_num_q35_9_6
+                        else:
+                            if libvirt_version.version_compare(7, 0, 0):
+                                exp_val = report_num_q35_8_4
+                            elif libvirt_version.version_compare(6, 6, 0):
+                                exp_val = report_num_q35_8_3
                    else:
                        if libvirt_version.version_compare(7, 0, 0):
                            exp_val = report_num_q35_8_4
                        elif libvirt_version.version_compare(6, 6, 0):
                            exp_val = report_num_q35_8_3
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1a6e85 and bf0cac8.

📒 Files selected for processing (1)
  • libvirt/tests/src/cpu/max_vcpus.py
🧰 Additional context used
🪛 Gitleaks (8.30.0)
libvirt/tests/src/cpu/max_vcpus.py

[high] 130-130: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Python 3.9
  • GitHub Check: Python 3.8
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.11
🔇 Additional comments (3)
libvirt/tests/src/cpu/max_vcpus.py (3)

2-2: LGTM!

The re module import is properly added to support version parsing.


64-75: LGTM!

The version parsing function is well-implemented with proper error handling. The check for None return from re.search (line 73-74) addresses the concern raised in the previous review, ensuring malformed version strings produce clear error messages rather than AttributeError.


130-130: Static analysis false positive.

The Gitleaks warning on line 130 is a false positive. The string "pc-q35-rhel7.3.0" is a QEMU machine type identifier, not an API key.

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