Skip to content

Test the VM power on/off functionality and verify memory usage - #20850

Merged
shubhamsg199 merged 1 commit into
SatelliteQE:masterfrom
amolpati30:Validate_VM_power_state_and_memory_usage
Mar 9, 2026
Merged

Test the VM power on/off functionality and verify memory usage#20850
shubhamsg199 merged 1 commit into
SatelliteQE:masterfrom
amolpati30:Validate_VM_power_state_and_memory_usage

Conversation

@amolpati30

@amolpati30 amolpati30 commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

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

Add a UI-based end-to-end test that provisions a host on OpenShift Virtualization and validates VM power state and memory reporting in the compute resource view.

New Features:

  • Introduce UI-driven image-based provisioning flow for OpenShift Virtualization VMs, including verification of power state, available power actions, and memory display in the compute resource UI.

Tests:

  • Add an OpenShift Virtualization UI end-to-end test that provisions a VM via userdata image and asserts correct build status, power on/off transitions, actions, and displayed memory size under the compute resource.

@amolpati30 amolpati30 added CherryPick PR needs CherryPick to previous branches AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing 6.19.z labels Feb 24, 2026
@sourcery-ai

sourcery-ai Bot commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a new UI end-to-end test for OpenShift Virtualization image-based provisioning that creates a host via the Foreman UI, verifies successful installation, and validates VM power state transitions, available power actions, and reported memory in the compute resource view, while slightly cleaning up the existing API test docstring spacing.

File-Level Changes

Change Details Files
Introduce a UI-based end-to-end test that provisions an OCP-V VM via the Host creation workflow and validates its power state, actions, and memory reporting in the compute resource UI.
  • Add new pytest e2e test for userdata image provisioning via UI for OpenShift Virtualization compute resources
  • Create a userdata provisioning template via API, associate it with the OS, and set it as an OS default template used during host provisioning
  • Use a UI session to create a host with specific CPU, memory, storage, image, and networking parameters on the OCP-V compute resource
  • Wait for the host build to complete and assert the host status is Installed via the API
  • Query the compute resource UI grid to assert initial VM power state is On, available action is Power Off, and displayed memory matches the configured value in GB
  • Trigger a VM power off action via the compute resource UI and assert the VM Power field changes to Off and the Actions field changes to Power On
  • Register a finalizer to delete the provisioned host via API as teardown
tests/foreman/ui/test_computeresource_ocpv.py
Minor cleanup of an existing API-based OCP-V end-to-end test docstring.
  • Remove an extra blank line from the docstring of the API-based userdata image provisioning end-to-end test
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 left some high level feedback:

  • You call session.computeresource.search_virtual_machine(cr.name, host.name)[0] multiple times in succession; consider assigning this to a local variable to avoid repeated lookups and make the assertions easier to read.
  • The test relies on hardcoded UI text values like 'On', 'Off', 'Power On', and 'Power Off'; consider centralizing these as constants or using higher-level helpers so the test is less brittle to minor UI wording changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You call `session.computeresource.search_virtual_machine(cr.name, host.name)[0]` multiple times in succession; consider assigning this to a local variable to avoid repeated lookups and make the assertions easier to read.
- The test relies on hardcoded UI text values like `'On'`, `'Off'`, `'Power On'`, and `'Power Off'`; consider centralizing these as constants or using higher-level helpers so the test is less brittle to minor UI wording changes.

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 +202 to +205
with session:
session.organization.select(org_name=module_org.name)
session.location.select(loc_name=module_location.name)
# The VM appears in the compute resource with correct power state (On)

@Gauravtalreja1 Gauravtalreja1 Feb 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is API test module, so I feel it should be wise to create UI test module to cover this scenario along with provisioning

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried using the API, but it appears that the API call is not working:
PUT /api/compute_resources/:id/available_virtual_machines/:vm_id/power

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.

Which compute resource is it? If it's not working we should fix it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@stejskalleos it is kubevirt

@evgeni evgeni Mar 4, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You don't say what "is not working", but I have a hunch that theforeman/foreman#10889 will fix the issue if the API was returning a 404 on that PUT request you tried.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@evgeni I tested your patch. It is now displaying the VM information correctly, which is good. However, the power action is still not being executed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I used hammer compute-resource virtual-machine power --id 1 --vm-id <id> and it worked on my instance.
What was the error you were getting?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is working now. I think I was trying it on an older machine earlier.

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14423
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/api/test_computeresource_ocpv.py -k test_positive_userdata_image_provision_end_to_end --external-logging --include-onprem-provisioning
Test Result : =========== 1 failed, 37 deselected, 6 warnings in 967.36s (0:16:07) ===========

@Satellite-QE Satellite-QE added the PRT-Failed Indicates that latest PRT run is failed for the PR label Feb 24, 2026
@amolpati30
amolpati30 force-pushed the Validate_VM_power_state_and_memory_usage branch 2 times, most recently from e296e90 to be6739b Compare February 24, 2026 11:31
@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14425
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/api/test_computeresource_ocpv.py -k test_positive_userdata_image_provision_end_to_end --external-logging --include-onprem-provisioning
Test Result : ========== 1 failed, 37 deselected, 9 warnings in 1072.94s (0:17:52) ===========

@amolpati30
amolpati30 force-pushed the Validate_VM_power_state_and_memory_usage branch from be6739b to 8b9b307 Compare February 26, 2026 15:21
@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14515
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, 6 warnings in 7488.91s (2:04:48) ==================

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14519
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 1237.34s (0:20:37) ==================

