|
| 1 | +import logging |
| 2 | + |
| 3 | +import pytest |
| 4 | +from ocp_resources.cdi import CDI |
| 5 | +from ocp_resources.kubevirt import KubeVirt |
| 6 | +from ocp_resources.ssp import SSP |
| 7 | + |
| 8 | +from tests.install_upgrade_operators.constants import ENABLE_MULTI_ARCH_BOOT_IMAGE_IMPORT, MANAGED_CRS_LIST |
| 9 | +from tests.install_upgrade_operators.hco_enablement_golden_image_updates.multiarch.utils import ( |
| 10 | + CUSTOM_MULTIARCH_DATASOURCE_NAME, |
| 11 | + get_control_plane_architecture, |
| 12 | + get_no_arch_annotation_template, |
| 13 | + get_unsupported_arch_template, |
| 14 | +) |
| 15 | +from utilities.constants import ( |
| 16 | + FEATURE_GATES, |
| 17 | + KUBERNETES_ARCH_LABEL, |
| 18 | +) |
| 19 | +from utilities.hco import ( |
| 20 | + ResourceEditorValidateHCOReconcile, |
| 21 | + update_hco_templates_spec, |
| 22 | +) |
| 23 | + |
| 24 | +LOGGER = logging.getLogger(__name__) |
| 25 | + |
| 26 | +_MULTIARCH_MANAGED_CRS = [SSP, KubeVirt, CDI] |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture(scope="class") |
| 30 | +def disabled_multiarch_feature_gate(hyperconverged_resource_scope_class): |
| 31 | + with ResourceEditorValidateHCOReconcile( |
| 32 | + patches={ |
| 33 | + hyperconverged_resource_scope_class: {"spec": {FEATURE_GATES: {ENABLE_MULTI_ARCH_BOOT_IMAGE_IMPORT: False}}} |
| 34 | + }, |
| 35 | + list_resource_reconcile=_MULTIARCH_MANAGED_CRS, |
| 36 | + wait_for_reconcile_post_update=True, |
| 37 | + ): |
| 38 | + yield |
| 39 | + |
| 40 | + |
| 41 | +@pytest.fixture(scope="class") |
| 42 | +def enabled_multiarch_feature_gate(hyperconverged_resource_scope_class): |
| 43 | + feature_gates = hyperconverged_resource_scope_class.instance.spec.get(FEATURE_GATES, {}) |
| 44 | + if feature_gates.get(ENABLE_MULTI_ARCH_BOOT_IMAGE_IMPORT): |
| 45 | + yield |
| 46 | + else: |
| 47 | + with ResourceEditorValidateHCOReconcile( |
| 48 | + patches={ |
| 49 | + hyperconverged_resource_scope_class: { |
| 50 | + "spec": {FEATURE_GATES: {ENABLE_MULTI_ARCH_BOOT_IMAGE_IMPORT: True}} |
| 51 | + } |
| 52 | + }, |
| 53 | + list_resource_reconcile=_MULTIARCH_MANAGED_CRS, |
| 54 | + wait_for_reconcile_post_update=True, |
| 55 | + ): |
| 56 | + yield |
| 57 | + |
| 58 | + |
| 59 | +@pytest.fixture(scope="class") |
| 60 | +def control_plane_architecture(control_plane_nodes): |
| 61 | + return get_control_plane_architecture(control_plane_nodes=control_plane_nodes) |
| 62 | + |
| 63 | + |
| 64 | +@pytest.fixture() |
| 65 | +def single_arch_node_placement(hyperconverged_resource_scope_function, worker_architectures): |
| 66 | + single_arch = sorted(worker_architectures)[0] |
| 67 | + LOGGER.info(f"Restricting workloads nodePlacement to single architecture: {single_arch}") |
| 68 | + placement = {"nodePlacement": {"nodeSelector": {KUBERNETES_ARCH_LABEL: single_arch}}} |
| 69 | + with ResourceEditorValidateHCOReconcile( |
| 70 | + patches={hyperconverged_resource_scope_function: {"spec": {"workloads": placement}}}, |
| 71 | + list_resource_reconcile=MANAGED_CRS_LIST, |
| 72 | + wait_for_reconcile_post_update=True, |
| 73 | + ): |
| 74 | + yield |
| 75 | + |
| 76 | + |
| 77 | +@pytest.fixture() |
| 78 | +def hco_with_custom_unsupported_arch_template( |
| 79 | + admin_client, |
| 80 | + hco_namespace, |
| 81 | + hyperconverged_resource_scope_function, |
| 82 | + hyperconverged_status_templates_scope_function, |
| 83 | + golden_images_namespace, |
| 84 | +): |
| 85 | + yield from update_hco_templates_spec( |
| 86 | + admin_client=admin_client, |
| 87 | + hco_namespace=hco_namespace, |
| 88 | + hyperconverged_resource=hyperconverged_resource_scope_function, |
| 89 | + updated_template=get_unsupported_arch_template( |
| 90 | + common_templates=hyperconverged_status_templates_scope_function, |
| 91 | + ), |
| 92 | + custom_datasource_name=CUSTOM_MULTIARCH_DATASOURCE_NAME, |
| 93 | + golden_images_namespace=golden_images_namespace, |
| 94 | + ) |
| 95 | + |
| 96 | + |
| 97 | +@pytest.fixture() |
| 98 | +def hco_with_custom_no_arch_annotation_template( |
| 99 | + admin_client, |
| 100 | + hco_namespace, |
| 101 | + hyperconverged_resource_scope_function, |
| 102 | + hyperconverged_status_templates_scope_function, |
| 103 | + golden_images_namespace, |
| 104 | +): |
| 105 | + yield from update_hco_templates_spec( |
| 106 | + admin_client=admin_client, |
| 107 | + hco_namespace=hco_namespace, |
| 108 | + hyperconverged_resource=hyperconverged_resource_scope_function, |
| 109 | + updated_template=get_no_arch_annotation_template( |
| 110 | + common_templates=hyperconverged_status_templates_scope_function, |
| 111 | + ), |
| 112 | + custom_datasource_name=CUSTOM_MULTIARCH_DATASOURCE_NAME, |
| 113 | + golden_images_namespace=golden_images_namespace, |
| 114 | + ) |
0 commit comments