Skip to content

Commit a6dea7c

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

2 files changed

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

0 commit comments

Comments
 (0)