@amolpati30
amolpati30 marked this pull request as draft February 27, 2026 08:13
@amolpati30
amolpati30 force-pushed the Validate_VM_power_state_and_memory_usage branch 2 times, most recently from 593da29 to 8acb372 Compare February 27, 2026 09:49
@amolpati30
amolpati30 marked this pull request as ready for review February 27, 2026 10:01

@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 left some high level feedback:

  • The test calls session.computeresource.search_virtual_machine(...) multiple times with identical arguments; consider querying once per state (initial, after poweroff) and reusing the result to simplify the assertions and reduce UI calls.
  • The hard-coded storage_class value ('trident-nfs (csi.trident.netapp.io)') makes the test tightly coupled to a specific environment; consider sourcing this from configuration or a fixture so the test can run against different OCPV setups.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The test calls `session.computeresource.search_virtual_machine(...)` multiple times with identical arguments; consider querying once per state (initial, after poweroff) and reusing the result to simplify the assertions and reduce UI calls.
- The hard-coded `storage_class` value (`'trident-nfs (csi.trident.netapp.io)'`) makes the test tightly coupled to a specific environment; consider sourcing this from configuration or a fixture so the test can run against different OCPV setups.

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.

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14529
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 1266.18s (0:21:06) ==================

@amolpati30
amolpati30 force-pushed the Validate_VM_power_state_and_memory_usage branch from 8acb372 to f6c8605 Compare February 27, 2026 10:39
@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14531
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 : ================== 12 warnings, 1 error in 9351.22s (2:35:51) ==================

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14541
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, 6 warnings in 1182.59s (0:19:42) ==================

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14543
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 1342.97s (0:22:22) ==================

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14546
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 1239.90s (0:20:39) ==================

@amolpati30
amolpati30 force-pushed the Validate_VM_power_state_and_memory_usage branch from f6c8605 to a6dea7c Compare March 1, 2026 10:20
@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14548
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 2603.41s (0:43:23) ==================

@amolpati30
amolpati30 force-pushed the Validate_VM_power_state_and_memory_usage branch from e570f1f to c81f868 Compare March 4, 2026 17:04
@Satellite-QE Satellite-QE removed the PRT-Passed Indicates that latest PRT run is passed for the PR label Mar 4, 2026
@amolpati30 amolpati30 added the PRT-Passed Indicates that latest PRT run is passed for the PR label Mar 4, 2026
Comment thread tests/foreman/ui/test_computeresource_ocpv.py
Comment thread tests/foreman/ui/test_computeresource_ocpv.py Outdated
Comment on lines +112 to +114
host_api = sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})
if host_api:
request.addfinalizer(host_api[0].delete)

@shubhamsg199 shubhamsg199 Mar 6, 2026

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.

You can just use existing provisioning cleanup finalizer which does the same
request.addfinalizer(lambda: sat.provisioning_cleanup(host.name))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed above part again because the tests were failing. With the previous change, the tests are now passing. ✅

Comment thread tests/foreman/ui/test_computeresource_ocpv.py Outdated
@amolpati30
amolpati30 force-pushed the Validate_VM_power_state_and_memory_usage branch from c81f868 to d7529ab Compare March 6, 2026 14:18
@Satellite-QE Satellite-QE removed the PRT-Passed Indicates that latest PRT run is passed for the PR label Mar 6, 2026
@amolpati30
amolpati30 requested a review from shubhamsg199 March 6, 2026 14:18

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

Ack, pending PRT results

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14645
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, 6 warnings in 8069.12s (2:14:29) ==================

@Satellite-QE Satellite-QE added the PRT-Failed Indicates that latest PRT run is failed for the PR label Mar 6, 2026
@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14647
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 : 2026-03-06 17:35:42 - robottelo - ERROR - Test phase teardown failed for test: tests/foreman/ui/test_computeresource_ocpv.py::test_positive_userdata_image_provision_end_to_end[destroy_vm_on_host_delete=True]

@sambible

sambible commented Mar 9, 2026

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: 2327

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

ACK, pending PRT. I re-kicked it.

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14653
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 : 2026-03-09 04:08:37 - robottelo - ERROR - Test phase teardown failed for test: tests/foreman/ui/test_computeresource_ocpv.py::test_positive_userdata_image_provision_end_to_end[destroy_vm_on_host_delete=True]

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14657
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 : 2026-03-09 08:50:34 - robottelo - ERROR - Test phase teardown failed for test: tests/foreman/ui/test_computeresource_ocpv.py::test_positive_userdata_image_provision_end_to_end[destroy_vm_on_host_delete=True]

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14658
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 : 2026-03-09 09:50:00 - robottelo - ERROR - Test phase teardown failed for test: tests/foreman/ui/test_computeresource_ocpv.py::test_positive_userdata_image_provision_end_to_end[destroy_vm_on_host_delete=True]

@amolpati30
amolpati30 force-pushed the Validate_VM_power_state_and_memory_usage branch from d7529ab to f071913 Compare March 9, 2026 11:17
@amolpati30

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

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14661
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 1491.53s (0:24:51) ==================

@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 9, 2026
@amolpati30
amolpati30 requested a review from shubhamsg199 March 9, 2026 12:12

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

Ack

@shubhamsg199
shubhamsg199 merged commit 9d843f7 into SatelliteQE:master Mar 9, 2026
12 checks passed
github-actions Bot pushed a commit that referenced this pull request Mar 9, 2026
Test the VM power on/off functionality and verify memory usage during the operation.

(cherry picked from commit 9d843f7)
amolpati30 added a commit that referenced this pull request Mar 12, 2026
Test the VM power on/off functionality and verify memory usage during the operation.

(cherry picked from commit 9d843f7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.19.z AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing CherryPick PR needs 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.

8 participants