Skip to content

[6.19.z] Test the VM power on/off functionality and verify memory usage - #20974

Merged
Satellite-QE merged 1 commit into
6.19.zfrom
cherry-pick-6.19.z-9d843f762bdb59ab3d98cdb1c21fd82a57ff91bd
Mar 12, 2026
Merged

[6.19.z] Test the VM power on/off functionality and verify memory usage#20974
Satellite-QE merged 1 commit into
6.19.zfrom
cherry-pick-6.19.z-9d843f762bdb59ab3d98cdb1c21fd82a57ff91bd

Conversation

@Satellite-QE

@Satellite-QE Satellite-QE commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator

Cherrypick of PR: #20850

Problem Statement

The VM was not displaying the correct power state (on/off), and the memory value was also not shown correctly.

Solution

After the fix, the VMs are showing the correct state. When the VM is powered on, it displays the correct memory value. However, when the VM is powered off, the memory value is not shown correctly. This behavior was already mentioned in the PR, and the developer is aware of the issue. At the moment, this is not a blocker for us.

Also adding end-to-end OCP image-based provisioning.

Summary by Sourcery

Extend OpenShift Virtualization end-to-end userdata image provisioning test to validate VM power state and memory reporting in the compute resource UI.

New Features:

  • Add UI-based validation of VM power state, available power actions, and memory allocation after provisioning an OpenShift Virtualization VM.

Tests:

  • Enhance the OpenShift Virtualization end-to-end provisioning test to assert correct VM power on/off state transitions, available actions, and displayed memory size in the compute resource UI.
  • Parameterize the test with a session fixture to drive UI interactions during VM state and memory verification.

Summary by Sourcery

Tests:

  • Introduce a UI-based OpenShift Virtualization userdata image provisioning test that provisions a host via image, waits for installation, and verifies VM power on/off state, available actions, and displayed memory size under the compute resource.

@Satellite-QE Satellite-QE added 6.19.z Auto_Cherry_Picked Automatically cherrypicked PR using GHA No-CherryPick PR doesnt need CherryPick to previous branches labels Mar 9, 2026
@Satellite-QE Satellite-QE added the AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing label Mar 9, 2026
@sourcery-ai

sourcery-ai Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a new end-to-end UI test that provisions an OpenShift Virtualization VM via image-based provisioning and validates VM power state transitions, available actions, and memory usage reporting in the compute resource view, including userdata template setup via API.

File-Level Changes

Change Details Files
Introduce UI-based end-to-end OCP-V image provisioning test that covers VM power state and memory reporting in the compute resource.
  • Add a pytest e2e UI test that provisions a host on OpenShift Virtualization using image-based provisioning and a generated userdata template.
  • Create the userdata provisioning template and associate it with the OS via API before running the UI flow.
  • Use a UI session to create the host with specific VM CPU, memory, storage, image, and networking parameters, then wait for installation to complete.
  • Verify compute resource VM table shows correct initial power state, available power action, and memory in GB, and that power off action updates state and available action accordingly.
  • Register test teardown to delete the provisioned host via API.
tests/foreman/ui/test_computeresource_ocpv.py
Minor cleanup of existing API-based OCP-V provisioning test docstring.
  • Remove an extraneous blank line in the existing API-based userdata image provisioning test docstring.
tests/foreman/api/test_computeresource_ocpv.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've found 1 issue, and left some high level feedback:

  • The wait_for and search calls assume at least one host is always returned (e.g. ...search(...)[0]), which can raise IndexError and make the test flaky; consider asserting the list is non-empty or using wait_for to guard against empty responses before indexing.
  • After calling vm_poweroff, the test immediately asserts the new power state without any retry or wait; wrapping the search_virtual_machine for the power-off verification in a wait_for would make the test more robust against UI/API propagation delays.
  • The memory check uses round(memory_in_gb) and string comparison to '6 GB'; tying the assertion directly to the configured MB value (e.g. computing the expected display format from API/CR settings) would reduce brittleness if the UI changes its rounding or unit display.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `wait_for` and `search` calls assume at least one host is always returned (e.g. `...search(...)[0]`), which can raise `IndexError` and make the test flaky; consider asserting the list is non-empty or using `wait_for` to guard against empty responses before indexing.
