bind health listeners to the pod's loopback and probe them by exec
This commit is contained in:
parent
b7a8410769
commit
62cc95671d
1 changed files with 255 additions and 185 deletions
|
|
@ -3,6 +3,7 @@
|
|||
# node first and fails the test through the driver (`succeed`, `wait_until_*`)
|
||||
# or an `AssertionError` naming what it saw.
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
|
||||
from test_driver.machine import QemuMachine
|
||||
|
|
@ -119,13 +120,17 @@ def wait_pod(
|
|||
|
||||
|
||||
def http_status(node: QemuMachine, name: str, port: int, path: str) -> int:
|
||||
"""The HTTP status pod `name` answers on its IP for `path`."""
|
||||
ip = pod(node, name)["status"]["podIP"]
|
||||
return int(
|
||||
node.succeed(
|
||||
f"curl -s -o /dev/null -m 5 -w '%{{http_code}}' http://{ip}:{port}{path}"
|
||||
)
|
||||
"""The HTTP status that pod `name` answers on its own loopback for `path`,
|
||||
read by the `wget` in the container: the health listeners bind there and
|
||||
nowhere else. `wget` prints no status for a 2xx, so that is 200."""
|
||||
rc, out = node.execute(
|
||||
f"kubectl exec {name} -- /bin/wget -O /dev/null http://127.0.0.1:{port}{path} 2>&1"
|
||||
)
|
||||
if rc == 0:
|
||||
return 200
|
||||
match = re.search(r"HTTP/1\.[01] (\d{3})", out)
|
||||
assert match, f"{name}: wget exit {rc} with no status: {out}"
|
||||
return int(match.group(1))
|
||||
|
||||
|
||||
def delete_pod(node: QemuMachine, name: str, timeout: int = 60) -> tuple[dict, float]:
|
||||
|
|
|
|||
Loading…
Reference in a new issue