-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtest_deployment.py
More file actions
90 lines (69 loc) · 2.61 KB
/
test_deployment.py
File metadata and controls
90 lines (69 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from __future__ import annotations
import logging
import os
import pytest
from integration.utils import (
MakeTargetError,
RouteNotFoundError,
get_route,
health_check,
load_agent_name,
run_make,
)
logger = logging.getLogger(__name__)
INTERNAL_REGISTRY = "image-registry.openshift-image-registry.svc:5000"
@pytest.fixture(scope="module")
def agent_dir(repo_root):
return repo_root / "agents" / "langgraph" / "human_in_the_loop"
@pytest.fixture(scope="module")
def agent_name(agent_dir):
return load_agent_name(agent_dir)
def _write_env_file(agent_dir, container_image):
"""Write a .env file so Makefile targets can source it."""
missing = [v for v in ("BASE_URL", "MODEL_ID") if v not in os.environ]
if missing:
pytest.fail(
f"Missing required env vars: {', '.join(missing)}. "
"Set them in the CI workflow or export locally."
)
env_path = agent_dir / ".env"
env_path.write_text(
f"API_KEY={os.environ.get('API_KEY', 'not-needed')}\n"
f"BASE_URL={os.environ['BASE_URL']}\n"
f"MODEL_ID={os.environ['MODEL_ID']}\n"
f"CONTAINER_IMAGE={container_image}\n"
)
return env_path
@pytest.fixture(scope="module")
def deployed_agent(cluster_auth, agent_dir, agent_name):
namespace = cluster_auth["namespace"]
container_image = f"{INTERNAL_REGISTRY}/{namespace}/{agent_name}:latest"
env_path = _write_env_file(agent_dir, container_image)
deployed = False
try:
logger.info("Building image on cluster via build-openshift...")
run_make("build-openshift", cwd=agent_dir, timeout=600)
logger.info("Deploying to cluster...")
run_make("deploy", cwd=agent_dir, timeout=300)
deployed = True
route_url = get_route(agent_name, namespace=namespace)
logger.info("Agent deployed at %s", route_url)
yield route_url
except (MakeTargetError, RouteNotFoundError) as exc:
pytest.fail(f"Deployment failed: {exc}")
finally:
if deployed:
logger.info("Tearing down deployment...")
try:
run_make("undeploy", cwd=agent_dir, timeout=120)
except MakeTargetError:
logger.warning(
"Cleanup failed — manual undeploy may be needed", exc_info=True
)
env_path.unlink(missing_ok=True)
@pytest.mark.integration
def test_health_endpoint(deployed_agent):
route_url = deployed_agent
result = health_check(f"{route_url}/health", retries=12, backoff=5.0)
assert result["status"] == "healthy"
assert result["agent_initialized"] is True