Created
June 24, 2020 15:56
-
-
Save atemate/70c8c992249d4fc265cc5ae1d9ec4b2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pytest.fixture(scope="session") | |
async def kube_proxy_url(docker_host: str) -> str: | |
cmd = "kubectl proxy -p 8084 --address='0.0.0.0' --accept-hosts='.*'" | |
err = f"Error while running command `{cmd}`" | |
proc = subprocess.Popen( | |
cmd, | |
shell=True, | |
stderr=subprocess.STDOUT, | |
stdout=subprocess.PIPE, | |
close_fds=True, | |
) | |
try: | |
prefix = "Starting to serve on " | |
line = proc.stdout.readline().decode().strip() | |
if "error" in line.lower(): | |
raise RuntimeError(f"{err}: Found error in output: `{line}`") | |
if not line.startswith(prefix): | |
raise RuntimeError(f"{err}: Unexpected output: `{line}`") | |
try: | |
value = line[len(prefix) :] | |
_, port_str = value.rsplit(":", 1) | |
port = int(port_str) | |
except ValueError as e: | |
raise RuntimeError(f"{err}: Could not parse `{line}`: {e}") | |
yield f"http://{docker_host}:{port}" | |
finally: | |
proc.terminate() | |
proc.kill() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
should be: