|
| 1 | +import pytest |
| 2 | +from settings import TEST_DATA |
| 3 | +from suite.utils.resources_utils import ( |
| 4 | + create_license, |
| 5 | + ensure_connection_to_public_endpoint, |
| 6 | + get_events_for_object, |
| 7 | + get_first_pod_name, |
| 8 | + get_reload_count, |
| 9 | + is_secret_present, |
| 10 | + replace_configmap_from_yaml, |
| 11 | + wait_before_test, |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | +def assert_event(event_list, event_type, reason, message_substring): |
| 16 | + """ |
| 17 | + Assert that an event with specific type, reason, and message substring exists. |
| 18 | +
|
| 19 | + :param event_list: List of events |
| 20 | + :param event_type: 'Normal' or 'Warning' |
| 21 | + :param reason: Event reason |
| 22 | + :param message_substring: Substring expected in the event message |
| 23 | + """ |
| 24 | + for event in event_list: |
| 25 | + if event.type == event_type and event.reason == reason and message_substring in event.message: |
| 26 | + return |
| 27 | + assert ( |
| 28 | + False |
| 29 | + ), f"Expected event with type '{event_type}', reason '{reason}', and message containing '{message_substring}' not found." |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.skip_for_nginx_oss |
| 33 | +@pytest.mark.ingresses |
| 34 | +@pytest.mark.smoke |
| 35 | +class TestMGMTConfigMap: |
| 36 | + @pytest.mark.parametrize( |
| 37 | + "ingress_controller", |
| 38 | + [ |
| 39 | + pytest.param( |
| 40 | + {"extra_args": ["-enable-prometheus-metrics"]}, |
| 41 | + ) |
| 42 | + ], |
| 43 | + indirect=["ingress_controller"], |
| 44 | + ) |
| 45 | + def test_mgmt_configmap_events( |
| 46 | + self, |
| 47 | + cli_arguments, |
| 48 | + kube_apis, |
| 49 | + ingress_controller_prerequisites, |
| 50 | + ingress_controller, |
| 51 | + ingress_controller_endpoint, |
| 52 | + ): |
| 53 | + ensure_connection_to_public_endpoint( |
| 54 | + ingress_controller_endpoint.public_ip, |
| 55 | + ingress_controller_endpoint.port, |
| 56 | + ingress_controller_endpoint.port_ssl, |
| 57 | + ) |
| 58 | + ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace) |
| 59 | + metrics_url = ( |
| 60 | + f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.metrics_port}/metrics" |
| 61 | + ) |
| 62 | + |
| 63 | + print("Step 1: get reload count") |
| 64 | + reload_count = get_reload_count(metrics_url) |
| 65 | + |
| 66 | + wait_before_test(1) |
| 67 | + print(f"Step 1a: initial reload count is {reload_count}") |
| 68 | + |
| 69 | + print("Step 2: create duplicate existing secret with new name") |
| 70 | + license_name = create_license( |
| 71 | + kube_apis.v1, |
| 72 | + ingress_controller_prerequisites.namespace, |
| 73 | + cli_arguments["plus-jwt"], |
| 74 | + license_token_name="license-token-changed", |
| 75 | + ) |
| 76 | + assert is_secret_present(kube_apis.v1, license_name, ingress_controller_prerequisites.namespace) |
| 77 | + |
| 78 | + print("Step 3: update the ConfigMap/license-token-secret-name to the new secret") |
| 79 | + replace_configmap_from_yaml( |
| 80 | + kube_apis.v1, |
| 81 | + "nginx-config-mgmt", |
| 82 | + ingress_controller_prerequisites.namespace, |
| 83 | + f"{TEST_DATA}/mgmt-configmap-keys/plus-token-name-keys.yaml", |
| 84 | + ) |
| 85 | + |
| 86 | + wait_before_test() |
| 87 | + |
| 88 | + print("Step 4: check reload count has incremented") |
| 89 | + new_reload_count = get_reload_count(metrics_url) |
| 90 | + print(f"Step 4a: new reload count is {new_reload_count}") |
| 91 | + assert new_reload_count > reload_count |
| 92 | + |
| 93 | + print("Step 5: check pod for SecretUpdated event") |
| 94 | + events = get_events_for_object( |
| 95 | + kube_apis.v1, |
| 96 | + ingress_controller_prerequisites.namespace, |
| 97 | + ic_pod_name, |
| 98 | + ) |
| 99 | + |
| 100 | + # Assert that the 'SecretUpdated' event is present |
| 101 | + assert_event( |
| 102 | + events, |
| 103 | + "Normal", |
| 104 | + "SecretUpdated", |
| 105 | + f"the special Secret {ingress_controller_prerequisites.namespace}/{license_name} was updated", |
| 106 | + ) |
0 commit comments