Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
453d967
refactor snapshots to use win 2k22 and vtpm
acinko-rh Apr 30, 2026
c190196
chore: ignore flake8 rules now handled by ruff (#4703)
rnetser May 4, 2026
3f16233
style: remove stale noqa comments and obsolete utf-8 headers (#4725)
rnetser May 4, 2026
3f86e48
use image from registry
acinko-rh May 5, 2026
637a20a
Merge branch 'main' into add_vtpm_to_win_machines_snapshots
acinko-rh May 6, 2026
4158220
Merge branch 'main' into add_vtpm_to_win_machines_snapshots
acinko-rh May 6, 2026
fdb3614
Merge branch 'main' into add_vtpm_to_win_machines_snapshots
acinko-rh May 21, 2026
8838670
mild name refactor and change the workflow for the helper functions
acinko-rh May 21, 2026
aa7e977
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 21, 2026
7a477cf
remove tox unused code
acinko-rh May 21, 2026
cc132ab
fix the test parameters
acinko-rh May 21, 2026
b7c6689
Merge branch 'main' into add_vtpm_to_win_machines_snapshots
acinko-rh May 28, 2026
a05c432
Merge branch 'main' into add_vtpm_to_win_machines_snapshots
acinko-rh Jun 2, 2026
a985f97
Merge branch 'main' into add_vtpm_to_win_machines_snapshots
acinko-rh Jun 2, 2026
88dc37e
Merge branch 'main' into add_vtpm_to_win_machines_snapshots
acinko-rh Jun 2, 2026
8d22cf3
Merge branch 'main' into add_vtpm_to_win_machines_snapshots
acinko-rh Jun 3, 2026
99dd41b
Merge branch 'main' into add_vtpm_to_win_machines_snapshots
acinko-rh Jun 9, 2026
6353aca
Merge branch 'main' into add_vtpm_to_win_machines_snapshots
acinko-rh Jun 10, 2026
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
59 changes: 41 additions & 18 deletions tests/storage/snapshots/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@
from tests.storage.snapshots.constants import WINDOWS_DIRECTORY_PATH
from tests.storage.utils import (
assert_windows_directory_existence,
create_windows19_vm,
create_windows_directory,
set_permissions,
)
from utilities.constants import TIMEOUT_2MIN, TIMEOUT_5SEC, TIMEOUT_10MIN, UNPRIVILEGED_USER
from tests.utils import create_windows2022_dv_template_from_registry, create_windows2022_vm_with_vtpm
from utilities.constants import (
TIMEOUT_2MIN,
TIMEOUT_5SEC,
TIMEOUT_10MIN,
UNPRIVILEGED_USER,
)
from utilities.virt import running_vm, wait_for_windows_vm

LOGGER = logging.getLogger(__name__)

Expand All @@ -44,63 +50,80 @@ def permissions_for_dv(namespace, admin_client):


@pytest.fixture()
def windows_vm_for_snapshot(
def windows_dv_template_from_registry(
request,
namespace,
unprivileged_client,
modern_cpu_for_migration,
storage_class_matrix_snapshot_matrix__module__,
):
with create_windows19_vm(
with create_windows2022_dv_template_from_registry(
dv_name=request.param["dv_name"],
namespace=namespace.name,
client=unprivileged_client,
storage_class=next(iter(storage_class_matrix_snapshot_matrix__module__)),
) as dv_template:
yield dv_template


@pytest.fixture()
def windows_vm_with_vtpm_for_snapshot(
request, namespace, unprivileged_client, modern_cpu_for_migration, windows_dv_template_from_registry
):
with create_windows2022_vm_with_vtpm(
dv_template=windows_dv_template_from_registry,
namespace=namespace.name,
client=unprivileged_client,
vm_name=request.param["vm_name"],
cpu_model=modern_cpu_for_migration,
storage_class=[*storage_class_matrix_snapshot_matrix__module__][0],
) as vm:
running_vm(vm=vm, wait_for_interfaces=False, check_ssh_connectivity=False)
wait_for_windows_vm(vm=vm, version="2022")
yield vm


@pytest.fixture()
def snapshot_windows_directory(windows_vm_for_snapshot):
create_windows_directory(windows_vm=windows_vm_for_snapshot, directory_path=WINDOWS_DIRECTORY_PATH)
def snapshot_windows_directory(windows_vm_with_vtpm_for_snapshot):
create_windows_directory(windows_vm=windows_vm_with_vtpm_for_snapshot, directory_path=WINDOWS_DIRECTORY_PATH)


@pytest.fixture()
def windows_snapshot(
snapshot_windows_directory,
windows_vm_for_snapshot,
windows_vm_with_vtpm_for_snapshot,
):
with VirtualMachineSnapshot(
name="windows-snapshot",
namespace=windows_vm_for_snapshot.namespace,
vm_name=windows_vm_for_snapshot.name,
namespace=windows_vm_with_vtpm_for_snapshot.namespace,
vm_name=windows_vm_with_vtpm_for_snapshot.name,
) as snapshot:
yield snapshot


@pytest.fixture()
def snapshot_dirctory_removed(windows_vm_for_snapshot, windows_snapshot):
def snapshot_dirctory_removed(windows_vm_with_vtpm_for_snapshot, windows_snapshot):
windows_snapshot.wait_ready_to_use(timeout=TIMEOUT_10MIN)
cmd = shlex.split(
f'powershell -command "Remove-Item -Path {WINDOWS_DIRECTORY_PATH} -Recurse"',
)
run_ssh_commands(host=windows_vm_for_snapshot.ssh_exec, commands=cmd, wait_timeout=TIMEOUT_2MIN, sleep=TIMEOUT_5SEC)
run_ssh_commands(
host=windows_vm_with_vtpm_for_snapshot.ssh_exec, commands=cmd, wait_timeout=TIMEOUT_2MIN, sleep=TIMEOUT_5SEC
)
assert_windows_directory_existence(
expected_result=False,
windows_vm=windows_vm_for_snapshot,
windows_vm=windows_vm_with_vtpm_for_snapshot,
directory_path=WINDOWS_DIRECTORY_PATH,
)
windows_vm_for_snapshot.stop(wait=True)
windows_vm_with_vtpm_for_snapshot.stop(wait=True)


@pytest.fixture()
def file_created_during_snapshot(windows_vm_for_snapshot, windows_snapshot):
def file_created_during_snapshot(windows_vm_with_vtpm_for_snapshot, windows_snapshot):
file = f"{WINDOWS_DIRECTORY_PATH}\\file.txt"
cmd = shlex.split(
f'powershell -command "for($i=1; $i -le 100; $i++){{$i| Out-File -FilePath {file} -Append}}"',
)
run_ssh_commands(host=windows_vm_for_snapshot.ssh_exec, commands=cmd, wait_timeout=TIMEOUT_2MIN, sleep=TIMEOUT_5SEC)
run_ssh_commands(
host=windows_vm_with_vtpm_for_snapshot.ssh_exec, commands=cmd, wait_timeout=TIMEOUT_2MIN, sleep=TIMEOUT_5SEC
)
windows_snapshot.wait_snapshot_done(timeout=TIMEOUT_10MIN)
windows_vm_for_snapshot.stop(wait=True)
windows_vm_with_vtpm_for_snapshot.stop(wait=True)
27 changes: 15 additions & 12 deletions tests/storage/snapshots/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,37 +397,40 @@ def test_fail_to_snapshot_with_unprivileged_client_dv_permissions(
)


@pytest.mark.tier3
@pytest.mark.parametrize(
"windows_vm_for_snapshot",
"windows_dv_template_from_registry, windows_vm_with_vtpm_for_snapshot",
[
pytest.param(
{"dv_name": "dv-8307", "vm_name": "vm-8307"},
{"dv_name": "dv-8307"},
{"vm_name": "vm-8307"},
marks=pytest.mark.polarion("CNV-8307"),
),
],
indirect=True,
)
def test_online_windows_vm_successful_restore(
windows_vm_for_snapshot,
windows_vm_with_vtpm_for_snapshot,
windows_snapshot,
snapshot_dirctory_removed,
):
with VirtualMachineRestore(
name="restore-vm",
namespace=windows_vm_for_snapshot.namespace,
vm_name=windows_vm_for_snapshot.name,
namespace=windows_vm_with_vtpm_for_snapshot.namespace,
vm_name=windows_vm_with_vtpm_for_snapshot.name,
snapshot_name=windows_snapshot.name,
) as restore:
start_windows_vm_after_restore(vm_restore=restore, windows_vm=windows_vm_for_snapshot)
start_windows_vm_after_restore(vm_restore=restore, windows_vm=windows_vm_with_vtpm_for_snapshot)
assert_windows_directory_existence(
expected_result=True,
windows_vm=windows_vm_for_snapshot,
windows_vm=windows_vm_with_vtpm_for_snapshot,
directory_path=WINDOWS_DIRECTORY_PATH,
)


@pytest.mark.tier3
@pytest.mark.parametrize(
"windows_vm_for_snapshot",
"windows_vm_with_vtpm_for_snapshot",
[
pytest.param(
{"dv_name": "dv-8536", "vm_name": "vm-8536"},
Expand All @@ -437,14 +440,14 @@ def test_online_windows_vm_successful_restore(
indirect=True,
)
def test_write_to_file_while_snapshot(
windows_vm_for_snapshot,
windows_vm_with_vtpm_for_snapshot,
windows_snapshot,
file_created_during_snapshot,
):
with VirtualMachineRestore(
name="restore-vm",
namespace=windows_vm_for_snapshot.namespace,
vm_name=windows_vm_for_snapshot.name,
namespace=windows_vm_with_vtpm_for_snapshot.namespace,
vm_name=windows_vm_with_vtpm_for_snapshot.name,
snapshot_name=windows_snapshot.name,
) as restore:
start_windows_vm_after_restore(vm_restore=restore, windows_vm=windows_vm_for_snapshot)
start_windows_vm_after_restore(vm_restore=restore, windows_vm=windows_vm_with_vtpm_for_snapshot)
8 changes: 4 additions & 4 deletions tests/storage/test_hotplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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 tests.utils import create_windows2022_dv_template_from_registry, create_windows2022_vm_with_vtpm
from utilities.constants import HOTPLUG_DISK_SCSI_BUS, HOTPLUG_DISK_SERIAL, HOTPLUG_DISK_VIRTIO_BUS, Images
from utilities.hco import ResourceEditorValidateHCOReconcile
from utilities.jira import is_jira_open
Expand Down Expand Up @@ -78,7 +78,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,
Expand All @@ -95,8 +95,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",
Expand Down
38 changes: 0 additions & 38 deletions tests/storage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@
from ocp_resources.service import Service
from ocp_resources.storage_class import StorageClass
from ocp_resources.storage_profile import StorageProfile
from ocp_resources.template import Template
from ocp_resources.upload_token_request import UploadTokenRequest
from pyhelper_utils.shell import run_ssh_commands
from pytest_testconfig import config as py_config
from timeout_sampler import TimeoutExpiredError, TimeoutSampler

from utilities import console
from utilities.artifactory import (
cleanup_artifactory_secret_and_config_map,
get_artifactory_config_map,
get_artifactory_secret,
get_http_image_url,
)
from utilities.constants import (
Expand All @@ -52,8 +48,6 @@
)
from utilities.virt import (
VirtualMachineForTests,
VirtualMachineForTestsFromTemplate,
running_vm,
vm_instance_from_template,
wait_for_windows_vm,
)
Expand Down Expand Up @@ -356,38 +350,6 @@ def get_hpp_daemonset(hco_namespace, hpp_cr_suffix, admin_client):
return daemonset


@contextmanager
def create_windows19_vm(dv_name, namespace, client, vm_name, cpu_model, storage_class):
artifactory_secret = get_artifactory_secret(namespace=namespace)
artifactory_config_map = get_artifactory_config_map(namespace=namespace)
dv = DataVolume(
name=dv_name,
namespace=namespace,
storage_class=storage_class,
source="http",
url=get_http_image_url(image_directory=Images.Windows.UEFI_WIN_DIR, image_name=Images.Windows.WIN2k19_IMG),
size=Images.Windows.DEFAULT_DV_SIZE,
client=client,
api_name="storage",
secret=artifactory_secret,
cert_configmap=artifactory_config_map.name,
)
dv.to_dict()
with VirtualMachineForTestsFromTemplate(
name=vm_name,
namespace=namespace,
client=client,
labels=Template.generate_template_labels(**py_config["latest_windows_os_dict"]["template_labels"]),
cpu_model=cpu_model,
data_volume_template={"metadata": dv.res["metadata"], "spec": dv.res["spec"]},
) as vm:
running_vm(vm=vm)
yield vm
cleanup_artifactory_secret_and_config_map(
artifactory_secret=artifactory_secret, artifactory_config_map=artifactory_config_map
)


def create_cirros_dv(
namespace,
name,
Expand Down
8 changes: 4 additions & 4 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ 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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions utilities/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ class NamespacesNames:
RHEL8_PREFERENCE = "rhel.8"
RHEL9_PREFERENCE = "rhel.9"
RHEL10_PREFERENCE = "rhel.10"
WINDOWS_2K22_PREFERENCE = "windows.2k22"
U1_SMALL = "u1.small"
U1_LARGE = "u1.large"
PROMETHEUS_K8S = "prometheus-k8s"
Expand Down
Loading