Skip to content

WIP: Use PowerShell ProcessorCount for Windows CPU hotplug verification #4753

Open
SamAlber wants to merge 1 commit intoRedHatQE:mainfrom
SamAlber:fix-windows-cpu-count-after-hotplug
Open

WIP: Use PowerShell ProcessorCount for Windows CPU hotplug verification #4753
SamAlber wants to merge 1 commit intoRedHatQE:mainfrom
SamAlber:fix-windows-cpu-count-after-hotplug

Conversation

@SamAlber
Copy link
Copy Markdown
Contributor

@SamAlber SamAlber commented May 5, 2026

%NUMBER_OF_PROCESSORS% is an inherited environment variable from the parent process (sshd). After CPU hotplug, sshd retains the stale boot-time value, causing SSH commands to report fewer CPUs than actually available.

Replace with [Environment]::ProcessorCount which queries the kernel directly via GetSystemInfo, reliably reflecting hotplugged CPUs.

This aligns with the Linux scenario that uses nproc (kernel query) on Linux rather than environment variables.

Short description:
More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
jira-ticket:

Summary by CodeRabbit

  • Bug Fixes
    • Improved processor count detection on Windows virtual machines using a more reliable system detection method.

%NUMBER_OF_PROCESSORS% is an inherited environment variable from the
parent process (sshd). After CPU hotplug, sshd retains the stale boot-time
value, causing SSH commands to report fewer CPUs than actually available.

Replace with [Environment]::ProcessorCount which queries the kernel
directly via GetSystemInfo, reliably reflecting hotplugged CPUs.

This aligns with how kubevirt's own tests use nproc (kernel query)
on Linux rather than environment variables.

Signed-off-by: Samuel Albershtein <salbersh@redhat.com>
@openshift-virtualization-qe-bot-3
Copy link
Copy Markdown
Contributor

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: A tracking issue is created for this PR and will be closed when the PR is merged or closed
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified
  • Labels: Enabled categories: branch, can-be-merged, cherry-pick, has-conflicts, hold, needs-rebase, size, verified, wip

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status
  • /reprocess - Trigger complete PR workflow reprocessing (useful if webhook failed or configuration changed)
  • /regenerate-welcome - Regenerate this welcome message

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest build-container - Rebuild and test container image
  • /retest verify-bugs-are-open - verify-bugs-are-open
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 2 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No wip, hold, has-conflicts labels and PR must be mergeable (no conflicts)
  5. Verified: PR must be marked as verified

📊 Review Process

Approvers and Reviewers

Approvers:

  • dshchedr
  • myakove
  • rnetser
  • vsibirsk

Reviewers:

  • RoniKishner
  • dshchedr
  • rnetser
  • vsibirsk
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
AI Features
  • Cherry-Pick Conflict Resolution: Enabled (claude/claude-opus-4-6[1m])

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is removed on new commits unless the push is detected as a clean rebase
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

@SamAlber
Copy link
Copy Markdown
Contributor Author

SamAlber commented May 5, 2026

/build-and-push-container

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

📝 Walkthrough

Walkthrough

The PR updates Windows CPU count detection in test utilities from batch-style environment variable echoing to a PowerShell command for improved reliability on modern Windows systems.

Changes

Windows CPU Detection Method

Layer / File(s) Summary
Core Implementation
tests/utils.py
get_os_cpu_count() Windows branch replaces echo %NUMBER_OF_PROCESSORS% with powershell.exe -command "[Environment]::ProcessorCount" for more reliable processor count retrieval.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes


Review notes

Why PowerShell over batch environment variables?

The original approach (%NUMBER_OF_PROCESSORS%) relies on a batch-style environment variable that may be unset or unreliable in containerized or virtualized Windows environments, especially in CI/VM contexts. PowerShell's [Environment]::ProcessorCount is:

  • Direct system API access — queries the runtime environment directly rather than relying on inherited shell state
  • Consistent across contexts — works reliably in VMs, containers, and modern Windows builds
  • Standard Windows tooling — PowerShell is built-in and ubiquitous on modern Windows

No risks identified: Single-line substitution with clear intent; no new dependencies or side effects.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description provides technical context but doesn't follow the required template structure with all specified sections. Fill in the empty template sections: 'Short description', 'More details', 'Which issue(s) this PR fixes', and 'jira-ticket'. The technical explanation exists but needs proper organization into template format.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and specifically describes the main change: replacing %NUMBER_OF_PROCESSORS% with PowerShell's ProcessorCount for Windows CPU hotplug verification, which is the core modification shown in the raw summary.

✏️ 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


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.

Copy link
Copy Markdown
Contributor

@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)
tests/utils.py (1)

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

HIGH: PR template required sections appear missing in the PR description.

The provided PR metadata does not include the required template headers (What this PR does / why we need it, Which issue(s) this PR fixes, Special notes for reviewer, jira-ticket). Please restore the template sections (with meaningful content for the first one) to satisfy repo policy and keep review/automation consistent.

As per coding guidelines, required PR template sections must be present, and What this PR does / why we need it: must contain meaningful content.

