Skip to content

Commit 742bbb4

Browse files
[Storage] remove artifactory usage in test_cdi_config.py (#4342)
##### Short description: This PR replaces the use of the artifactory images with the DataSource Fedora in tests/storage/test_cdi_config.py and moves it to its dedicated folder. ##### More details: https://redhat.atlassian.net/browse/CNV-83362 ##### What this PR does / why we need it: ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: Assisted by Claude Code ##### 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** * Added a focused post-upgrade test suite validating CDI config: upload-proxy routing, operator-driven reconciliation, and propagation of tunable settings; includes new fixtures and test constants to support these scenarios. * **Refactor** * Removed an older overlapping test module, legacy fixtures and helpers, and an unused storage utility, consolidating and simplifying the test surface. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Emanuele Prella <eprella@redhat.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 914c41c commit 742bbb4

File tree

6 files changed

+195
-432
lines changed

6 files changed

+195
-432
lines changed

tests/storage/cdi_config/__init__.py

Whitespace-only changes.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Pytest conftest file for CNV CDI Config tests
5+
"""
6+
7+
import pytest
8+
from ocp_resources.cdi import CDI
9+
10+
from utilities.hco import ResourceEditorValidateHCOReconcile
11+
from utilities.storage import cdi_feature_gate_list_with_added_feature
12+
13+
14+
@pytest.fixture()
15+
def cdi_with_extra_non_existent_feature_gate(cdi):
16+
with ResourceEditorValidateHCOReconcile(
17+
patches={
18+
cdi: {
19+
"spec": {
20+
"config": {
21+
"featureGates": cdi_feature_gate_list_with_added_feature(feature="ExtraNonExistentFeature")
22+
}
23+
},
24+
},
25+
},
26+
list_resource_reconcile=[CDI],
27+
wait_for_reconcile_post_update=True,
28+
):
29+
yield cdi
30+
31+
32+
@pytest.fixture()
33+
def initial_cdi_config_from_cr(cdi):
34+
return cdi.instance.to_dict()["spec"]["config"]
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
"""CDIConfig tests"""
2+
3+
import pytest
4+
from ocp_resources.cdi import CDI
5+
from ocp_resources.route import Route
6+
from timeout_sampler import TimeoutSampler
7+
8+
from tests.storage.utils import LOGGER
9+
from utilities.constants import CDI_UPLOADPROXY
10+
from utilities.hco import ResourceEditorValidateHCOReconcile
11+
12+
pytestmark = pytest.mark.post_upgrade
13+
14+
STORAGE_WORKLOADS_DICT = {
15+
"limits": {"cpu": "505m", "memory": "2Gi"},
16+
"requests": {"cpu": "252m", "memory": "1Gi"},
17+
}
18+
NON_EXISTENT_SCRATCH_SC_DICT = {"scratchSpaceStorageClass": "NonExistentSC"}
19+
INSECURE_REGISTRIES_LIST = ["added-private-registry:5000"]
20+
21+
22+
@pytest.mark.sno
23+
@pytest.mark.gating
24+
@pytest.mark.polarion("CNV-2208")
25+
@pytest.mark.s390x
26+
def test_cdi_config_exists(cdi_config, upload_proxy_route):
27+
"""
28+
Test that CDIConfig exists and has the expected upload_proxy_url
29+
"""
30+
assert cdi_config.upload_proxy_url == upload_proxy_route.host, (
31+
f"Expected upload_proxy_url to match upload-proxy route host {upload_proxy_route.host},"
32+
f"got {cdi_config.upload_proxy_url}"
33+
)
34+
35+
36+
@pytest.mark.destructive
37+
@pytest.mark.polarion("CNV-2209")
38+
def test_different_route_for_upload_proxy(hco_namespace, cdi_config, uploadproxy_route_deleted):
39+
"""
40+
Test that CDIConfig's upload_proxy_url changes when the upload-proxy route is deleted
41+
and recreated with a different host
42+
"""
43+
with Route(
44+
namespace=hco_namespace.name,
45+
name="new-route-uploadproxy",
46+
service=CDI_UPLOADPROXY,
47+
) as new_route:
48+
cdi_config.wait_until_upload_url_changed(uploadproxy_url=new_route.host)
49+
50+
51+
@pytest.mark.sno
52+
@pytest.mark.polarion("CNV-2215")
53+
@pytest.mark.s390x
54+
def test_route_for_different_service(admin_client, cdi_config, upload_proxy_route):
55+
"""
56+
Test that CDIConfig's upload_proxy_url does not change when a route for a different service is created
57+
"""
58+
with Route(
59+
namespace=upload_proxy_route.namespace, name="cdi-api", service="cdi-api", client=admin_client
60+
) as cdi_api_route:
61+
assert cdi_config.upload_proxy_url != cdi_api_route.host, (
62+
f"upload_proxy_url unexpectedly changed to cdi-api route host {cdi_api_route.host}"
63+
)
64+
assert cdi_config.upload_proxy_url == upload_proxy_route.host, (
65+
f"Expected upload_proxy_url to remain {upload_proxy_route.host}, got {cdi_config.upload_proxy_url}"
66+
)
67+
68+
69+
@pytest.mark.sno
70+
@pytest.mark.polarion("CNV-2216")
71+
@pytest.mark.s390x
72+
def test_upload_proxy_url_overridden(admin_client, cdi_config, namespace, cdi_config_upload_proxy_overridden):
73+
"""
74+
Test that CDIConfig's upload_proxy_url does not change when overridden
75+
and a new route is created for upload-proxy service
76+
"""
77+
with Route(namespace=namespace.name, name="my-route", service=CDI_UPLOADPROXY, client=admin_client) as new_route:
78+
assert cdi_config.upload_proxy_url != new_route.host, (
79+
f"upload_proxy_url should remain overridden and not switch to route host {new_route.host}"
80+
)
81+
82+
83+
@pytest.mark.sno
84+
@pytest.mark.polarion("CNV-6312")
85+
@pytest.mark.s390x
86+
def test_cdi_spec_reconciled_by_hco(initial_cdi_config_from_cr, cdi_with_extra_non_existent_feature_gate):
87+
"""
88+
Test that added feature gate on the CDI CR does not persist
89+
(HCO Should reconcile back changes on the CDI CR)
90+
"""
91+
assert (
92+
cdi_with_extra_non_existent_feature_gate.instance.to_dict()["spec"]["config"] == initial_cdi_config_from_cr
93+
), "HCO should have reconciled back changes"
94+
95+
96+
@pytest.mark.sno
97+
@pytest.mark.parametrize(
98+
("hco_updated_spec_stanza", "expected_in_cdi_config_from_cr"),
99+
[
100+
pytest.param(
101+
{"resourceRequirements": {"storageWorkloads": STORAGE_WORKLOADS_DICT}},
102+
{"podResourceRequirements": STORAGE_WORKLOADS_DICT},
103+
marks=(pytest.mark.polarion("CNV-6000")),
104+
id="test_storage_workloads_in_hco_propagated_to_cdi_cr",
105+
),
106+
pytest.param(
107+
NON_EXISTENT_SCRATCH_SC_DICT,
108+
NON_EXISTENT_SCRATCH_SC_DICT,
109+
marks=(pytest.mark.polarion("CNV-6001")),
110+
id="test_scratch_sc_in_hco_propagated_to_cdi_cr",
111+
),
112+
pytest.param(
113+
{"storageImport": {"insecureRegistries": INSECURE_REGISTRIES_LIST}},
114+
{"insecureRegistries": INSECURE_REGISTRIES_LIST},
115+
marks=(pytest.mark.polarion("CNV-6092")),
116+
id="test_insecure_registries_in_hco_propagated_to_cdi_cr",
117+
),
118+
],
119+
)
120+
@pytest.mark.s390x
121+
def test_cdi_tunables_in_hco_propagated_to_cr(
122+
hyperconverged_resource_scope_module,
123+
cdi,
124+
namespace,
125+
expected_in_cdi_config_from_cr,
126+
hco_updated_spec_stanza,
127+
):
128+
"""
129+
Test that the exposed CDI-related tunables in HCO are propagated to the CDI CR
130+
"""
131+
initial_cdi_config_from_cr = cdi.instance.to_dict()["spec"]["config"]
132+
133+
def _verify_propagation():
134+
current_cdi_config_from_cr = cdi.instance.to_dict()["spec"]["config"]
135+
return {
136+
**initial_cdi_config_from_cr,
137+
**expected_in_cdi_config_from_cr,
138+
} == current_cdi_config_from_cr
139+
140+
def _verify_revert() -> bool:
141+
current_cdi_config_from_cr = cdi.instance.to_dict()["spec"]["config"]
142+
return current_cdi_config_from_cr == initial_cdi_config_from_cr
143+
144+
with ResourceEditorValidateHCOReconcile(
145+
patches={hyperconverged_resource_scope_module: {"spec": hco_updated_spec_stanza}},
146+
list_resource_reconcile=[CDI],
147+
):
148+
propagated = False
149+
for sample in TimeoutSampler(wait_timeout=20, sleep=1, func=_verify_propagation):
150+
if sample:
151+
propagated = True
152+
break
153+
assert propagated, "CDI config was not updated from HCO tunables within timeout"
154+
155+
LOGGER.info("Check values revert back to original")
156+
reverted = False
157+
for sample in TimeoutSampler(wait_timeout=20, sleep=1, func=_verify_revert):
158+
if sample:
159+
reverted = True
160+
break
161+
assert reverted, "CDI config did not revert to the original values after restore"

tests/storage/conftest.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
from ocp_resources.data_source import DataSource
2020
from ocp_resources.deployment import Deployment
2121
from ocp_resources.exceptions import ExecOnPodError
22-
from ocp_resources.resource import ResourceEditor
2322
from ocp_resources.route import Route
2423
from ocp_resources.secret import Secret
25-
from ocp_resources.storage_class import StorageClass
2624
from ocp_resources.virtual_machine_cluster_instancetype import (
2725
VirtualMachineClusterInstancetype,
2826
)
@@ -316,48 +314,6 @@ def default_fs_overhead(cdi_config):
316314
return float(cdi_config.instance.status.filesystemOverhead["global"])
317315

318316

319-
@pytest.fixture()
320-
def unset_predefined_scratch_sc(hyperconverged_resource_scope_module, cdi_config):
321-
if cdi_config.instance.spec.scratchSpaceStorageClass:
322-
empty_scratch_space_spec = {"spec": {"scratchSpaceStorageClass": ""}}
323-
with ResourceEditorValidateHCOReconcile(
324-
patches={hyperconverged_resource_scope_module: empty_scratch_space_spec},
325-
list_resource_reconcile=[CDI],
326-
):
327-
LOGGER.info(f"wait for {empty_scratch_space_spec} in CDIConfig")
328-
for sample in TimeoutSampler(
329-
wait_timeout=20,
330-
sleep=1,
331-
func=lambda: not cdi_config.instance.spec.scratchSpaceStorageClass,
332-
):
333-
if sample:
334-
break
335-
yield
336-
else:
337-
yield
338-
339-
340-
@pytest.fixture()
341-
def default_sc_as_fallback_for_scratch(unset_predefined_scratch_sc, admin_client, cdi_config, default_sc):
342-
# Based on py_config["default_storage_class"], update default SC, if needed
343-
if default_sc:
344-
yield default_sc
345-
else:
346-
for sc in StorageClass.get(client=admin_client, name=py_config["default_storage_class"]):
347-
assert sc, f"The cluster does not include {py_config['default_storage_class']} storage class"
348-
with ResourceEditor(
349-
patches={
350-
sc: {
351-
"metadata": {
352-
"annotations": {StorageClass.Annotations.IS_DEFAULT_CLASS: "true"},
353-
"name": sc.name,
354-
}
355-
}
356-
}
357-
):
358-
yield sc
359-
360-
361317
@pytest.fixture()
362318
def router_cert_secret(admin_client):
363319
router_secret = "router-certs-default"
@@ -429,16 +385,6 @@ def rhel_vm_name(request):
429385
return request.param["vm_name"]
430386

431387

432-
@pytest.fixture(scope="session")
433-
def available_hpp_storage_class(skip_test_if_no_hpp_sc, cluster_storage_classes):
434-
"""
435-
Get an HPP storage class if there is any in the cluster
436-
"""
437-
for storage_class in cluster_storage_classes:
438-
if storage_class.name in HPP_STORAGE_CLASSES:
439-
return storage_class
440-
441-
442388
@pytest.fixture(scope="module")
443389
def artifactory_secret_scope_module(namespace):
444390
artifactory_secret = get_artifactory_secret(namespace=namespace.name)

0 commit comments

Comments
 (0)