diff --git a/tests/storage/memory_dump/conftest.py b/tests/storage/memory_dump/conftest.py index 0c3f00d8dd..5226bc0995 100644 --- a/tests/storage/memory_dump/conftest.py +++ b/tests/storage/memory_dump/conftest.py @@ -5,28 +5,35 @@ import pytest from ocp_resources.datavolume import DataVolume from ocp_resources.persistent_volume_claim import PersistentVolumeClaim +from pytest_testconfig import config as py_config from tests.storage.memory_dump.utils import wait_for_memory_dump_status_completed from utilities.constants import Images from utilities.constants.timeouts import TIMEOUT_2MIN from utilities.storage import PodWithPVC, get_containers_for_pods_with_pvc, virtctl_memory_dump -from utilities.virt import running_vm, vm_instance_from_template @pytest.fixture() -def windows_vm_for_memory_dump( - request, +def windows_vm_with_vtpm_for_memory_dump( unprivileged_client, namespace, - golden_image_data_source_scope_function, + modern_cpu_for_migration, ): - with vm_instance_from_template( - request=request, - unprivileged_client=unprivileged_client, - namespace=namespace, - data_source=golden_image_data_source_scope_function, - ) as vm: - running_vm(vm=vm) + with ( + create_windows2022_dv_template_from_registry( + dv_name="windows-2022-dv", + namespace=namespace.name, + client=unprivileged_client, + storage_class=py_config["default_storage_class"], + ) as dv_template, + create_windows2022_vm_with_vtpm( + vm_name="windows-2022-vm", + namespace=namespace.name, + client=unprivileged_client, + dv_template=dv_template, + cpu_model=modern_cpu_for_migration, + ) as vm, + ): yield vm @@ -50,11 +57,11 @@ def pvc_for_windows_memory_dump(unprivileged_client, namespace, storage_class_wi @pytest.fixture() -def windows_vm_memory_dump(namespace, windows_vm_for_memory_dump, pvc_for_windows_memory_dump): +def windows_vm_memory_dump(namespace, windows_vm_with_vtpm_for_memory_dump, pvc_for_windows_memory_dump): status, out, err = virtctl_memory_dump( action="get", namespace=namespace.name, - vm_name=windows_vm_for_memory_dump.name, + vm_name=windows_vm_with_vtpm_for_memory_dump.name, claim_name=pvc_for_windows_memory_dump.name, ) assert status, f"Failed to get memory dump, out: {out}, err: {err}." @@ -62,12 +69,14 @@ def windows_vm_memory_dump(namespace, windows_vm_for_memory_dump, pvc_for_window @pytest.fixture() -def windows_vm_memory_dump_completed(windows_vm_for_memory_dump): - wait_for_memory_dump_status_completed(vm=windows_vm_for_memory_dump) +def windows_vm_memory_dump_completed(windows_vm_with_vtpm_for_memory_dump): + wait_for_memory_dump_status_completed(vm=windows_vm_with_vtpm_for_memory_dump) @pytest.fixture() -def consumer_pod_for_verifying_windows_memory_dump(namespace, windows_vm_for_memory_dump, pvc_for_windows_memory_dump): +def consumer_pod_for_verifying_windows_memory_dump( + namespace, windows_vm_with_vtpm_for_memory_dump, pvc_for_windows_memory_dump +): with PodWithPVC( namespace=namespace.name, name="consumer-pod", @@ -80,18 +89,18 @@ def consumer_pod_for_verifying_windows_memory_dump(namespace, windows_vm_for_mem pod.wait_for_status(status=pod.Status.RUNNING, timeout=TIMEOUT_2MIN) assert re.match( - rf"{windows_vm_for_memory_dump.name}-{pvc_for_windows_memory_dump.name}-\d*-\d*.memory.dump", + rf"{windows_vm_with_vtpm_for_memory_dump.name}-{pvc_for_windows_memory_dump.name}-\d*-\d*.memory.dump", pod.execute(command=shlex.split("bash -c 'ls -1 /pvc | grep dump'")), re.IGNORECASE, ), "Memory dump file doesn't exist" @pytest.fixture() -def windows_vm_memory_dump_deletion(namespace, windows_vm_for_memory_dump): +def windows_vm_memory_dump_deletion(namespace, windows_vm_with_vtpm_for_memory_dump): status, out, err = virtctl_memory_dump( action="remove", namespace=namespace.name, - vm_name=windows_vm_for_memory_dump.name, + vm_name=windows_vm_with_vtpm_for_memory_dump.name, ) assert status, f"Failed to remove memory dump, out: {out}, err: {err}." yield diff --git a/tests/storage/memory_dump/test_memory_dump.py b/tests/storage/memory_dump/test_memory_dump.py index 5d71061236..eabc712966 100644 --- a/tests/storage/memory_dump/test_memory_dump.py +++ b/tests/storage/memory_dump/test_memory_dump.py @@ -3,39 +3,19 @@ """ import pytest -from pytest_testconfig import config as py_config -from tests.os_params import WINDOWS_LATEST, WINDOWS_LATEST_LABELS from tests.storage.memory_dump.utils import wait_for_memory_dump_status_removed @pytest.mark.tier3 -@pytest.mark.parametrize( - "golden_image_data_volume_scope_function, windows_vm_for_memory_dump", - [ - pytest.param( - { - "dv_name": "dv-windows", - "image": WINDOWS_LATEST.get("image_path"), - "storage_class": py_config["default_storage_class"], - "dv_size": WINDOWS_LATEST.get("dv_size"), - }, - { - "vm_name": "windows-vm-mem", - "template_labels": WINDOWS_LATEST_LABELS, - }, - marks=pytest.mark.polarion("CNV-8518"), - ), - ], - indirect=True, -) +@pytest.mark.polarion("CNV-8518") def test_windows_memory_dump( namespace, - windows_vm_for_memory_dump, + windows_vm_with_vtpm_for_memory_dump, pvc_for_windows_memory_dump, windows_vm_memory_dump, windows_vm_memory_dump_completed, consumer_pod_for_verifying_windows_memory_dump, windows_vm_memory_dump_deletion, ): - wait_for_memory_dump_status_removed(vm=windows_vm_for_memory_dump) + wait_for_memory_dump_status_removed(vm=windows_vm_with_vtpm_for_memory_dump) diff --git a/tests/storage/test_hotplug.py b/tests/storage/test_hotplug.py index 6ff7200d5c..6f85252fd2 100644 --- a/tests/storage/test_hotplug.py +++ b/tests/storage/test_hotplug.py @@ -14,7 +14,6 @@ from ocp_resources.storage_profile import StorageProfile from tests.storage.utils import assert_disk_bus -from tests.utils import create_windows2022_dv_from_registry, create_windows2022_vm_with_vtpm_from_registry from utilities.constants import Images from utilities.constants.storage import HOTPLUG_DISK_SCSI_BUS, HOTPLUG_DISK_SERIAL, HOTPLUG_DISK_VIRTIO_BUS from utilities.hco import ResourceEditorValidateHCOReconcile @@ -85,7 +84,7 @@ def windows_dv_from_registry_scope_class( storage_class_matrix__class__, ): """Creates a Windows 2022 DataVolume from registry container disk.""" - with create_windows2022_dv_from_registry( + with create_windows2022_dv_template_from_registry( dv_name="dv-windows-2022-hotplug", namespace=namespace.name, client=unprivileged_client, @@ -102,8 +101,8 @@ def vm_instance_from_template_multi_storage_scope_class( windows_dv_from_registry_scope_class, ): """Creates a Windows 2022 VM with vTPM from registry container disk.""" - with create_windows2022_vm_with_vtpm_from_registry( - dv_dict=windows_dv_from_registry_scope_class, + with create_windows2022_vm_with_vtpm( + dv_template=windows_dv_from_registry_scope_class, namespace=namespace.name, client=unprivileged_client, vm_name="vm-win-2022-hotplug", diff --git a/tests/utils.py b/tests/utils.py index 874dcc7633..84c40bf1d3 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -705,14 +705,14 @@ def verify_rwx_default_storage(client: DynamicClient) -> None: @contextmanager -def create_windows2022_dv_from_registry( +def create_windows2022_dv_template_from_registry( dv_name: str, namespace: str, client: DynamicClient, storage_class: str, ) -> Generator[dict]: """ - Creates a Windows Server 2022 DataVolume from registry container disk. + Creates a Windows Server 2022 DataVolume template from registry container disk. Args: dv_name: Name for the DataVolume @@ -749,8 +749,8 @@ def create_windows2022_dv_from_registry( @contextmanager -def create_windows2022_vm_with_vtpm_from_registry( - dv_dict: dict, +def create_windows2022_vm_with_vtpm( + dv_template: dict, namespace: str, client: DynamicClient, vm_name: str, @@ -760,7 +760,7 @@ def create_windows2022_vm_with_vtpm_from_registry( Creates a Windows Server 2022 VM with vTPM from registry container disk. Args: - dv_dict: DataVolume template dictionary with metadata and spec + dv_template: DataVolume template dictionary with metadata and spec namespace: Kubernetes namespace client: Kubernetes client vm_name: Name for the VirtualMachine @@ -776,7 +776,7 @@ def create_windows2022_vm_with_vtpm_from_registry( os_flavor=OS_FLAVOR_WIN_CONTAINER_DISK, vm_instance_type=VirtualMachineClusterInstancetype(name=U1_LARGE, client=client), vm_preference=VirtualMachineClusterPreference(name=WINDOWS_2K22_PREFERENCE, client=client), - data_volume_template=dv_dict, + data_volume_template=dv_template, cpu_model=cpu_model, ) as vm: running_vm(vm=vm)