Skip to content

Commit d848361

Browse files
authored
[Storage] replace artifactory with DataSource in test_golden_image (#4095)
##### Short description: This PR replaces the use of the artifactory with the DataSource Fedora in tests/storage/golden_image/test_golden_image.py https://issues.redhat.com/browse/CNV-79290 ##### More details: ##### What this PR does / why we need it: ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: There is another PR #3892 that contains changes used by this PR: - moving fedora_data_source_scope_module fixture from tests/storage/cdi_clone/conftest.py to tests/storage/conftest.py - adding a separate function get_dv_size_from_datasource to get the size from a DataSource (the function is placed in tests/storage/utils.py since it will be used both in tests/storage/golden_image/test_golden_image.py and tests/storage/restricted_namespace_cloning (#3892)) ##### jira-ticket: <!-- full-ticket-url needs to be provided. This would add a link to the pull request to the jira and close it when the pull request is merged If the task is not tracked by a Jira ticket, just write "NONE". --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Updated storage tests to use dynamic data sources instead of hardcoded image URLs and sizes. * Added support for Fedora OS flavor in test fixtures alongside existing RHEL configurations. * Refactored golden image tests to use data source references for DataVolume creation, providing more flexible and maintainable test scenarios. * Improved test utility functions to support dynamic size extraction from data sources. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent fef3832 commit d848361

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

tests/storage/cdi_clone/conftest.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import pytest
2-
from ocp_resources.data_source import DataSource
32
from ocp_resources.datavolume import DataVolume
43

54
from tests.storage.utils import create_cirros_dv
6-
from utilities.constants import OS_FLAVOR_FEDORA
75
from utilities.storage import data_volume
86

97

@@ -50,13 +48,3 @@ def data_volume_snapshot_capable_storage_scope_function(
5048
storage_class_matrix=storage_class_matrix_snapshot_matrix__function__,
5149
client=namespace.client,
5250
)
53-
54-
55-
@pytest.fixture(scope="module")
56-
def fedora_data_source_scope_module(golden_images_namespace):
57-
return DataSource(
58-
namespace=golden_images_namespace.name,
59-
name=OS_FLAVOR_FEDORA,
60-
client=golden_images_namespace.client,
61-
ensure_exists=True,
62-
)

tests/storage/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
CDI_OPERATOR,
5252
CDI_UPLOADPROXY,
5353
CNV_TEST_SERVICE_ACCOUNT,
54+
OS_FLAVOR_FEDORA,
5455
OS_FLAVOR_RHEL,
5556
RHEL10_PREFERENCE,
5657
SECURITY_CONTEXT,
@@ -583,6 +584,16 @@ def rhel10_data_source_scope_module(golden_images_namespace):
583584
)
584585

585586

587+
@pytest.fixture(scope="module")
588+
def fedora_data_source_scope_module(golden_images_namespace):
589+
return DataSource(
590+
namespace=golden_images_namespace.name,
591+
name=OS_FLAVOR_FEDORA,
592+
client=golden_images_namespace.client,
593+
ensure_exists=True,
594+
)
595+
596+
586597
@pytest.fixture(scope="class")
587598
def unique_suffix():
588599
return shortuuid.ShortUUID().random(length=4).lower()

tests/storage/golden_image/test_golden_image.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pytest_testconfig import config as py_config
88

99
from tests.os_params import RHEL_LATEST
10-
from utilities.artifactory import get_test_artifact_server_url
10+
from tests.storage.utils import get_dv_size_from_datasource
1111
from utilities.constants import PVC, TIMEOUT_20MIN
1212
from utilities.storage import ErrorMsg, create_dv
1313

@@ -34,14 +34,20 @@ def dv_created_by_unprivileged_user_with_rolebinding(
3434
golden_images_edit_rolebinding,
3535
unprivileged_client,
3636
storage_class_name_scope_function,
37+
fedora_data_source_scope_module,
3738
):
39+
size = get_dv_size_from_datasource(data_source=fedora_data_source_scope_module)
3840
with create_dv(
3941
client=unprivileged_client,
4042
dv_name=f"{request.param['dv_name']}-{storage_class_name_scope_function}",
4143
namespace=golden_images_namespace.name,
42-
url=f"{get_test_artifact_server_url()}{LATEST_RHEL_IMAGE}",
43-
size=RHEL_IMAGE_SIZE,
44+
size=size,
4445
storage_class=storage_class_name_scope_function,
46+
source_ref={
47+
"kind": fedora_data_source_scope_module.kind,
48+
"name": fedora_data_source_scope_module.name,
49+
"namespace": fedora_data_source_scope_module.namespace,
50+
},
4551
) as dv:
4652
yield dv
4753

@@ -52,19 +58,25 @@ def dv_created_by_unprivileged_user_with_rolebinding(
5258
def test_regular_user_cant_create_dv_in_ns(
5359
golden_images_namespace,
5460
unprivileged_client,
61+
fedora_data_source_scope_module,
5562
):
5663
LOGGER.info("Try as a regular user, to create a DV in golden image NS and receive the proper error")
64+
size = get_dv_size_from_datasource(data_source=fedora_data_source_scope_module)
5765
with pytest.raises(
5866
ApiException,
5967
match=ErrorMsg.CANNOT_CREATE_RESOURCE,
6068
):
6169
with create_dv(
6270
dv_name="cnv-4755",
6371
namespace=golden_images_namespace.name,
64-
url=f"{get_test_artifact_server_url()}{LATEST_RHEL_IMAGE}",
65-
size=RHEL_IMAGE_SIZE,
72+
size=size,
6673
storage_class=py_config["default_storage_class"],
6774
client=unprivileged_client,
75+
source_ref={
76+
"kind": fedora_data_source_scope_module.kind,
77+
"name": fedora_data_source_scope_module.name,
78+
"namespace": fedora_data_source_scope_module.namespace,
79+
},
6880
):
6981
return
7082

tests/storage/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ocp_resources.cluster_role import ClusterRole
1111
from ocp_resources.config_map import ConfigMap
1212
from ocp_resources.daemonset import DaemonSet
13+
from ocp_resources.data_source import DataSource
1314
from ocp_resources.datavolume import DataVolume
1415
from ocp_resources.hostpath_provisioner import HostPathProvisioner
1516
from ocp_resources.pod import Pod
@@ -503,3 +504,12 @@ def assert_disk_bus(vm: VirtualMachineForTests, volume: DataVolume, expected_bus
503504
assert disk is not None, f"Disk {volume.name} not found in VM {vm.name}"
504505
actual_bus = disk.get("disk", {}).get("bus")
505506
assert actual_bus == expected_bus, f"Disk {volume.name} has bus '{actual_bus}' but expected '{expected_bus}'"
507+
508+
509+
def get_dv_size_from_datasource(data_source: DataSource) -> str | int | None:
510+
source_dict = data_source.source.instance.to_dict()
511+
source_spec_dict = source_dict["spec"]
512+
dv_size = source_spec_dict.get("resources", {}).get("requests", {}).get("storage") or source_dict.get(
513+
"status", {}
514+
).get("restoreSize")
515+
return dv_size

0 commit comments

Comments
 (0)