Skip to content

Commit 24f8983

Browse files
[4.21][Storage] remove artifactory usage in test_cdi_config.py (#4429)
Refactors CDI config tests by moving them to tests/storage/cdi_config/, removing artifactory-dependent tests, and cleaning up unused fixtures. Original PR: #4342 assisted by: claude code sonnet-4.5 ##### Short description: ##### More details: ##### What this PR does / why we need it: ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: Backported using /backport skill ##### 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". --> Signed-off-by: Emanuele Prella <eprella@redhat.com>
1 parent 39e5a62 commit 24f8983

File tree

6 files changed

+195
-443
lines changed

6 files changed

+195
-443
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
@@ -18,10 +18,8 @@
1818
from ocp_resources.data_source import DataSource
1919
from ocp_resources.deployment import Deployment
2020
from ocp_resources.exceptions import ExecOnPodError
21-
from ocp_resources.resource import ResourceEditor
2221
from ocp_resources.route import Route
2322
from ocp_resources.secret import Secret
24-
from ocp_resources.storage_class import StorageClass
2523
from ocp_resources.virtual_machine_cluster_instancetype import (
2624
VirtualMachineClusterInstancetype,
2725
)
@@ -313,48 +311,6 @@ def default_fs_overhead(cdi_config):
313311
return float(cdi_config.instance.status.filesystemOverhead["global"])
314312

315313

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

428384

429-
@pytest.fixture(scope="session")
430-
def available_hpp_storage_class(skip_test_if_no_hpp_sc, cluster_storage_classes):
431-
"""
432-
Get an HPP storage class if there is any in the cluster
433-
"""
434-
for storage_class in cluster_storage_classes:
435-
if storage_class.name in HPP_STORAGE_CLASSES:
436-
return storage_class
437-
438-
439385
@pytest.fixture(scope="module")
440386
def artifactory_secret_scope_module(namespace):
441387
artifactory_secret = get_artifactory_secret(namespace=namespace.name)

0 commit comments

Comments
 (0)