From e229caac5c96eb649902c016495a44799980d3ad Mon Sep 17 00:00:00 2001 From: "Louise K. Schmidtgen" Date: Mon, 8 Jul 2024 12:37:40 +0200 Subject: [PATCH] Follow up ingress & gateway e2e tests (#528) * Remove unrelated tests * Moonray * update gateway test * cleanup comments * update ingress test * Revert "Remove unrelated tests" This reverts commit 35b33386865e8114e343c00cefa10f77d0982bee. * Revert "Moonray" This reverts commit fe323026208e5cda8be8dbb178c8c3fbd7e5bb54. * change retry params ingress test * angry linter * update name --- tests/integration/tests/test_gateway.py | 69 +++++++++++-------------- tests/integration/tests/test_ingress.py | 36 ++++++------- 2 files changed, 46 insertions(+), 59 deletions(-) diff --git a/tests/integration/tests/test_gateway.py b/tests/integration/tests/test_gateway.py index 77f017a7a..9770af46f 100644 --- a/tests/integration/tests/test_gateway.py +++ b/tests/integration/tests/test_gateway.py @@ -11,6 +11,31 @@ LOG = logging.getLogger(__name__) +def get_gateway_service_node_port(p): + gateway_http_port = None + services = json.loads(p.stdout.decode()) + + gateway_services = [ + svc + for svc in services["items"] + if ( + svc["metadata"].get("labels").get("projectcontour.io/owning-gateway-name") + == "my-gateway" + or svc["metadata"].get("labels").get("io.cilium.gateway/owning-gateway") + == "my-gateway" + ) + ] + + for svc in gateway_services: + for port in svc["spec"]["ports"]: + if port["port"] == 80: + gateway_http_port = port["nodePort"] + break + if gateway_http_port: + return gateway_http_port + return None + + def test_gateway(session_instance: harness.Instance): manifest = MANIFESTS_DIR / "gateway-test.yaml" session_instance.exec( @@ -40,45 +65,13 @@ def test_gateway(session_instance: harness.Instance): # Get gateway node port gateway_http_port = None - util.stubbornly(retries=5, delay_s=2).on(session_instance).until( - lambda p: "my-gateway" in p.stdout.decode() - ).exec(["k8s", "kubectl", "get", "service", "-o", "json"]) - - p = session_instance.exec( - [ - "k8s", - "kubectl", - "get", - "service", - "-o=json", - ], - capture_output=True, + result = ( + util.stubbornly(retries=7, delay_s=3) + .on(session_instance) + .until(lambda p: get_gateway_service_node_port(p) is not None) + .exec(["k8s", "kubectl", "get", "service", "-o", "json"]) ) - - services = json.loads(p.stdout.decode()) - - gateway_services = [ - svc - for svc in services["items"] - if ( - svc["metadata"].get("labels").get("projectcontour.io/owning-gateway-name") - == "my-gateway" - or svc["metadata"].get("labels").get("io.cilium.gateway/owning-gateway") - == "my-gateway" - ) - ] - - assert ( - len(gateway_services) > 0 - ), "No gateway services found that are owned by my-gateway." - - for svc in gateway_services: - for port in svc["spec"]["ports"]: - if port["port"] == 80: - gateway_http_port = port["nodePort"] - break - if gateway_http_port: - break + gateway_http_port = get_gateway_service_node_port(result) assert gateway_http_port is not None, "No ingress nodePort found." diff --git a/tests/integration/tests/test_ingress.py b/tests/integration/tests/test_ingress.py index d1c9d870f..f2cccc61c 100644 --- a/tests/integration/tests/test_ingress.py +++ b/tests/integration/tests/test_ingress.py @@ -12,24 +12,7 @@ LOG = logging.getLogger(__name__) -def test_ingress(session_instance: List[harness.Instance]): - - util.stubbornly(retries=5, delay_s=2).on(session_instance).until( - lambda p: "ingress" in p.stdout.decode() - ).exec(["k8s", "kubectl", "get", "service", "-A", "-o", "json"]) - - p = session_instance.exec( - [ - "k8s", - "kubectl", - "get", - "service", - "-A", - "-o=json", - ], - capture_output=True, - ) - +def get_ingress_service_node_port(p): ingress_http_port = None services = json.loads(p.stdout.decode()) @@ -42,15 +25,26 @@ def test_ingress(session_instance: List[harness.Instance]): ) ] - assert len(ingress_services) > 0, "No ingress services found." - for svc in ingress_services: for port in svc["spec"]["ports"]: if port["port"] == 80: ingress_http_port = port["nodePort"] break if ingress_http_port: - break + return ingress_http_port + return None + + +def test_ingress(session_instance: List[harness.Instance]): + + result = ( + util.stubbornly(retries=7, delay_s=3) + .on(session_instance) + .until(lambda p: get_ingress_service_node_port(p) is not None) + .exec(["k8s", "kubectl", "get", "service", "-A", "-o", "json"]) + ) + + ingress_http_port = get_ingress_service_node_port(result) assert ingress_http_port is not None, "No ingress nodePort found."