|
| 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" |
0 commit comments