Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 14 additions & 10 deletions tests/storage/upgrade/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,58 @@


@pytest.fixture(scope="session")
def cirros_vm_for_upgrade_a(
def rhel_vm_for_upgrade_a(
upgrade_namespace_scope_session,
admin_client,
storage_class_for_snapshot,
cluster_common_node_cpu,
modern_cpu_for_migration,
rhel10_data_source_scope_session,
):
with create_vm_for_snapshot_upgrade_tests(
vm_name="snapshot-upgrade-a",
namespace=upgrade_namespace_scope_session.name,
client=admin_client,
storage_class_for_snapshot=storage_class_for_snapshot,
cpu_model=cluster_common_node_cpu,
cpu_model=modern_cpu_for_migration,
data_source=rhel10_data_source_scope_session,
) as vm:
yield vm


@pytest.fixture(scope="session")
def snapshots_for_upgrade_a(
admin_client,
cirros_vm_for_upgrade_a,
rhel_vm_for_upgrade_a,
):
with create_snapshot_for_upgrade(vm=cirros_vm_for_upgrade_a, client=admin_client) as snapshot:
with create_snapshot_for_upgrade(vm=rhel_vm_for_upgrade_a, client=admin_client) as snapshot:
yield snapshot


@pytest.fixture(scope="session")
def cirros_vm_for_upgrade_b(
def rhel_vm_for_upgrade_b(
upgrade_namespace_scope_session,
admin_client,
storage_class_for_snapshot,
cluster_common_node_cpu,
modern_cpu_for_migration,
rhel10_data_source_scope_session,
):
with create_vm_for_snapshot_upgrade_tests(
vm_name="snapshot-upgrade-b",
namespace=upgrade_namespace_scope_session.name,
client=admin_client,
storage_class_for_snapshot=storage_class_for_snapshot,
cpu_model=cluster_common_node_cpu,
cpu_model=modern_cpu_for_migration,
data_source=rhel10_data_source_scope_session,
) as vm:
yield vm


@pytest.fixture(scope="session")
def snapshots_for_upgrade_b(
admin_client,
cirros_vm_for_upgrade_b,
rhel_vm_for_upgrade_b,
):
with create_snapshot_for_upgrade(vm=cirros_vm_for_upgrade_b, client=admin_client) as snapshot:
with create_snapshot_for_upgrade(vm=rhel_vm_for_upgrade_b, client=admin_client) as snapshot:
yield snapshot


Expand Down
9 changes: 9 additions & 0 deletions tests/storage/upgrade/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Upgrade storage test constants
"""

# Upgrade snapshot test file constants
UPGRADE_FIRST_FILE_NAME = "first-file.txt"
UPGRADE_FIRST_FILE_CONTENT = "first-file"
UPGRADE_SECOND_FILE_NAME = "second-file.txt"
UPGRADE_SECOND_FILE_CONTENT = "second-file"
Comment thread
josemacassan marked this conversation as resolved.
88 changes: 62 additions & 26 deletions tests/storage/upgrade/test_upgrade_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import pytest
from ocp_resources.virtual_machine_restore import VirtualMachineRestore

from tests.storage.upgrade.constants import (
UPGRADE_FIRST_FILE_CONTENT,
UPGRADE_FIRST_FILE_NAME,
UPGRADE_SECOND_FILE_NAME,
)
from tests.storage.utils import assert_disk_bus
from tests.upgrade_params import (
HOTPLUG_VM_AFTER_UPGRADE_NODE_ID,
Expand All @@ -15,14 +20,14 @@
SNAPSHOT_RESTORE_CREATE_AFTER_UPGRADE,
STORAGE_NODE_ID_PREFIX,
)
from utilities.constants import DEPENDENCY_SCOPE_SESSION, HOTPLUG_DISK_VIRTIO_BUS, LS_COMMAND
from utilities.constants import DEPENDENCY_SCOPE_SESSION, HOTPLUG_DISK_VIRTIO_BUS
from utilities.storage import (
assert_disk_serial,
assert_hotplugvolume_nonexist,
run_command_on_cirros_vm_and_check_output,
run_command_on_vm_and_check_output,
wait_for_vm_volume_ready,
)
from utilities.virt import migrate_vm_and_verify
from utilities.virt import migrate_vm_and_verify, running_vm

if TYPE_CHECKING:
from kubernetes.dynamic import DynamicClient
Expand Down Expand Up @@ -52,22 +57,32 @@ def test_vm_snapshot_restore_before_upgrade(
self,
admin_client,
skip_if_no_storage_class_for_snapshot,
cirros_vm_for_upgrade_a,
rhel_vm_for_upgrade_a,
snapshots_for_upgrade_a,
):
with VirtualMachineRestore(
name=f"restore-snapshot-{cirros_vm_for_upgrade_a.name}",
client=admin_client,
name=f"restore-snapshot-{rhel_vm_for_upgrade_a.name}",
namespace=snapshots_for_upgrade_a.namespace,
vm_name=cirros_vm_for_upgrade_a.name,
vm_name=rhel_vm_for_upgrade_a.name,
snapshot_name=snapshots_for_upgrade_a.name,
client=admin_client,
) as vm_restore:
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if rhel_vm_for_upgrade_a.ready:
rhel_vm_for_upgrade_a.stop(wait=True)
vm_restore.wait_restore_done()
cirros_vm_for_upgrade_a.start(wait=True)
run_command_on_cirros_vm_and_check_output(
vm=cirros_vm_for_upgrade_a,
command=LS_COMMAND,
expected_result="1",
running_vm(vm=rhel_vm_for_upgrade_a)
# Verify first file exists (created before snapshot)
run_command_on_vm_and_check_output(
vm=rhel_vm_for_upgrade_a,
command=f"cat {UPGRADE_FIRST_FILE_NAME}",
expected_result=UPGRADE_FIRST_FILE_CONTENT,
)

# Verify second file does NOT exist (created after snapshot)
run_command_on_vm_and_check_output(
vm=rhel_vm_for_upgrade_a,
command=f"test ! -f {UPGRADE_SECOND_FILE_NAME} && echo 'file not found'",
expected_result="file not found",
)
Comment thread
josemacassan marked this conversation as resolved.

@pytest.mark.sno
Expand Down Expand Up @@ -117,12 +132,21 @@ def test_vm_with_hotplug_before_upgrade(
)
def test_vm_snapshot_restore_check_after_upgrade(
self,
cirros_vm_for_upgrade_a,
rhel_vm_for_upgrade_a,
):
run_command_on_cirros_vm_and_check_output(
vm=cirros_vm_for_upgrade_a,
command=LS_COMMAND,
expected_result="1",
running_vm(vm=rhel_vm_for_upgrade_a)
# Verify first file exists (created before snapshot, should still be there after upgrade)
run_command_on_vm_and_check_output(
vm=rhel_vm_for_upgrade_a,
command=f"cat {UPGRADE_FIRST_FILE_NAME}",
expected_result=UPGRADE_FIRST_FILE_CONTENT,
)

# Verify second file does NOT exist (was created after snapshot, should not be present after restore)
run_command_on_vm_and_check_output(
vm=rhel_vm_for_upgrade_a,
command=f"test ! -f {UPGRADE_SECOND_FILE_NAME} && echo 'file not found'",
expected_result="file not found",
)

@pytest.mark.sno
Expand All @@ -137,21 +161,33 @@ def test_vm_snapshot_restore_check_after_upgrade(
scope=DEPENDENCY_SCOPE_SESSION,
)
def test_vm_snapshot_restore_create_after_upgrade(
self, admin_client, cirros_vm_for_upgrade_b, snapshots_for_upgrade_b
self, admin_client, rhel_vm_for_upgrade_b, snapshots_for_upgrade_b
):
with VirtualMachineRestore(
name=f"restore-snapshot-{cirros_vm_for_upgrade_b.name}",
client=admin_client,
name=f"restore-snapshot-{rhel_vm_for_upgrade_b.name}",
namespace=snapshots_for_upgrade_b.namespace,
vm_name=cirros_vm_for_upgrade_b.name,
vm_name=rhel_vm_for_upgrade_b.name,
snapshot_name=snapshots_for_upgrade_b.name,
client=admin_client,
) as vm_restore:
if rhel_vm_for_upgrade_b.ready:
rhel_vm_for_upgrade_b.stop(wait=True)
vm_restore.wait_restore_done()
cirros_vm_for_upgrade_b.start(wait=True)
run_command_on_cirros_vm_and_check_output(
vm=cirros_vm_for_upgrade_b,
command=LS_COMMAND,
expected_result="1",

running_vm(vm=rhel_vm_for_upgrade_b)

# Verify first file exists (created before snapshot)
run_command_on_vm_and_check_output(
vm=rhel_vm_for_upgrade_b,
command=f"cat {UPGRADE_FIRST_FILE_NAME}",
expected_result=UPGRADE_FIRST_FILE_CONTENT,
)

# Verify second file does NOT exist (created after snapshot)
run_command_on_vm_and_check_output(
vm=rhel_vm_for_upgrade_b,
command=f"test ! -f {UPGRADE_SECOND_FILE_NAME} && echo 'file not found'",
expected_result="file not found",
)

@pytest.mark.polarion("CNV-5310")
Expand Down
42 changes: 30 additions & 12 deletions tests/storage/upgrade/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
from contextlib import contextmanager

from ocp_resources.virtual_machine import VirtualMachine
from ocp_resources.virtual_machine_cluster_instancetype import VirtualMachineClusterInstancetype
from ocp_resources.virtual_machine_cluster_preference import VirtualMachineClusterPreference
from ocp_resources.virtual_machine_snapshot import VirtualMachineSnapshot

from tests.utils import create_cirros_vm
from utilities.storage import write_file
from tests.storage.upgrade.constants import (
UPGRADE_FIRST_FILE_CONTENT,
UPGRADE_FIRST_FILE_NAME,
UPGRADE_SECOND_FILE_CONTENT,
UPGRADE_SECOND_FILE_NAME,
)
from utilities.constants import OS_FLAVOR_RHEL, RHEL10_PREFERENCE, U1_SMALL
from utilities.storage import data_volume_template_with_source_ref_dict, write_file_via_ssh
from utilities.virt import VirtualMachineForTests, running_vm


@contextmanager
Expand All @@ -13,19 +23,27 @@ def create_vm_for_snapshot_upgrade_tests(
client,
storage_class_for_snapshot,
cpu_model,
data_source,
):
with create_cirros_vm(
storage_class=storage_class_for_snapshot,
with VirtualMachineForTests(
name=f"vm-{vm_name}",
namespace=namespace,
client=client,
dv_name=f"dv-{vm_name}",
vm_name=f"vm-{vm_name}",
os_flavor=OS_FLAVOR_RHEL,
vm_instance_type=VirtualMachineClusterInstancetype(client=client, name=U1_SMALL),
vm_preference=VirtualMachineClusterPreference(client=client, name=RHEL10_PREFERENCE),
data_volume_template=data_volume_template_with_source_ref_dict(
data_source=data_source,
storage_class=storage_class_for_snapshot,
),
run_strategy=VirtualMachine.RunStrategy.ALWAYS,
cpu_model=cpu_model,
) as vm:
write_file(
running_vm(vm=vm)
write_file_via_ssh(
vm=vm,
filename="first-file.txt",
content="first-file",
filename=UPGRADE_FIRST_FILE_NAME,
content=UPGRADE_FIRST_FILE_CONTENT,
)
yield vm

Expand All @@ -40,9 +58,9 @@ def create_snapshot_for_upgrade(vm, client):
client=client,
) as vm_snapshot:
vm_snapshot.wait_snapshot_done()
write_file(
write_file_via_ssh(
vm=vm,
filename="second-file.txt",
content="second-file",
filename=UPGRADE_SECOND_FILE_NAME,
content=UPGRADE_SECOND_FILE_CONTENT,
)
yield vm_snapshot
6 changes: 0 additions & 6 deletions utilities/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,6 @@ def run_command_on_vm_and_check_output(
)


def run_command_on_cirros_vm_and_check_output(vm, command, expected_result):
with console.Console(vm=vm) as vm_console:
vm_console.sendline(command)
vm_console.expect(expected_result, timeout=20)


def assert_disk_serial(vm, command=_DEFAULT_DISK_SERIAL_COMMAND):
assert (
HOTPLUG_DISK_SERIAL
Expand Down
Loading