Skip to content

Commit e570f1f

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

2 files changed

Lines changed: 163 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: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
value = 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+
session.host.create(
93+
{
94+
'host.name': name,
95+
'host.hostgroup': module_ocpv_hostgroup.name,
96+
'provider_content.virtual_machine.cpus': '2',
97+
'provider_content.virtual_machine.memory': memory,
98+
'provider_content.virtual_machine.startup': True,
99+
'provider_content.storage.storage_class': 'trident-nfs (csi.trident.netapp.io)',
100+
'provider_content.storage.size': 18,
101+
'provider_content.storage.bootable': True,
102+
'operating_system.architecture': f'{settings.ocpv.image_arch}',
103+
'operating_system.operating_system': module_ocpv_image.os.title,
104+
'provider_content.operating_system.provision_method': 'image',
105+
'operating_system.image': module_ocpv_image.image.name,
106+
'operating_system.root_password': gen_string('alpha').lower(),
107+
'interfaces.interface.ocpv_network': f'{settings.ocpv.network}',
108+
}
109+
)
110+
111+
# Teardown: delete host via API
112+
host_api = sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})
113+
if host_api:
114+
request.addfinalizer(host_api[0].delete)
115+
116+
wait_for(
117+
lambda: (
118+
sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})[0].build_status_label
119+
!= 'Pending installation'
120+
),
121+
timeout=1500,
122+
delay=10,
123+
)
124+
125+
host = sat.api.Host().search(query={'search': f'name="{host_fqdn}"'})[0]
126+
assert host.name == host_fqdn
127+
assert host.build_status_label == 'Installed'
128+
129+
assert (
130+
session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)[0][
131+
'Power'
132+
]
133+
== 'On'
134+
)
135+
# Power management actions work correctly (Power Off transitions the VM state)
136+
assert (
137+
session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)[0][
138+
'Actions'
139+
]
140+
== 'Power Off'
141+
)
142+
# Memory allocation matches the configured value
143+
assert (
144+
session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)[0][
145+
'Memory'
146+
]
147+
== f'{round(value)} GB'
148+
)
149+
# Test VM power management: power off the VM and verify the state changes accordingly
150+
# After power off, the VM should show 'Off' status and 'Power On' as the available action
151+
session.computeresource.vm_poweroff(module_ocpv_cr.name, host.name)
152+
assert (
153+
session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)[0][
154+
'Power'
155+
]
156+
== 'Off'
157+
)
158+
assert (
159+
session.computeresource.search_virtual_machine(module_ocpv_cr.name, host.name)[0][
160+
'Actions'
161+
]
162+
== 'Power On'
163+
)

0 commit comments

Comments
 (0)