diff --git a/tests/integration/tests/test_loadbalancer.py b/tests/integration/tests/test_loadbalancer.py index 2bd3a4bbf..b35f955bb 100644 --- a/tests/integration/tests/test_loadbalancer.py +++ b/tests/integration/tests/test_loadbalancer.py @@ -2,10 +2,10 @@ # Copyright 2024 Canonical, Ltd. # import ipaddress -import json import logging -from pathlib import Path +import subprocess import time +from pathlib import Path from typing import List import pytest @@ -118,8 +118,23 @@ def test_loadbalancer(instances: List[harness.Instance]): # Try to access the service via Ingress instance.exec(["k8s", "enable", "ingress"]) - instance.exec(["k8s", "kubectl", "apply", "-f", "-"], input=Path(MANIFESTS_DIR / "ingress-test.yaml").read_bytes()) - instance.exec(["k8s", "kubectl", "wait", "--for=condition=ready", "pod", "-l", "run=my-nginx", "--timeout", "180s"]) + instance.exec( + ["k8s", "kubectl", "apply", "-f", "-"], + input=Path(MANIFESTS_DIR / "ingress-test.yaml").read_bytes(), + ) + instance.exec( + [ + "k8s", + "kubectl", + "wait", + "--for=condition=ready", + "pod", + "-l", + "run=my-nginx", + "--timeout", + "180s", + ] + ) try_count = 0 ingress_ip = None @@ -127,20 +142,24 @@ def test_loadbalancer(instances: List[harness.Instance]): try_count += 1 for svc in ["ck-ingress-contour-envoy", "cilium-ingress"]: try: - ingress_ip = instance.exec( - [ - "k8s", - "kubectl", - "--namespace", - "kube-system", - "get", - "service", - svc, - "-o=jsonpath='{.status.loadBalancer.ingress[0].ip}'", - ], - capture_output=True, - ).stdout.decode().replace("'", "") - except : + ingress_ip = ( + instance.exec( + [ + "k8s", + "kubectl", + "--namespace", + "kube-system", + "get", + "service", + svc, + "-o=jsonpath='{.status.loadBalancer.ingress[0].ip}'", + ], + capture_output=True, + ) + .stdout.decode() + .replace("'", "") + ) + except subprocess.CalledProcessError: ingress_ip = None pass time.sleep(3)