Skip to content

Commit f071913

Browse files
committed
Test the VM power on/off functionality and verify memory usage during the operation.
1 parent 7272734 commit f071913

2 files changed

Lines changed: 144 additions & 1 deletion

File tree

tests/foreman/api/test_computeresource_ocpv.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ def test_positive_userdata_image_provision_end_to_end(
112112
6. Check if the host status is installed.
113113
114114
:expectedresults: Host is provisioned successfully on OpenShift Virtualization
115-
116115
"""
117116
name = gen_string('alpha').lower()
118117
sat = module_ocpv_sat
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
"""
2+
:Requirement: Computeresource - OCP-V
3+
4+
:CaseAutomation: Automated
5+
6+
:CaseComponent: ComputeResources-OCP-V
7+
8+
:Team: Rocket
9+
10+
:CaseImportance: High
11+
"""
12+
13+
import textwrap
14+
15+
from fauxfactory import gen_string
16+
import pytest
17+
from wait_for import wait_for
18+
19+
from robottelo.config import settings
20+
21+
22+
@pytest.mark.e2e
23+
@pytest.mark.on_premises_provisioning
24+
@pytest.mark.parametrize('setting_update', ['destroy_vm_on_host_delete=True'], indirect=True)
25+
def test_positive_userdata_image_provision_end_to_end(
26+
request,
27+
setting_update,
28+
module_ocpv_cr,
29+
module_ocpv_sat,
30+
module_org,
31+
module_location,
32+
module_ocpv_image,
33+
module_ocpv_hostgroup,
34+
):
35+
"""Provision a host on OpenShift Virtualization using image-based provisioning via UI.
36+
37+
:id: a1b2c3d4-5e6f-4a5b-8c9d-0e1f2a3b4c5d
38+
39+
:steps:
40+
1. Create OCP compute resource
41+
2. Create image for the compute resource
42+
3. Create userdata provisioning template and associate with OS
43+
4. Create hostgroup
44+
5. Via UI: Create host with hostgroup, deploy on OCP-V, image, and interfaces
45+
6. Wait for build status and verify host status is Installed
46+
7. Verify the VM power status and memory usage under the compute resource.
47+
48+
:expectedresults: Host is provisioned successfully on OpenShift Virtualization via UI
49+
50+
:Verifies: SAT-42060, SAT-41355
51+
"""
52+
name = gen_string('alpha').lower()
53+
sat = module_ocpv_sat
54+
os = module_ocpv_image.os
55+
domain_name = module_ocpv_hostgroup.domain.read().name
56+
host_fqdn = f'{name}.{domain_name}'
57+
memory = '6144'
58+
memory_in_gb = int(memory) / 1024
59+
60+
USERDATA_TEMPLATE = textwrap.dedent("""\
61+
#cloud-config
62+
<%# Contact Foreman to confirm instance is built -%>
63+
phone_home:
64+
url: <%= foreman_url('built') %>
65+
post: []
66+
tries: 10
67+
""")
68+
69+
# Create userdata provisioning template via API
70+
template_kind = sat.api.TemplateKind().search(query={'search': 'name=user_data'})[0]
71+
userdata_template = sat.api.ProvisioningTemplate(
72+
name=gen_string('alpha'),
73+
organization=[module_org],
74+
location=[module_location],
75+
snippet=False,
76+
template_kind=template_kind,
77+
operatingsystem=[os],
78+
template=USERDATA_TEMPLATE,
79+
).create()
80+
81+
os.provisioning_template.append(userdata_template)
82+
os.update(['provisioning_template'])
83+
sat.api.OSDefaultTemplate(
84+
operatingsystem=os,
85+
provisioning_template=userdata_template,
86+
template_kind=template_kind,
87+
).create()
88+
89+
with module_ocpv_sat.ui_session() as session:
90+
session.organization.select(org_name=module_org.name)
91+
session.location.select(loc_name=module_location.name)
92+
93+
session.host.create(
94+
{
95+
'host.name': name,
96+
'host.hostgroup': module_ocpv_hostgroup.name,
97+
'provider_content.virtual_machine.cpus': '2',
98+
'provider_content.virtual_machine.memory': memory,
99+
'provider_content.virtual_machine.startup': True,
100+
'provider_content.storage.storage_class': 'trident-nfs (csi.trident.netapp.io)',
101+
'provider_content.storage.size': 18,
102+
'provider_content.storage.bootable': True,
103+
'operating_system.architecture': f'{settings.ocpv.image_arch}',
104+
'operating_system.operating_system': module_ocpv_image.os.title,
105+
'provider_content.operating_system.provision_method': 'image',
106+
'operating_system.image': module_ocpv_image.image.name,
107+
'operating_system.root_password': settings.provisioning.host_root_password,
108+
'interfaces.interface.ocpv_network': f'{settings.ocpv.network}',
109+
}
110+
)
111+
112+
# Teardown: delete host via API
113+
host_api = sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})
114+
if host_api:
115+
request.addfinalizer(host_api[0].delete)
116+
117+
wait_for(
118+
lambda: (
119+
sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})[0].build_status_label
120+
!= 'Pending installation'
121+
),
122+
timeout=1500,
123+
delay=10,
124+
)
125+
126+
host = sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})[0]
127+
assert host.name == host_fqdn
128+
assert host.build_status_label == 'Installed'
129+
130+
on_value = session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)
131+
assert on_value[0]['Power'] == 'On'
132+
133+
# Power management actions work correctly (Power Off transitions the VM state)
134+
assert on_value[0]['Actions'] == 'Power Off'
135+
136+
# Memory allocation matches the configured value
137+
assert on_value[0]['Memory'] == f'{round(memory_in_gb)} GB'
138+
139+
# Test VM power management: power off the VM and verify the state changes accordingly
140+
# After power off, the VM should show 'Off' status and 'Power On' as the available action
141+
session.computeresource.vm_poweroff(module_ocpv_cr.name, host.name)
142+
off_value = session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)
143+
assert off_value[0]['Power'] == 'Off'
144+
assert off_value[0]['Actions'] == 'Power On'

0 commit comments

Comments
 (0)