🤖 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 `@tests/utils.py` at line 1, The PR description is missing required template
sections; update the PR description to include the headers "What this PR does /
why we need it", "Which issue(s) this PR fixes", "Special notes for reviewer",
and "jira-ticket" and provide meaningful content under "What this PR does / why
we need it" (summarize the change and rationale), fill "Which issue(s) this PR
fixes" with relevant issue IDs, add any review notes under "Special notes for
reviewer", and include the ticket identifier under "jira-ticket" so the repo
automation and reviewers can validate the PR.
🤖 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 `@tests/utils.py`:
- Line 1: The PR description is missing required template sections; update the
PR description to include the headers "What this PR does / why we need it",
"Which issue(s) this PR fixes", "Special notes for reviewer", and "jira-ticket"
and provide meaningful content under "What this PR does / why we need it"
(summarize the change and rationale), fill "Which issue(s) this PR fixes" with
relevant issue IDs, add any review notes under "Special notes for reviewer", and
include the ticket identifier under "jira-ticket" so the repo automation and
reviewers can validate the PR.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 37fd041b-a754-4783-878e-3fe1fa97c387

📥 Commits

Reviewing files that changed from the base of the PR and between b6372ab and a152e67.

📒 Files selected for processing (1)
  • tests/utils.py

@openshift-virtualization-qe-bot-4
Copy link
Copy Markdown

New container for quay.io/openshift-cnv/openshift-virtualization-tests:pr-4753 published

@SamAlber
Copy link
Copy Markdown
Contributor Author

SamAlber commented May 5, 2026

/verified

-k "test_hotplug_cpu and WIN-VM"

@openshift-virtualization-qe-bot-3
Copy link
Copy Markdown
Contributor

@coderabbitai

Test execution plan request details

CRITICAL: You MUST post an inline review comment on the first changed line of the first file.
The inline comment should contain the Test Execution Plan with the smoke tests recommendation.
Do NOT submit a formal review - just post the inline comment directly.

As an expert software testing engineer, analyze all modified files in this PR and create a targeted test execution plan.
You will post an inline review comment with the test execution plan on the first changed file.
If you fail to run or post a comment, retry.

Analysis Requirements:

  1. Examine code changes in each modified file
  2. Identify affected code paths, functions, and classes
  3. Analyze pytest-specific elements: fixtures (scope, dependencies), parametrization, markers, conftest changes
  4. Trace test dependencies through imports, shared utilities, and fixture inheritance
  5. Detect new tests introduced in the PR
  6. Smoke Test Impact Analysis: Determine if any changes could affect smoke tests by checking:
    • Changes to files/functions used by tests marked with @pytest.mark.smoke
    • Changes to fixtures or utilities imported by smoke tests
    • Changes to conftest.py files that may affect smoke test execution
    • Changes to core infrastructure code (utilities/, libs/) that smoke tests depend on

Your deliverable:
Your change request comment will be based on the following requirements:

Test Execution Plan

  • Run smoke tests: True / False (Based on your smoke test impact analysis - True if any changes may affect smoke tests)
  • path/to/test_file.py - When the entire test file needs verification
  • path/to/test_file.py::TestClass::test_method - When specific test(s) needed
  • path/to/test_file.py::test_function - When specific test(s) needed
  • -m marker - When specific marker(s) can be used to cover multiple cases.

Guidelines:

  • Include only tests directly affected by the changes
  • Use a full file path only if ALL tests in that file require verification
  • Use file path + test name if only specific tests are needed
  • If a test marker can cover multiple files/tests, provide the marker
  • Balance coverage vs over-testing - Keep descriptions minimal

Hardware-Related Checks (SR-IOV, GPU, DPDK):

When PR modifies fixtures for hardware-specific resources:

  • Collection Safety: Fixtures MUST have existence checks (return None when hardware unavailable)
  • Test Plan: MUST verify both WITH and WITHOUT hardware:
    • Run affected tests on cluster WITH hardware
    • Verify collection succeeds on cluster WITHOUT hardware

CRITICAL WORKFLOW COMPLETION RULES:

When responding to this test execution plan request, you MUST follow these rules EXACTLY:

  1. YOUR ONLY DELIVERABLE: Post an inline review comment containing the test execution plan on the first changed line
  2. THEN STOP IMMEDIATELY - Do NOT generate any additional response
  3. FALLBACK ONLY: If submitting the review fails after retrying, post as a regular PR comment
  4. SILENCE = SUCCESS: After successfully submitting the review, your task is complete. No confirmation needed.

ABSOLUTE PROHIBITIONS (violating these creates empty/meaningless reviews):

  • ❌ Do NOT post acknowledgment messages like "Test execution plan posted", "Review posted successfully", "I've successfully posted"
  • ❌ Do NOT mention review IDs, URLs, or confirmation of posting in the PR thread
  • ❌ Do NOT add any follow-up comments after submitting the review
  • ❌ Do NOT reply to confirm task completion
  • ❌ Do NOT explain what you did - just do it and stop

Remember: The pull request review is visible to users. Additional comments are redundant noise.

