From 538ec9041a308ca4272afb845ca0795c912d4f12 Mon Sep 17 00:00:00 2001 From: Jim Ryan Date: Mon, 16 Sep 2024 10:39:39 +0100 Subject: [PATCH] fix test --- .../global-configuration.yaml | 4 +- .../suite/test_udp_http_listeners_together.py | 62 ++++++++++++------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/tests/data/udp-http-listeners-together/global-configuration.yaml b/tests/data/udp-http-listeners-together/global-configuration.yaml index 155b34f0ef..861b3e1e04 100644 --- a/tests/data/udp-http-listeners-together/global-configuration.yaml +++ b/tests/data/udp-http-listeners-together/global-configuration.yaml @@ -6,8 +6,8 @@ metadata: spec: listeners: - name: udp-listener - port: 5353 + port: 5454 protocol: UDP - name: http-listener - port: 5353 + port: 5454 protocol: HTTP diff --git a/tests/suite/test_udp_http_listeners_together.py b/tests/suite/test_udp_http_listeners_together.py index de340d062d..7ee7dd734c 100644 --- a/tests/suite/test_udp_http_listeners_together.py +++ b/tests/suite/test_udp_http_listeners_together.py @@ -1,13 +1,20 @@ +import time + import pytest from settings import TEST_DATA -from suite.utils.custom_resources_utils import patch_gc_from_yaml, patch_ts_from_yaml, read_custom_resource +from suite.utils.custom_resources_utils import ( + create_ts_from_yaml, + delete_ts, + patch_gc_from_yaml, + read_custom_resource, + read_ts, +) from suite.utils.resources_utils import get_first_pod_name, get_ts_nginx_template_conf, wait_before_test from suite.utils.vs_vsr_resources_utils import get_vs_nginx_template_conf, patch_virtual_server_from_yaml @pytest.mark.vs @pytest.mark.ts -@pytest.mark.vs_ipv6 @pytest.mark.parametrize( "crd_ingress_controller, virtual_server_setup, transport_server_setup", [ @@ -35,6 +42,11 @@ def test_udp_and_http_listeners_together( transport_server_setup, ): + wait_before_test() + existing_ts = read_ts(kube_apis.custom_objects, transport_server_setup.namespace, transport_server_setup.name) + # delete TS and VS first + delete_ts(kube_apis.custom_objects, existing_ts, transport_server_setup.namespace) + global_config_file = f"{TEST_DATA}/udp-http-listeners-together/global-configuration.yaml" transport_server_file = f"{TEST_DATA}/udp-http-listeners-together/transport-server.yaml" virtual_server_file = f"{TEST_DATA}/udp-http-listeners-together/virtual-server.yaml" @@ -42,9 +54,7 @@ def test_udp_and_http_listeners_together( gc_namespace = "nginx-ingress" patch_gc_from_yaml(kube_apis.custom_objects, gc_resource_name, global_config_file, gc_namespace) - patch_ts_from_yaml( - kube_apis.custom_objects, "transport-server", transport_server_file, transport_server_setup.namespace - ) + create_ts_from_yaml(kube_apis.custom_objects, transport_server_file, transport_server_setup.namespace) patch_virtual_server_from_yaml( kube_apis.custom_objects, "virtual-server-status", virtual_server_file, virtual_server_setup.namespace ) @@ -65,21 +75,31 @@ def test_udp_and_http_listeners_together( ic_pod_name, ingress_controller_prerequisites.namespace, ) - assert "listen 5353;" in vs_config - assert "listen 5353 udp;" in ts_config + assert "listen 5454;" in vs_config + assert "listen 5454 udp;" in ts_config - transport_server_response = read_custom_resource( - kube_apis.custom_objects, - transport_server_setup.namespace, - "transportservers", - "transport-server", - ) - virtual_server_response = read_custom_resource( - kube_apis.custom_objects, - virtual_server_setup.namespace, - "virtualservers", - "virtual-server-status", - ) - assert transport_server_response["status"] and transport_server_response["status"]["state"] == "Valid" + for _ in range(30): + transport_server_response = read_custom_resource( + kube_apis.custom_objects, + transport_server_setup.namespace, + "transportservers", + "transport-server", + ) + if "status" in transport_server_response and transport_server_response["status"]["state"] == "Valid": + break + time.sleep(1) + else: + pytest.fail("TransportServer status did not become 'Valid' within the timeout period") - assert virtual_server_response["status"] and virtual_server_response["status"]["state"] == "Valid" + for _ in range(30): + virtual_server_response = read_custom_resource( + kube_apis.custom_objects, + virtual_server_setup.namespace, + "virtualservers", + "virtual-server-status", + ) + if "status" in virtual_server_response and virtual_server_response["status"]["state"] == "Valid": + break + time.sleep(1) + else: + pytest.fail("VirtualServer status did not become 'Valid' within the timeout period")