Skip to content

Commit 8b9b307

Browse files
committed
Test the VM power on/off functionality and verify memory usage during the operation.
1 parent 6e909f9 commit 8b9b307

2 files changed

Lines changed: 162 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: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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 = '6000'
56+
value = int(memory) / 1024
57+
storage_data = [
58+
{'storage_class': 'trident-nfs (csi.trident.netapp.io)', 'size': '18', 'bootable': True}
59+
]
60+
61+
USERDATA_TEMPLATE = """\
62+
#cloud-config
63+
<%# Contact Foreman to confirm instance is built -%>
64+
phone_home:
65+
url: <%= foreman_url('built') %>
66+
post: []
67+
tries: 10
68+
"""
69+
70+
# Create userdata provisioning template via API
71+
template_kind = sat.api.TemplateKind().search(query={'search': 'name=user_data'})[0]
72+
userdata_template = sat.api.ProvisioningTemplate(
73+
name=gen_string('alpha'),
74+
organization=[module_org],
75+
location=[module_location],
76+
snippet=False,
77+
template_kind=template_kind,
78+
operatingsystem=[os],
79+
template=USERDATA_TEMPLATE,
80+
).create()
81+
82+
os.provisioning_template.append(userdata_template)
83+
os.update(['provisioning_template'])
84+
sat.api.OSDefaultTemplate(
85+
operatingsystem=os,
86+
provisioning_template=userdata_template,
87+
template_kind=template_kind,
88+
).create()
89+
90+
with module_ocpv_sat.ui_session() as session:
91+
session.organization.select(org_name=module_org.name)
92+
session.location.select(loc_name=module_location.name)
93+
session.host.create(
94+
{
95+
'host.name': name,
96+
'host.hostgroup': 'qptWRGJiKt',
97+
'provider_content.virtual_machine.cpus': '2',
98+
'provider_content.virtual_machine.memory': memory,
99+
'provider_content.virtual_machine.startup': True,
100+
'provider_content.virtual_machine.storage': storage_data,
101+
'operating_system.architecture': 'x86_64',
102+
'operating_system.operating_system': 'caUaDFMzpp',
103+
'provider_content.operating_system.provision_method': 'image',
104+
'operating_system.image': 'HnrwYwgTfK',
105+
'operating_system.root_password': gen_string('alpha').lower(),
106+
'interfaces.interface.openshift_network': f'{settings.ocpv.network}',
107+
}
108+
)
109+
110+
# Teardown: delete host via API
111+
host_api = sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})
112+
if host_api:
113+
request.addfinalizer(host_api[0].delete)
114+
115+
wait_for(
116+
lambda: (
117+
sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})[0].build_status_label
118+
!= 'Pending installation'
119+
),
120+
timeout=1500,
121+
delay=10,
122+
)
123+
124+
host = sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})[0]
125+
assert host.name == host_fqdn
126+
assert host.build_status_label == 'Installed'
127+
128+
assert (
129+
session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)[0][
130+
'Power'
131+
]
132+
== 'On'
133+
)
134+
# Power management actions work correctly (Power Off transitions the VM state)
135+
assert (
136+
session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)[0][
137+
'Actions'
138+
]
139+
== 'Power Off'
140+
)
141+
# Memory allocation matches the configured value
142+
assert (
143+
session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)[0][
144+
'Memory'
145+
]
146+
== f'{round(value)} GB'
147+
)
148+
# Test VM power management: power off the VM and verify the state changes accordingly
149+
# After power off, the VM should show 'Off' status and 'Power On' as the available action
150+
session.computeresource.vm_poweroff(module_ocpv_cr.name, host.name)
151+
assert (
152+
session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)[0][
153+
'Power'
154+
]
155+
== 'Off'
156+
)
157+
assert (
158+
session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)[0][
159+
'Actions'
160+
]
161+
== 'Power On'
162+
)

0 commit comments

Comments
 (0)