Skip to content

Commit

Permalink
DEBUGGING
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Sep 21, 2023
1 parent 469eb19 commit e20b5c6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
27 changes: 19 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,29 @@ def admin_user_client(test_client, test_auth_settings):


@pytest.fixture(scope="session")
def demo_kubectl_env(request):
def demo_dir(request):
demo_dir = request.config.getoption("--demo-dir")
demo_dir = (demo_dir / ".demo").resolve()
if demo_dir is None:
pytest.skip("Requires a running instance of the DiracX demo")
kube_conf = demo_dir / ".demo" / "kube.conf"
yield demo_dir / ".demo"


@pytest.fixture(scope="session")
def demo_kubectl(demo_dir):
kubectl = demo_dir / "kubectl"
if not kubectl.is_file():
raise RuntimeError("Could not find kubectl, is the demo running?")
yield str(kubectl)


@pytest.fixture(scope="session")
def demo_kubectl_env(demo_dir, demo_kubectl):
"""TODO: docstring"""
kube_conf = demo_dir / "kube.conf"
if not kube_conf.exists():
raise RuntimeError(f"Could not find {kube_conf}, is the demo running?")
env = {
**os.environ,
"KUBECONFIG": str(kube_conf),
"PATH": os.environ["PATH"] + ":" + str(demo_dir / ".demo"),
}
pods_result = subprocess.check_output(["kubectl", "get", "pods"], env=env)
env = {**os.environ, "KUBECONFIG": str(kube_conf)}
pods_result = subprocess.check_output([demo_kubectl, "get", "pods"], env=env)
assert pods_result
yield env
18 changes: 11 additions & 7 deletions tests/db/opensearch/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import secrets
import socket
import subprocess
from subprocess import PIPE, Popen

import pytest

Expand Down Expand Up @@ -43,19 +43,19 @@ def index_name(self, doc_id: int) -> str:


@pytest.fixture(scope="session")
def opensearch_conn_kwargs(demo_kubectl_env):
def opensearch_conn_kwargs(demo_kubectl, demo_kubectl_env):
"""Fixture which forwards a port from the diracx-demo and returns the connection kwargs."""
require_port_availability(OPENSEARCH_PORT)
command = [
"kubectl",
cmd = [
demo_kubectl,
"port-forward",
"service/opensearch-cluster-master",
f"{OPENSEARCH_PORT}:9200",
]
with subprocess.Popen(
command, stdout=subprocess.PIPE, universal_newlines=True, env=demo_kubectl_env
) as proc:
output_lines = []
with Popen(cmd, stdout=PIPE, stderr=PIPE, text=True, env=demo_kubectl_env) as proc:
for line in proc.stdout:
output_lines.append(line)
if line.startswith("Forwarding from"):
yield {
"hosts": f"admin:admin@localhost:{OPENSEARCH_PORT}",
Expand All @@ -64,6 +64,10 @@ def opensearch_conn_kwargs(demo_kubectl_env):
}
proc.kill()
break
else:
raise RuntimeError(
f"Could not start port forwarding with {cmd=}\n{output_lines=}"
)
proc.wait()


Expand Down

0 comments on commit e20b5c6

Please sign in to comment.