- After calling `vm_poweroff`, the test immediately asserts the new power state without any retry or wait; wrapping the `search_virtual_machine` for the power-off verification in a `wait_for` would make the test more robust against UI/API propagation delays.
- The memory check uses `round(memory_in_gb)` and string comparison to `'6 GB'`; tying the assertion directly to the configured MB value (e.g. computing the expected display format from API/CR settings) would reduce brittleness if the UI changes its rounding or unit display.

## Individual Comments

### Comment 1
<location path="tests/foreman/ui/test_computeresource_ocpv.py" line_range="117-120" />
<code_context>
+        if host_api:
+            request.addfinalizer(host_api[0].delete)
+
+        wait_for(
+            lambda: (
+                sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})[0].build_status_label
+                != 'Pending installation'
+            ),
+            timeout=1500,
</code_context>
<issue_to_address>
**issue (bug_risk):** Make the wait_for condition resilient to missing host records to avoid IndexError flakiness

The `wait_for` lambda assumes `sat.api.Host().search(...)[0]` always returns a host. If the record isn’t present yet, this raises `IndexError` and fails the test instead of retrying. Please make this more defensive by checking that the search result is non-empty before accessing `[0]`, or by catching `IndexError` and returning `False`, so `wait_for` can keep polling instead of causing flaky failures when host creation is slow.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +117 to +120
wait_for(
lambda: (
sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})[0].build_status_label
!= 'Pending installation'

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.

issue (bug_risk): Make the wait_for condition resilient to missing host records to avoid IndexError flakiness

The wait_for lambda assumes sat.api.Host().search(...)[0] always returns a host. If the record isn’t present yet, this raises IndexError and fails the test instead of retrying. Please make this more defensive by checking that the search result is non-empty before accessing [0], or by catching IndexError and returning False, so wait_for can keep polling instead of causing flaky failures when host creation is slow.

@SatelliteQE SatelliteQE deleted a comment from Satellite-QE Mar 11, 2026
@Satellite-QE

Copy link
Copy Markdown
Collaborator Author

PRT Result

Build Number: 14704
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ui/test_computeresource_ocpv.py -k test_positive_userdata_image_provision_end_to_end --external-logging --include-onprem-provisioning
Test Result : ================== 1 failed, 8 warnings in 1185.62s (0:19:45) ==================

@Satellite-QE Satellite-QE added the PRT-Failed Indicates that latest PRT run is failed for the PR label Mar 11, 2026
Test the VM power on/off functionality and verify memory usage during the operation.

(cherry picked from commit 9d843f7)
@amolpati30
amolpati30 force-pushed the cherry-pick-6.19.z-9d843f762bdb59ab3d98cdb1c21fd82a57ff91bd branch from fe0708f to 72742ef Compare March 12, 2026 08:11
@Satellite-QE

Copy link
Copy Markdown
Collaborator Author

PRT Result

Build Number: 14711
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ui/test_computeresource_ocpv.py -k test_positive_userdata_image_provision_end_to_end --external-logging --include-onprem-provisioning
Test Result : ================== 1 failed, 8 warnings in 1225.49s (0:20:25) ==================

@amolpati30

Copy link
Copy Markdown
Contributor
trigger: test-robottelo
pytest: tests/foreman/ui/test_computeresource_ocpv.py -k test_positive_userdata_image_provision_end_to_end
provisioning: true
airgun: 2337

@Satellite-QE

Copy link
Copy Markdown
Collaborator Author

PRT Result

Build Number: 14714
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_computeresource_ocpv.py -k test_positive_userdata_image_provision_end_to_end --external-logging --include-onprem-provisioning
Test Result : ================= 1 passed, 11 warnings in 1332.25s (0:22:12) ==================

@Satellite-QE Satellite-QE added PRT-Passed Indicates that latest PRT run is passed for the PR and removed PRT-Failed Indicates that latest PRT run is failed for the PR labels Mar 12, 2026
@Satellite-QE
Satellite-QE merged commit 897b480 into 6.19.z Mar 12, 2026
14 checks passed
@Satellite-QE
Satellite-QE deleted the cherry-pick-6.19.z-9d843f762bdb59ab3d98cdb1c21fd82a57ff91bd branch March 12, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.19.z Auto_Cherry_Picked Automatically cherrypicked PR using GHA AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing No-CherryPick PR doesnt need CherryPick to previous branches PRT-Passed Indicates that latest PRT run is passed for the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants