Skip to content

Update hyperv features test to use instance types #1126

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 61 additions & 38 deletions tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import logging

import pytest
from ocp_resources.virtual_machine_cluster_instancetype import VirtualMachineClusterInstancetype
from ocp_resources.virtual_machine_cluster_preference import VirtualMachineClusterPreference
from pytest_testconfig import py_config

from tests.os_params import (
FEDORA_LATEST,
FEDORA_LATEST_LABELS,
FEDORA_LATEST_OS,
WINDOWS_LATEST,
WINDOWS_LATEST_LABELS,
WINDOWS_LATEST_OS,
)
from utilities.constants import VIRT_LAUNCHER
from utilities.virt import vm_instance_from_template
from utilities.constants import OS_FLAVOR_FEDORA, OS_FLAVOR_WINDOWS, VIRT_LAUNCHER
from utilities.storage import data_volume_template_with_source_ref_dict
from utilities.virt import VirtualMachineForTests, running_vm

LOGGER = logging.getLogger(__name__)

Expand All @@ -23,19 +24,47 @@ def hyperv_vm(
unprivileged_client,
namespace,
golden_image_data_source_scope_class,
hyperv_instance_type,
hyperv_preference,
):
hyperv_dict = request.param.get("hyperv_dict")
if hyperv_dict:
request.param["vm_dict"] = {"spec": {"template": {"spec": {"domain": {"features": {"hyperv": hyperv_dict}}}}}}
with vm_instance_from_template(
request=request,
unprivileged_client=unprivileged_client,
namespace=namespace,
data_source=golden_image_data_source_scope_class,
with VirtualMachineForTests(
name=request.param.get("vm_name"),
namespace=namespace.name,
client=unprivileged_client,
data_volume_template=data_volume_template_with_source_ref_dict(
data_source=golden_image_data_source_scope_class
),
disk_type=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need disk_type?

vm_instance_type=hyperv_instance_type,
vm_preference=hyperv_preference,
os_flavor=request.param.get("os_flavor"),
) as vm:
running_vm(vm=vm)
yield vm


@pytest.fixture()
def hyperv_instance_type(request):
with VirtualMachineClusterInstancetype(
name="hyperv-instance-type",
memory={"guest": "8Gi"},
cpu={"guest": 2, "model": request.param.get("model")},
) as hyperv_instance_type:
yield hyperv_instance_type


@pytest.fixture()
def hyperv_preference(request):
hyperv_preference_dict = VirtualMachineClusterPreference(
name=request.param.get("preference_name")
).instance.to_dict()
hyperv_preference_dict["metadata"] = {"name": "hyperv-cluster-preference"}
if hyperv_dict := request.param.get("hyperv_dict"):
hyperv_preference_dict["spec"]["features"].update(hyperv_dict)
with VirtualMachineClusterPreference(kind_dict=hyperv_preference_dict) as hyperv_preference:
yield hyperv_preference


def get_hyperv_enabled_labels(instance_labels):
return [
label
Expand Down Expand Up @@ -74,21 +103,18 @@ def verify_evmcs_related_attributes(vmi_xml_dict):
@pytest.mark.high_resource_vm
class TestWindowsHyperVFlags:
@pytest.mark.parametrize(
"hyperv_vm",
"hyperv_vm, hyperv_instance_type, hyperv_preference",
[
pytest.param(
{
"vm_name": "win-vm-with-default-hyperv-features",
"template_labels": WINDOWS_LATEST_LABELS,
},
{"vm_name": "win-vm-with-default-hyperv-features", "os_flavor": OS_FLAVOR_WINDOWS},
{},
{"preference_name": "windows.2k19"},
marks=(pytest.mark.polarion("CNV-7247")),
),
pytest.param(
{
"vm_name": "win-vm-with-host-passthrough",
"template_labels": WINDOWS_LATEST_LABELS,
"vm_dict": {"spec": {"template": {"spec": {"domain": {"cpu": {"model": "host-passthrough"}}}}}},
},
{"vm_name": "win-vm-with-host-passthrough", "os_flavor": OS_FLAVOR_WINDOWS},
{"model": "host-passthrough"},
{"preference_name": "windows.2k19"},
marks=(pytest.mark.polarion("CNV-7248")),
),
],
Expand Down Expand Up @@ -119,13 +145,14 @@ def test_vm_hyperv_labels_on_launcher_pod(
)

@pytest.mark.parametrize(
"hyperv_vm",
"hyperv_vm, hyperv_instance_type, hyperv_preference",
[
pytest.param(
{"vm_name": "win-vm-with-added-hyperv-features", "os_flavor": OS_FLAVOR_WINDOWS},
{},
{
"vm_name": "win-vm-with-added-hyperv-features",
"template_labels": WINDOWS_LATEST_LABELS,
"hyperv_dict": {"vendorid": {"vendorid": "randomid"}},
"preference_name": "windows.2k19",
"hyperv_dict": {"preferredHyperv": {"vendorid": {"vendorid": "randomid"}}},
},
marks=(pytest.mark.polarion("CNV-6087")),
),
Expand All @@ -141,14 +168,12 @@ def test_vm_added_hyperv_features(
assert vendor_id["@state"] == "on" and vendor_id["@value"] == "randomid", f"Vendor id in libvirt: {vendor_id}"

@pytest.mark.parametrize(
"hyperv_vm",
"hyperv_vm, hyperv_instance_type, hyperv_preference",
[
pytest.param(
{
"vm_name": "win-vm-with-evmcs-feature",
"template_labels": WINDOWS_LATEST_LABELS,
"hyperv_dict": {"evmcs": {}},
},
{"vm_name": "win-vm-with-evmcs-feature", "os_flavor": OS_FLAVOR_WINDOWS},
{},
{"preference_name": "windows.2k19"},
marks=pytest.mark.polarion("CNV-6202"),
),
],
Expand All @@ -174,14 +199,12 @@ def test_windows_vm_with_evmcs_feature(self, hyperv_vm):
)
class TestFedoraHyperVFlags:
@pytest.mark.parametrize(
"hyperv_vm",
"hyperv_vm, hyperv_instance_type, hyperv_preference",
[
pytest.param(
{
"vm_name": "fedora-vm-with-evmcs-feature",
"template_labels": FEDORA_LATEST_LABELS,
"hyperv_dict": {"evmcs": {}},
},
{"vm_name": "fedora-vm-with-evmcs-feature", "os_flavor": OS_FLAVOR_FEDORA},
{},
{"preference_name": "fedora", "hyperv_dict": {"preferredHyperv": {"evmcs": {}}}},
marks=pytest.mark.polarion("CNV-6090"),
),
],
Expand Down