CRITICAL: Before setting "Run smoke tests: True", you MUST use shell scripts to:
- Trace the actual fixture dependency chain from smoke tests to changed fixtures
- Verify that smoke tests actually import/use changed utilities or functions
- Confirm the dependency path exists; do NOT assume based on scope or semantics
- Be conservative: Session-scoped fixtures or infrastructure-sounding names do NOT
automatically mean smoke test impact. Only flag smoke test impact when you can
demonstrate a concrete dependency path.
WRONG: "This session-scoped storage fixture might affect smoke tests"
RIGHT: "Smoke test X uses fixture Y, which depends on the changed fixture Z"

Comment thread tests/utils.py
def get_os_cpu_count(vm):
if "windows" in vm.name:
cmd = shlex.split("echo %NUMBER_OF_PROCESSORS%")
cmd = shlex.split('powershell.exe -command "[Environment]::ProcessorCount"')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test Execution Plan

Run smoke tests: False
(No dependency path found from any @pytest.mark.smoke test to get_os_cpu_count in tests/utils.py)

Affected Tests

The change only affects the Windows VM branch of get_os_cpu_count. Target Windows CPU hotplug tests specifically:

  • tests/virt/node/hotplug/test_cpu_memory_hotplug.py — filter with -k "test_hotplug_cpu and WIN"
  • tests/infrastructure/instance_types/test_cpu_memory_hotplug_instancetype.py::TestCPUHotPlugInstanceType::test_hotplug_cpu_instance_type
  • tests/virt/node/migration_and_maintenance/test_post_copy_migration.py — filter with -k "test_hotplug_cpu and WIN"

Note: Linux VMs are unaffected (the else: nproc branch is unchanged).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find the get_os_cpu_count function and the changed line
rg -n "get_os_cpu_count\|NUMBER_OF_PROCESSORS\|ProcessorCount" --type py -C3

echo "---SMOKE TESTS---"
# Find smoke test markers and check if they use get_os_cpu_count
rg -n "pytest.mark.smoke" --type py -l

echo "---HOTPLUG CPU TESTS---"
# Find CPU hotplug tests that call get_os_cpu_count
rg -n "get_os_cpu_count\|hotplug_cpu\|hotplug.*cpu\|cpu.*hotplug" --type py -l

echo "---WINDOWS CPU HOTPLUG TEST FILE---"
# Find test files for Windows CPU hotplug
fd -e py | xargs grep -l "hotplug.*cpu\|cpu.*hotplug\|WIN.*CPU\|cpu.*WIN" 2>/dev/null | head -20

Unrecoverable error: Failed to clone repository


🏁 Script executed:

#!/bin/bash
# Get the PR diff to find changed line numbers and files
gh pr diff 4753 --repo RedHatQE/openshift-virtualization-tests

Length of output: 511


🏁 Script executed:

#!/bin/bash
# Search for usages of get_os_cpu_count and smoke test markers in the repo
gh search code "get_os_cpu_count" --repo RedHatQE/openshift-virtualization-tests --json path,textMatches

echo "---SMOKE TEST SEARCH---"
gh search code "mark.smoke" --repo RedHatQE/openshift-virtualization-tests --json path,textMatches | head -100

echo "---CPU HOTPLUG TEST FILES---"
gh search code "hotplug_cpu" --repo RedHatQE/openshift-virtualization-tests --json path,textMatches | head -100

Length of output: 8353


🏁 Script executed:

#!/bin/bash
# Post inline review comment on the changed line in tests/utils.py
# The changed line is line 212 in the new file (patch position 4)
gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  repos/RedHatQE/openshift-virtualization-tests/pulls/4753/reviews \
  --field body="" \
  --field event="COMMENT" \
  --field "comments[][path]=tests/utils.py" \
  --field "comments[][line]=212" \
  --field "comments[][side]=RIGHT" \
  --field "comments[][body]=## Test Execution Plan

**Run smoke tests: False**
_(No dependency path found from any \`@pytest.mark.smoke\` test to \`get_os_cpu_count\` in \`tests/utils.py\`)_

### Affected Tests

The change only affects the **Windows VM branch** of \`get_os_cpu_count\`. Target Windows CPU hotplug tests specifically:

- \`tests/virt/node/hotplug/test_cpu_memory_hotplug.py\` — filter with \`-k \"test_hotplug_cpu and WIN\"\`
- \`tests/infrastructure/instance_types/test_cpu_memory_hotplug_instancetype.py::TestCPUHotPlugInstanceType::test_hotplug_cpu_instance_type\`
- \`tests/virt/node/migration_and_maintenance/test_post_copy_migration.py\` — filter with \`-k \"test_hotplug_cpu and WIN\"\`

> **Note:** Linux VMs are unaffected (the \`else: nproc\` branch is unchanged)."

Length of output: 1735


@SamAlber
Copy link
Copy Markdown
Contributor Author

SamAlber commented May 5, 2026

/wip

need one more investigation

@openshift-virtualization-qe-bot openshift-virtualization-qe-bot changed the title Use PowerShell ProcessorCount for Windows CPU hotplug verification WIP: Use PowerShell ProcessorCount for Windows CPU hotplug verification May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants