Skip to content

[4.19] Update Cirros image to Fedora into test_clone.py #1303

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

Open
wants to merge 6 commits into
base: cnv-4.19
Choose a base branch
from
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
18 changes: 11 additions & 7 deletions tests/storage/cdi_clone/conftest.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
import pytest
from ocp_resources.datavolume import DataVolume

from tests.storage.utils import create_cirros_dv
from tests.storage.utils import create_fedora_dv
from utilities.storage import data_volume


@pytest.fixture(scope="module")
def cirros_dv_with_filesystem_volume_mode(
def fedora_dv_with_filesystem_volume_mode(
namespace,
storage_class_with_filesystem_volume_mode,
fedora_latest_os_params,
):
yield from create_cirros_dv(
yield from create_fedora_dv(
namespace=namespace.name,
name="cirros-fs",
name="fedora-fs",
storage_class=storage_class_with_filesystem_volume_mode,
volume_mode=DataVolume.VolumeMode.FILE,
fedora_latest_os_params=fedora_latest_os_params,
)


@pytest.fixture(scope="module")
def cirros_dv_with_block_volume_mode(
def fedora_dv_with_block_volume_mode(
namespace,
storage_class_with_block_volume_mode,
fedora_latest_os_params,
):
yield from create_cirros_dv(
yield from create_fedora_dv(
namespace=namespace.name,
name="cirros-block",
name="fedora-block",
storage_class=storage_class_with_block_volume_mode,
volume_mode=DataVolume.VolumeMode.BLOCK,
fedora_latest_os_params=fedora_latest_os_params,
)


Expand Down
40 changes: 22 additions & 18 deletions tests/storage/cdi_clone/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from ocp_resources.datavolume import DataVolume

from tests.os_params import WINDOWS_11, WINDOWS_11_TEMPLATE_LABELS
from tests.os_params import FEDORA_LATEST, WINDOWS_11, WINDOWS_11_TEMPLATE_LABELS
from tests.storage.utils import (
assert_pvc_snapshot_clone_annotation,
assert_use_populator,
Expand All @@ -16,7 +16,7 @@
create_windows_vm_validate_guest_agent_info,
)
from utilities.constants import (
OS_FLAVOR_CIRROS,
OS_FLAVOR_FEDORA,
OS_FLAVOR_WINDOWS,
TIMEOUT_1MIN,
TIMEOUT_10MIN,
Expand Down Expand Up @@ -51,9 +51,9 @@ def create_vm_from_clone_dv_template(
with VirtualMachineForTests(
name=vm_name,
namespace=namespace_name,
os_flavor=OS_FLAVOR_CIRROS,
os_flavor=OS_FLAVOR_FEDORA,
client=client,
memory_requests=Images.Cirros.DEFAULT_MEMORY_SIZE,
memory_guest=Images.Fedora.DEFAULT_MEMORY_SIZE,
data_volume_template=data_volume_template_dict(
target_dv_name=dv_name,
target_dv_namespace=namespace_name,
Expand Down Expand Up @@ -114,8 +114,8 @@ def test_successful_clone_of_large_image(
pytest.param(
{
"dv_name": "dv-source",
"image": f"{Images.Cirros.DIR}/{Images.Cirros.QCOW2_IMG}",
"dv_size": Images.Cirros.DEFAULT_DV_SIZE,
"image": FEDORA_LATEST.get("image_path"),
"dv_size": Images.Fedora.DEFAULT_DV_SIZE,
},
marks=(
pytest.mark.polarion("CNV-2148"),
Expand All @@ -140,7 +140,9 @@ def test_successful_vm_restart_with_cloned_dv(
storage_class=data_volume_multi_storage_scope_function.storage_class,
) as cdv:
cdv.wait_for_dv_success(timeout=TIMEOUT_10MIN)
with create_vm_from_dv(dv=cdv) as vm_dv:
with create_vm_from_dv(
dv=cdv, vm_name="fedora-vm", os_flavor=OS_FLAVOR_FEDORA, memory_guest=Images.Fedora.DEFAULT_MEMORY_SIZE
) as vm_dv:
restart_vm_wait_for_running_vm(vm=vm_dv, wait_for_interfaces=False)
check_disk_count_in_vm(vm=vm_dv)

Expand Down Expand Up @@ -197,8 +199,8 @@ def test_successful_vm_from_cloned_dv_windows(
pytest.param(
{
"dv_name": "dv-source",
"image": f"{Images.Cirros.DIR}/{Images.Cirros.QCOW2_IMG}",
"dv_size": Images.Cirros.DEFAULT_DV_SIZE,
"image": FEDORA_LATEST.get("image_path"),
"dv_size": Images.Fedora.DEFAULT_DV_SIZE,
},
marks=(pytest.mark.polarion("CNV-4035")),
)
Expand Down Expand Up @@ -236,9 +238,9 @@ def test_disk_image_after_clone(
[
pytest.param(
{
"dv_name": "dv-source-cirros",
"image": f"{Images.Cirros.DIR}/{Images.Cirros.QCOW2_IMG}",
"dv_size": Images.Cirros.DEFAULT_DV_SIZE,
"dv_name": "dv-source-fedora",
"image": FEDORA_LATEST.get("image_path"),
"dv_size": Images.Fedora.DEFAULT_DV_SIZE,
},
marks=(pytest.mark.polarion("CNV-3545"), pytest.mark.gating()),
),
Expand Down Expand Up @@ -269,7 +271,9 @@ def test_successful_snapshot_clone(
) as cdv:
cdv.wait_for_dv_success()
if OS_FLAVOR_WINDOWS not in data_volume_snapshot_capable_storage_scope_function.url.split("/")[-1]:
with create_vm_from_dv(dv=cdv) as vm_dv:
with create_vm_from_dv(
dv=cdv, vm_name="fedora-vm", os_flavor=OS_FLAVOR_FEDORA, memory_guest=Images.Fedora.DEFAULT_MEMORY_SIZE
) as vm_dv:
check_disk_count_in_vm(vm=vm_dv)
pvc = cdv.pvc
assert_use_populator(
Expand All @@ -287,14 +291,14 @@ def test_clone_from_fs_to_block_using_dv_template(
skip_test_if_no_block_sc,
unprivileged_client,
namespace,
cirros_dv_with_filesystem_volume_mode,
fedora_dv_with_filesystem_volume_mode,
storage_class_with_block_volume_mode,
):
create_vm_from_clone_dv_template(
vm_name="vm-5607",
dv_name="dv-5607",
namespace_name=namespace.name,
source_dv=cirros_dv_with_filesystem_volume_mode,
source_dv=fedora_dv_with_filesystem_volume_mode,
client=unprivileged_client,
volume_mode=DataVolume.VolumeMode.BLOCK,
storage_class=storage_class_with_block_volume_mode,
Expand All @@ -308,20 +312,20 @@ def test_clone_from_block_to_fs_using_dv_template(
skip_test_if_no_block_sc,
unprivileged_client,
namespace,
cirros_dv_with_block_volume_mode,
fedora_dv_with_block_volume_mode,
storage_class_with_filesystem_volume_mode,
default_fs_overhead,
):
create_vm_from_clone_dv_template(
vm_name="vm-5608",
dv_name="dv-5608",
namespace_name=namespace.name,
source_dv=cirros_dv_with_block_volume_mode,
source_dv=fedora_dv_with_block_volume_mode,
client=unprivileged_client,
volume_mode=DataVolume.VolumeMode.FILE,
# add fs overhead and round up the result
size=overhead_size_for_dv(
image_size=int(cirros_dv_with_block_volume_mode.size[:-2]),
image_size=int(fedora_dv_with_block_volume_mode.size[:-2]),
overhead_value=default_fs_overhead,
),
storage_class=storage_class_with_filesystem_volume_mode,
Expand Down
16 changes: 16 additions & 0 deletions tests/storage/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
create_cirros_dv_for_snapshot_dict,
data_volume,
get_downloaded_artifact,
get_test_artifact_server_url,
sc_volume_binding_mode_is_wffc,
write_file,
)
Expand Down Expand Up @@ -591,3 +592,18 @@ def storage_class_name_scope_module(storage_class_matrix__module__):
@pytest.fixture(scope="session")
def cluster_csi_drivers_names():
yield [csi_driver.name for csi_driver in list(CSIDriver.get())]


@pytest.fixture(scope="session")
def fedora_latest_os_params():
"""This fixture is needed as during collection pytest_testconfig is empty.
os_params or any globals using py_config in conftest cannot be used.
"""
if latest_fedora_dict := py_config.get("latest_fedora_os_dict"):
return {
"fedora_image_path": f"{get_test_artifact_server_url()}{latest_fedora_dict['image_path']}",
"fedora_dv_size": latest_fedora_dict["dv_size"],
"fedora_template_labels": latest_fedora_dict["template_labels"],
}

raise ValueError("Failed to get latest Fedora OS parameters")
24 changes: 24 additions & 0 deletions tests/storage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,30 @@ def create_cirros_dv(
yield dv


def create_fedora_dv(
namespace,
name,
storage_class,
fedora_latest_os_params,
access_modes=None,
volume_mode=None,
client=None,
dv_size=Images.Fedora.DEFAULT_DV_SIZE,
):
with create_dv(
dv_name=f"dv-{name}",
namespace=namespace,
url=fedora_latest_os_params["fedora_image_path"],
size=dv_size,
storage_class=storage_class,
access_modes=access_modes,
volume_mode=volume_mode,
client=client,
) as dv:
dv.wait_for_dv_success()
yield dv


def check_snapshot_indication(snapshot, is_online):
snapshot_indications = snapshot.instance.status.indications
online = "Online"
Expand Down
8 changes: 4 additions & 4 deletions utilities/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
CDI_LABEL,
HOTPLUG_DISK_SERIAL,
HPP_POOL,
OS_FLAVOR_CIRROS,
OS_FLAVOR_FEDORA,
OS_FLAVOR_WINDOWS,
POD_CONTAINER_SPEC,
TIMEOUT_1SEC,
Expand Down Expand Up @@ -994,13 +994,13 @@ def wait_for_dv_expected_restart_count(dv, expected_result):
@contextmanager
def create_vm_from_dv(
dv,
vm_name="cirros-vm",
vm_name="fedora-vm",
image=None,
start=True,
os_flavor=OS_FLAVOR_CIRROS,
os_flavor=OS_FLAVOR_FEDORA,
node_selector=None,
cpu_model=None,
memory_guest=Images.Cirros.DEFAULT_MEMORY_SIZE,
memory_guest=Images.Fedora.DEFAULT_MEMORY_SIZE,
wait_for_cloud_init=False,
):
with virt_util.VirtualMachineForTests(
Expand Down