-
Notifications
You must be signed in to change notification settings - Fork 138
Test the VM power on/off functionality and verify memory usage #20850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shubhamsg199
merged 1 commit into
SatelliteQE:master
from
amolpati30:Validate_VM_power_state_and_memory_usage
Mar 9, 2026
+144
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| """ | ||
| :Requirement: Computeresource - OCP-V | ||
|
|
||
| :CaseAutomation: Automated | ||
|
|
||
| :CaseComponent: ComputeResources-OCP-V | ||
|
|
||
| :Team: Rocket | ||
|
|
||
| :CaseImportance: High | ||
| """ | ||
|
|
||
| import textwrap | ||
|
|
||
| from fauxfactory import gen_string | ||
| import pytest | ||
| from wait_for import wait_for | ||
|
|
||
| from robottelo.config import settings | ||
|
|
||
|
|
||
| @pytest.mark.e2e | ||
| @pytest.mark.on_premises_provisioning | ||
| @pytest.mark.parametrize('setting_update', ['destroy_vm_on_host_delete=True'], indirect=True) | ||
| def test_positive_userdata_image_provision_end_to_end( | ||
| request, | ||
| setting_update, | ||
| module_ocpv_cr, | ||
| module_ocpv_sat, | ||
| module_org, | ||
| module_location, | ||
| module_ocpv_image, | ||
| module_ocpv_hostgroup, | ||
| ): | ||
| """Provision a host on OpenShift Virtualization using image-based provisioning via UI. | ||
|
|
||
| :id: a1b2c3d4-5e6f-4a5b-8c9d-0e1f2a3b4c5d | ||
|
|
||
| :steps: | ||
| 1. Create OCP compute resource | ||
| 2. Create image for the compute resource | ||
| 3. Create userdata provisioning template and associate with OS | ||
| 4. Create hostgroup | ||
| 5. Via UI: Create host with hostgroup, deploy on OCP-V, image, and interfaces | ||
| 6. Wait for build status and verify host status is Installed | ||
| 7. Verify the VM power status and memory usage under the compute resource. | ||
|
|
||
| :expectedresults: Host is provisioned successfully on OpenShift Virtualization via UI | ||
|
|
||
| :Verifies: SAT-42060, SAT-41355 | ||
| """ | ||
| name = gen_string('alpha').lower() | ||
| sat = module_ocpv_sat | ||
| os = module_ocpv_image.os | ||
| domain_name = module_ocpv_hostgroup.domain.read().name | ||
| host_fqdn = f'{name}.{domain_name}' | ||
| memory = '6144' | ||
| memory_in_gb = int(memory) / 1024 | ||
|
|
||
| USERDATA_TEMPLATE = textwrap.dedent("""\ | ||
| #cloud-config | ||
| <%# Contact Foreman to confirm instance is built -%> | ||
| phone_home: | ||
| url: <%= foreman_url('built') %> | ||
| post: [] | ||
| tries: 10 | ||
| """) | ||
|
|
||
| # Create userdata provisioning template via API | ||
| template_kind = sat.api.TemplateKind().search(query={'search': 'name=user_data'})[0] | ||
| userdata_template = sat.api.ProvisioningTemplate( | ||
| name=gen_string('alpha'), | ||
| organization=[module_org], | ||
| location=[module_location], | ||
| snippet=False, | ||
| template_kind=template_kind, | ||
| operatingsystem=[os], | ||
| template=USERDATA_TEMPLATE, | ||
| ).create() | ||
|
|
||
| os.provisioning_template.append(userdata_template) | ||
| os.update(['provisioning_template']) | ||
| sat.api.OSDefaultTemplate( | ||
| operatingsystem=os, | ||
| provisioning_template=userdata_template, | ||
| template_kind=template_kind, | ||
| ).create() | ||
|
|
||
| with module_ocpv_sat.ui_session() as session: | ||
| session.organization.select(org_name=module_org.name) | ||
| session.location.select(loc_name=module_location.name) | ||
|
|
||
| session.host.create( | ||
| { | ||
| 'host.name': name, | ||
| 'host.hostgroup': module_ocpv_hostgroup.name, | ||
| 'provider_content.virtual_machine.cpus': '2', | ||
| 'provider_content.virtual_machine.memory': memory, | ||
| 'provider_content.virtual_machine.startup': True, | ||
| 'provider_content.storage.storage_class': 'trident-nfs (csi.trident.netapp.io)', | ||
| 'provider_content.storage.size': 18, | ||
| 'provider_content.storage.bootable': True, | ||
| 'operating_system.architecture': f'{settings.ocpv.image_arch}', | ||
| 'operating_system.operating_system': module_ocpv_image.os.title, | ||
| 'provider_content.operating_system.provision_method': 'image', | ||
| 'operating_system.image': module_ocpv_image.image.name, | ||
| 'operating_system.root_password': settings.provisioning.host_root_password, | ||
| 'interfaces.interface.ocpv_network': f'{settings.ocpv.network}', | ||
| } | ||
| ) | ||
|
|
||
| # Teardown: delete host via API | ||
| host_api = sat.api.Host().search(query={'search': f'name="{host_fqdn}"'}) | ||
| 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, | ||
| delay=10, | ||
| ) | ||
|
|
||
| host = sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})[0] | ||
| assert host.name == host_fqdn | ||
| assert host.build_status_label == 'Installed' | ||
|
|
||
| on_value = session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name) | ||
| assert on_value[0]['Power'] == 'On' | ||
|
|
||
| # Power management actions work correctly (Power Off transitions the VM state) | ||
| assert on_value[0]['Actions'] == 'Power Off' | ||
|
|
||
| # Memory allocation matches the configured value | ||
| assert on_value[0]['Memory'] == f'{round(memory_in_gb)} GB' | ||
|
|
||
| # Test VM power management: power off the VM and verify the state changes accordingly | ||
| # After power off, the VM should show 'Off' status and 'Power On' as the available action | ||
| session.computeresource.vm_poweroff(module_ocpv_cr.name, host.name) | ||
| off_value = session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name) | ||
| assert off_value[0]['Power'] == 'Off' | ||
| assert off_value[0]['Actions'] == 'Power On' | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.