Skip to content

Commit 09f1787

Browse files
ema-aka-youngclaude
andcommitted
CherryPicked: [4.20] [Storage] remove artifactory usage in test_cdi_config.py
Refactors CDI config tests by moving them to tests/storage/cdi_config/, removing artifactory-dependent tests, and cleaning up unused fixtures. Original PR: RedHatQE#4342 assisted by: claude code sonnet-4.5 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 5afad3e commit 09f1787

File tree

6 files changed

+195
-429
lines changed

6 files changed

+195
-429
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 & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
from ocp_resources.data_source import DataSource
1818
from ocp_resources.deployment import Deployment
1919
from ocp_resources.exceptions import ExecOnPodError
20-
from ocp_resources.resource import ResourceEditor
2120
from ocp_resources.route import Route
2221
from ocp_resources.secret import Secret
23-
from ocp_resources.storage_class import StorageClass
2422
from ocp_resources.virtual_machine_cluster_instancetype import (
2523
VirtualMachineClusterInstancetype,
2624
)
@@ -307,49 +305,6 @@ def default_fs_overhead(cdi_config):
307305
return float(cdi_config.instance.status.filesystemOverhead["global"])
308306

309307

310-
@pytest.fixture()
311-
def unset_predefined_scratch_sc(hyperconverged_resource_scope_module, cdi_config):
312-
if cdi_config.instance.spec.scratchSpaceStorageClass:
313-
empty_scratch_space_spec = {"spec": {"scratchSpaceStorageClass": ""}}
314-
with ResourceEditorValidateHCOReconcile(
315-
patches={hyperconverged_resource_scope_module: empty_scratch_space_spec},
316-
list_resource_reconcile=[CDI],
317-
):
318-
LOGGER.info(f"wait for {empty_scratch_space_spec} in CDIConfig")
319-
for sample in TimeoutSampler(
320-
wait_timeout=20,
321-
sleep=1,
322-
func=lambda: not cdi_config.instance.spec.scratchSpaceStorageClass,
323-
):
324-
if sample:
325-
break
326-
yield
327-
else:
328-
yield
329-
330-
331-
@pytest.fixture()
332-
def default_sc_as_fallback_for_scratch(unset_predefined_scratch_sc, admin_client, cdi_config, default_sc):
333-
# Based on py_config["default_storage_class"], update default SC, if needed
334-
if default_sc:
335-
yield default_sc
336-
else:
337-
for sc in StorageClass.get(dyn_client=admin_client, name=py_config["default_storage_class"]):
338-
assert sc, f"The cluster does not include {py_config['default_storage_class']} storage class"
339-
with ResourceEditor(
340-
patches={
341-
sc: {
342-
"metadata": {
343-
"annotations": {StorageClass.Annotations.IS_DEFAULT_CLASS: "true"},
344-
"name": sc.name,
345-
}
346-
}
347-
}
348-
):
349-
yield sc
350-
351-
352-
@pytest.fixture()
353308
def router_cert_secret(admin_client):
354309
router_secret = "router-certs-default"
355310
for secret in Secret.get(

0 commit comments

Comments
 (0)